Skip to content

Commit 76d4439

Browse files
committed
dmodule.d: transition to eSink
1 parent 8dc1ce6 commit 76d4439

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

compiler/src/dmd/dmodule.d

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import dmd.declaration;
2828
import dmd.dmacro;
2929
import dmd.dsymbol;
3030
import dmd.errors;
31+
import dmd.errorsink;
3132
import dmd.expression;
3233
import dmd.file_manager;
3334
import dmd.func;
@@ -422,7 +423,8 @@ extern (C++) final class Module : Package
422423
!FileName.equalsExt(srcfilename, dd_ext))
423424
{
424425

425-
error(loc, "%s `%s` source file name '%.*s' must have .%.*s extension",
426+
auto eSink = global.errorSink;
427+
eSink.error(loc, "%s `%s` source file name '%.*s' must have .%.*s extension",
426428
kind, toPrettyChars,
427429
cast(int)srcfilename.length, srcfilename.ptr,
428430
cast(int)mars_ext.length, mars_ext.ptr);
@@ -565,7 +567,8 @@ extern (C++) final class Module : Package
565567
}
566568
if (FileName.equals(docfilename, srcfile.toString()))
567569
{
568-
error(loc, "%s `%s` source file and output file have same name '%s'",
570+
auto eSink = global.errorSink;
571+
eSink.error(loc, "%s `%s` source file and output file have same name '%s'",
569572
kind, toPrettyChars, srcfile.toChars());
570573
fatal();
571574
}
@@ -589,6 +592,7 @@ extern (C++) final class Module : Package
589592
*/
590593
private void onFileReadError(Loc loc, bool removeHeaders)
591594
{
595+
auto eSink = global.errorSink;
592596
const name = srcfile.toString();
593597
if (FileName.equals(name, "object.d"))
594598
{
@@ -599,17 +603,17 @@ extern (C++) final class Module : Package
599603
// Modules whose original argument name has an extension, or do not
600604
// have a valid location come from the command-line.
601605
// Error that their file cannot be found and return early.
602-
.error(loc, "cannot find input file `%.*s`", cast(int)name.length, name.ptr);
606+
eSink.error(loc, "cannot find input file `%.*s`", cast(int)name.length, name.ptr);
603607
}
604608
else
605609
{
606610
// if module is not named 'package' but we're trying to read 'package.d', we're looking for a package module
607611
bool isPackageMod = (strcmp(toChars(), "package") != 0) && isPackageFileName(srcfile);
608612
if (isPackageMod)
609-
.error(loc, "importing package '%s' requires a 'package.d' file which cannot be found in '%.*s'", toChars(), cast(int)name.length, name.ptr);
613+
eSink.error(loc, "importing package '%s' requires a 'package.d' file which cannot be found in '%.*s'", toChars(), cast(int)name.length, name.ptr);
610614
else
611615
{
612-
.error(loc, "unable to read module `%s`", toChars());
616+
eSink.error(loc, "unable to read module `%s`", toChars());
613617
const pkgfile = FileName.combine(FileName.sansExt(name), package_d);
614618
.errorSupplemental(loc, "Expected '%.*s' or '%.*s' in one of the following import paths:",
615619
cast(int)name.length, name.ptr, cast(int)pkgfile.length, pkgfile.ptr);
@@ -692,6 +696,7 @@ extern (C++) final class Module : Package
692696
{
693697
const(char)* srcname = srcfile.toChars();
694698
//printf("Module::parse(srcname = '%s')\n", srcname);
699+
auto eSink = global.errorSink;
695700

696701
import dmd.timetrace;
697702
timeTraceBeginEvent(TimeTraceEventType.parse);
@@ -815,7 +820,7 @@ extern (C++) final class Module : Package
815820
Module m = ppack ? ppack.isModule() : null;
816821
if (m && !isPackageFileName(m.srcfile))
817822
{
818-
.error(md.loc, "package name '%s' conflicts with usage as a module name in file %s", ppack.toPrettyChars(), m.srcfile.toChars());
823+
eSink.error(md.loc, "package name '%s' conflicts with usage as a module name in file %s", ppack.toPrettyChars(), m.srcfile.toChars());
819824
}
820825
}
821826
else
@@ -827,7 +832,7 @@ extern (C++) final class Module : Package
827832
/* Check to see if module name is a valid identifier
828833
*/
829834
if (!Identifier.isValidIdentifier(this.ident.toChars()))
830-
error(loc, "%s `%s` has non-identifier characters in filename, use module declaration instead", kind, toPrettyChars);
835+
eSink.error(loc, "%s `%s` has non-identifier characters in filename, use module declaration instead", kind, toPrettyChars);
831836
}
832837
// Insert module into the symbol table
833838
Dsymbol s = this;
@@ -880,11 +885,11 @@ extern (C++) final class Module : Package
880885
if (Module mprev = prev.isModule())
881886
{
882887
if (!FileName.equals(srcname, mprev.srcfile.toChars()))
883-
error(loc, "%s `%s` from file %s conflicts with another module %s from file %s", kind, toPrettyChars, srcname, mprev.toErrMsg(), mprev.srcfile.toChars());
888+
eSink.error(loc, "%s `%s` from file %s conflicts with another module %s from file %s", kind, toPrettyChars, srcname, mprev.toErrMsg(), mprev.srcfile.toChars());
884889
else if (isRoot() && mprev.isRoot())
885-
error(loc, "%s `%s` from file %s is specified twice on the command line", kind, toPrettyChars, srcname);
890+
eSink.error(loc, "%s `%s` from file %s is specified twice on the command line", kind, toPrettyChars, srcname);
886891
else
887-
error(loc, "%s `%s` from file %s must be imported with 'import %s;'", kind, toPrettyChars, srcname, toPrettyChars());
892+
eSink.error(loc, "%s `%s` from file %s must be imported with 'import %s;'", kind, toPrettyChars, srcname, toPrettyChars());
888893
// https://issues.dlang.org/show_bug.cgi?id=14446
889894
// Return previously parsed module to avoid AST duplication ICE.
890895
return mprev;
@@ -895,7 +900,7 @@ extern (C++) final class Module : Package
895900
if (isPackageFile)
896901
amodules.push(this); // Add to global array of all modules
897902
else
898-
error(md ? md.loc : loc, "%s `%s` from file %s conflicts with package name %s", kind, toPrettyChars, srcname, pkg.toErrMsg());
903+
eSink.error(md ? md.loc : loc, "%s `%s` from file %s conflicts with package name %s", kind, toPrettyChars, srcname, pkg.toErrMsg());
899904
}
900905
else
901906
assert(global.errors);
@@ -1081,6 +1086,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
10811086
enum SourceEncoding { utf16, utf32}
10821087
enum Endian { little, big}
10831088
immutable loc = mod.loc;
1089+
auto eSink = global.errorSink;
10841090

10851091
/*
10861092
* Convert a buffer from UTF32 to UTF8
@@ -1100,7 +1106,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11001106

11011107
if (buf.length & 3)
11021108
{
1103-
.error(loc, "%s `%s` odd length of UTF-32 char source %llu",
1109+
eSink.error(loc, "%s `%s` odd length of UTF-32 char source %llu",
11041110
mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
11051111
return null;
11061112
}
@@ -1117,7 +1123,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11171123
{
11181124
if (u > 0x10FFFF)
11191125
{
1120-
.error(loc, "%s `%s` UTF-32 value %08x greater than 0x10FFFF", mod.kind, mod.toPrettyChars, u);
1126+
eSink.error(loc, "%s `%s` UTF-32 value %08x greater than 0x10FFFF", mod.kind, mod.toPrettyChars, u);
11211127
return null;
11221128
}
11231129
dbuf.writeUTF8(u);
@@ -1147,7 +1153,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11471153

11481154
if (buf.length & 1)
11491155
{
1150-
.error(loc, "%s `%s` odd length of UTF-16 char source %llu", mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
1156+
eSink.error(loc, "%s `%s` odd length of UTF-16 char source %llu", mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
11511157
return null;
11521158
}
11531159

@@ -1167,26 +1173,26 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11671173
i++;
11681174
if (i >= eBuf.length)
11691175
{
1170-
.error(loc, "%s `%s` surrogate UTF-16 high value %04x at end of file", mod.kind, mod.toPrettyChars, u);
1176+
eSink.error(loc, "%s `%s` surrogate UTF-16 high value %04x at end of file", mod.kind, mod.toPrettyChars, u);
11711177
return null;
11721178
}
11731179
const u2 = readNext(&eBuf[i]);
11741180
if (u2 < 0xDC00 || 0xE000 <= u2)
11751181
{
1176-
.error(loc, "%s `%s` surrogate UTF-16 low value %04x out of range", mod.kind, mod.toPrettyChars, u2);
1182+
eSink.error(loc, "%s `%s` surrogate UTF-16 low value %04x out of range", mod.kind, mod.toPrettyChars, u2);
11771183
return null;
11781184
}
11791185
u = (u - 0xD7C0) << 10;
11801186
u |= (u2 - 0xDC00);
11811187
}
11821188
else if (u >= 0xDC00 && u <= 0xDFFF)
11831189
{
1184-
.error(loc, "%s `%s` unpaired surrogate UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
1190+
eSink.error(loc, "%s `%s` unpaired surrogate UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
11851191
return null;
11861192
}
11871193
else if (u == 0xFFFE || u == 0xFFFF)
11881194
{
1189-
.error(loc, "%s `%s` illegal UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
1195+
eSink.error(loc, "%s `%s` illegal UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
11901196
return null;
11911197
}
11921198
dbuf.writeUTF8(u);
@@ -1245,7 +1251,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
12451251
// It's UTF-8
12461252
if (buf[0] >= 0x80)
12471253
{
1248-
.error(loc, "%s `%s` source file must start with BOM or ASCII character, not \\x%02X", mod.kind, mod.toPrettyChars, buf[0]);
1254+
eSink.error(loc, "%s `%s` source file must start with BOM or ASCII character, not \\x%02X", mod.kind, mod.toPrettyChars, buf[0]);
12491255
return null;
12501256
}
12511257

0 commit comments

Comments
 (0)