Skip to content

Commit 95dea5e

Browse files
committed
dmodule.d: transition to eSink
1 parent 8dc1ce6 commit 95dea5e

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

compiler/src/dmd/dmodule.d

Lines changed: 24 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;
@@ -398,10 +399,13 @@ extern (C++) final class Module : Package
398399
size_t nameoffset; // offset of module name from start of ModuleInfo
399400
size_t namelen; // length of module name in characters
400401

402+
ErrorSink eSink;
403+
401404
extern (D) this(Loc loc, const(char)[] filename, Identifier ident, int doDocComment, int doHdrGen)
402405
{
403406
super(loc, ident);
404407
this.dsym = DSYM.module_;
408+
eSink = global.errorSink;
405409
const(char)[] srcfilename;
406410
//printf("Module::Module(filename = '%.*s', ident = '%s')\n", cast(int)filename.length, filename.ptr, ident.toChars());
407411
this.arg = filename;
@@ -422,7 +426,7 @@ extern (C++) final class Module : Package
422426
!FileName.equalsExt(srcfilename, dd_ext))
423427
{
424428

425-
error(loc, "%s `%s` source file name '%.*s' must have .%.*s extension",
429+
eSink.error(loc, "%s `%s` source file name '%.*s' must have .%.*s extension",
426430
kind, toPrettyChars,
427431
cast(int)srcfilename.length, srcfilename.ptr,
428432
cast(int)mars_ext.length, mars_ext.ptr);
@@ -565,7 +569,7 @@ extern (C++) final class Module : Package
565569
}
566570
if (FileName.equals(docfilename, srcfile.toString()))
567571
{
568-
error(loc, "%s `%s` source file and output file have same name '%s'",
572+
eSink.error(loc, "%s `%s` source file and output file have same name '%s'",
569573
kind, toPrettyChars, srcfile.toChars());
570574
fatal();
571575
}
@@ -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);
@@ -815,7 +819,7 @@ extern (C++) final class Module : Package
815819
Module m = ppack ? ppack.isModule() : null;
816820
if (m && !isPackageFileName(m.srcfile))
817821
{
818-
.error(md.loc, "package name '%s' conflicts with usage as a module name in file %s", ppack.toPrettyChars(), m.srcfile.toChars());
822+
eSink.error(md.loc, "package name '%s' conflicts with usage as a module name in file %s", ppack.toPrettyChars(), m.srcfile.toChars());
819823
}
820824
}
821825
else
@@ -827,7 +831,7 @@ extern (C++) final class Module : Package
827831
/* Check to see if module name is a valid identifier
828832
*/
829833
if (!Identifier.isValidIdentifier(this.ident.toChars()))
830-
error(loc, "%s `%s` has non-identifier characters in filename, use module declaration instead", kind, toPrettyChars);
834+
eSink.error(loc, "%s `%s` has non-identifier characters in filename, use module declaration instead", kind, toPrettyChars);
831835
}
832836
// Insert module into the symbol table
833837
Dsymbol s = this;
@@ -880,11 +884,11 @@ extern (C++) final class Module : Package
880884
if (Module mprev = prev.isModule())
881885
{
882886
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());
887+
eSink.error(loc, "%s `%s` from file %s conflicts with another module %s from file %s", kind, toPrettyChars, srcname, mprev.toErrMsg(), mprev.srcfile.toChars());
884888
else if (isRoot() && mprev.isRoot())
885-
error(loc, "%s `%s` from file %s is specified twice on the command line", kind, toPrettyChars, srcname);
889+
eSink.error(loc, "%s `%s` from file %s is specified twice on the command line", kind, toPrettyChars, srcname);
886890
else
887-
error(loc, "%s `%s` from file %s must be imported with 'import %s;'", kind, toPrettyChars, srcname, toPrettyChars());
891+
eSink.error(loc, "%s `%s` from file %s must be imported with 'import %s;'", kind, toPrettyChars, srcname, toPrettyChars());
888892
// https://issues.dlang.org/show_bug.cgi?id=14446
889893
// Return previously parsed module to avoid AST duplication ICE.
890894
return mprev;
@@ -895,7 +899,7 @@ extern (C++) final class Module : Package
895899
if (isPackageFile)
896900
amodules.push(this); // Add to global array of all modules
897901
else
898-
error(md ? md.loc : loc, "%s `%s` from file %s conflicts with package name %s", kind, toPrettyChars, srcname, pkg.toErrMsg());
902+
eSink.error(md ? md.loc : loc, "%s `%s` from file %s conflicts with package name %s", kind, toPrettyChars, srcname, pkg.toErrMsg());
899903
}
900904
else
901905
assert(global.errors);
@@ -1081,6 +1085,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
10811085
enum SourceEncoding { utf16, utf32}
10821086
enum Endian { little, big}
10831087
immutable loc = mod.loc;
1088+
auto eSink = global.errorSink;
10841089

10851090
/*
10861091
* Convert a buffer from UTF32 to UTF8
@@ -1100,7 +1105,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11001105

11011106
if (buf.length & 3)
11021107
{
1103-
.error(loc, "%s `%s` odd length of UTF-32 char source %llu",
1108+
eSink.error(loc, "%s `%s` odd length of UTF-32 char source %llu",
11041109
mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
11051110
return null;
11061111
}
@@ -1117,7 +1122,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11171122
{
11181123
if (u > 0x10FFFF)
11191124
{
1120-
.error(loc, "%s `%s` UTF-32 value %08x greater than 0x10FFFF", mod.kind, mod.toPrettyChars, u);
1125+
eSink.error(loc, "%s `%s` UTF-32 value %08x greater than 0x10FFFF", mod.kind, mod.toPrettyChars, u);
11211126
return null;
11221127
}
11231128
dbuf.writeUTF8(u);
@@ -1147,7 +1152,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11471152

11481153
if (buf.length & 1)
11491154
{
1150-
.error(loc, "%s `%s` odd length of UTF-16 char source %llu", mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
1155+
eSink.error(loc, "%s `%s` odd length of UTF-16 char source %llu", mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
11511156
return null;
11521157
}
11531158

@@ -1167,26 +1172,26 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
11671172
i++;
11681173
if (i >= eBuf.length)
11691174
{
1170-
.error(loc, "%s `%s` surrogate UTF-16 high value %04x at end of file", mod.kind, mod.toPrettyChars, u);
1175+
eSink.error(loc, "%s `%s` surrogate UTF-16 high value %04x at end of file", mod.kind, mod.toPrettyChars, u);
11711176
return null;
11721177
}
11731178
const u2 = readNext(&eBuf[i]);
11741179
if (u2 < 0xDC00 || 0xE000 <= u2)
11751180
{
1176-
.error(loc, "%s `%s` surrogate UTF-16 low value %04x out of range", mod.kind, mod.toPrettyChars, u2);
1181+
eSink.error(loc, "%s `%s` surrogate UTF-16 low value %04x out of range", mod.kind, mod.toPrettyChars, u2);
11771182
return null;
11781183
}
11791184
u = (u - 0xD7C0) << 10;
11801185
u |= (u2 - 0xDC00);
11811186
}
11821187
else if (u >= 0xDC00 && u <= 0xDFFF)
11831188
{
1184-
.error(loc, "%s `%s` unpaired surrogate UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
1189+
eSink.error(loc, "%s `%s` unpaired surrogate UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
11851190
return null;
11861191
}
11871192
else if (u == 0xFFFE || u == 0xFFFF)
11881193
{
1189-
.error(loc, "%s `%s` illegal UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
1194+
eSink.error(loc, "%s `%s` illegal UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
11901195
return null;
11911196
}
11921197
dbuf.writeUTF8(u);
@@ -1245,7 +1250,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
12451250
// It's UTF-8
12461251
if (buf[0] >= 0x80)
12471252
{
1248-
.error(loc, "%s `%s` source file must start with BOM or ASCII character, not \\x%02X", mod.kind, mod.toPrettyChars, buf[0]);
1253+
eSink.error(loc, "%s `%s` source file must start with BOM or ASCII character, not \\x%02X", mod.kind, mod.toPrettyChars, buf[0]);
12491254
return null;
12501255
}
12511256

0 commit comments

Comments
 (0)