Skip to content

Commit

Permalink
[dimport.d] move addAlias to parser, remove import dmd.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator committed Oct 5, 2024
1 parent 645db4e commit 10f7572
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
10 changes: 0 additions & 10 deletions compiler/src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,6 @@ struct ASTBase
this.ident = id;
}
}
void addAlias(Identifier name, Identifier _alias)
{
if (isstatic)
error(loc, "cannot have an import bind list");
if (!aliasId)
this.ident = null;

names.push(name);
aliases.push(_alias);
}

override void accept(Visitor v)
{
Expand Down
17 changes: 5 additions & 12 deletions compiler/src/dmd/dimport.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module dmd.dimport;
import dmd.arraytypes;
import dmd.dmodule;
import dmd.dsymbol;
import dmd.errors;
import dmd.identifier;
import dmd.location;
import dmd.visitor;
Expand Down Expand Up @@ -84,16 +83,6 @@ extern (C++) final class Import : Dsymbol
this.visibility = Visibility.Kind.private_; // default to private
}

extern (D) void addAlias(Identifier name, Identifier _alias)
{
if (isstatic)
.error(loc, "%s `%s` cannot have an import bind list", kind, toPrettyChars);
if (!aliasId)
this.ident = null; // make it an anonymous import
names.push(name);
aliases.push(_alias);
}

override const(char)* kind() const
{
return isstatic ? "static import" : "import";
Expand All @@ -110,9 +99,13 @@ extern (C++) final class Import : Dsymbol
assert(!s);
auto si = new Import(loc, packages, id, aliasId, isstatic);
si.comment = comment;
assert(!(isstatic && names.length));
if (!si.aliasId)
si.ident = null;
for (size_t i = 0; i < names.length; i++)
{
si.addAlias(names[i], aliases[i]);
si.names.push(names[i]);
si.aliases.push(aliases[i]);
}
return si;
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -3501,7 +3501,12 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
name = _alias;
_alias = null;
}
s.addAlias(name, _alias);
if (s.isstatic)
error(loc, "static import `%s` cannot have an import bind list", s.toPrettyChars());
if (!s.aliasId)
s.ident = null; // make it an anonymous import
s.names.push(name);
s.aliases.push(_alias);
}
while (token.value == TOK.comma);
break; // no comma-separated imports of this form
Expand Down

0 comments on commit 10f7572

Please sign in to comment.