Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mangle-only extern(C++, namespace) into an AttribDeclaration #10021

Merged
merged 1 commit into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dmd/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
sc2.explicitProtection = 0;
sc2.aligndecl = null;
sc2.userAttribDecl = null;
sc2.namespace = null;
return sc2;
}

Expand Down
30 changes: 23 additions & 7 deletions src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -1172,23 +1172,17 @@ struct ASTBase

extern (C++) final class Nspace : ScopeDsymbol
{
/**
* Determines whether the symbol for this namespace should be included in the symbol table.
*/
bool mangleOnly;

/**
* Namespace identifier resolved during semantic.
*/
Expression identExp;

extern (D) this(const ref Loc loc, Identifier ident, Expression identExp, Dsymbols* members, bool mangleOnly)
extern (D) this(const ref Loc loc, Identifier ident, Expression identExp, Dsymbols* members)
{
super(ident);
this.loc = loc;
this.members = members;
this.identExp = identExp;
this.mangleOnly = mangleOnly;
}

override void accept(Visitor v)
Expand Down Expand Up @@ -1312,6 +1306,28 @@ struct ASTBase
}
}

extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
{
Expression exp;

extern (D) this(Identifier ident, Dsymbols* decl)
{
super(decl);
this.ident = ident;
}

extern (D) this(Expression exp, Dsymbols* decl)
{
super(decl);
this.exp = exp;
}

override void accept(Visitor v)
{
v.visit(this);
}
}

extern (C++) final class ProtDeclaration : AttribDeclaration
{
Prot protection;
Expand Down
60 changes: 60 additions & 0 deletions src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,66 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration
}
}

/***********************************************************
*/
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
{
Expression exp;

extern (D) this(Identifier ident, Dsymbols* decl)
{
super(decl);
this.ident = ident;
}

extern (D) this(Expression exp, Dsymbols* decl)
{
super(decl);
this.exp = exp;
}

extern (D) this(Identifier ident, Expression exp, Dsymbols* decl,
CPPNamespaceDeclaration parent)
{
super(decl);
this.ident = ident;
this.exp = exp;
this.namespace = parent;
}

override Dsymbol syntaxCopy(Dsymbol s)
{
assert(!s);
return new CPPNamespaceDeclaration(
this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.namespace);
}

override Scope* newScope(Scope* sc)
{
auto scx = sc.copy();
scx.linkage = LINK.cpp;
scx.namespace = this;
return scx;
}

override const(char)* toChars() const
{
return toString().ptr;
}

extern(D) override const(char)[] toString() const
{
return "extern (C++, `namespace`)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should include the identifier or expression instead of "namespace".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nspace doesn't do that (and it allocates)
I was considering doing a refactor where toString takes a sink, but it has been put off so far.

}

override void accept(Visitor v)
{
v.visit(this);
}

override inout(CPPNamespaceDeclaration) isCPPNamespaceDeclaration() inout { return this; }
}

/***********************************************************
*/
extern (C++) final class ProtDeclaration : AttribDeclaration
Expand Down
11 changes: 11 additions & 0 deletions src/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class CPPMangleDeclaration : public AttribDeclaration
void accept(Visitor *v) { v->visit(this); }
};

class CPPNamespaceDeclaration : public AttribDeclaration
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
public:
Expression *exp;

Dsymbol *syntaxCopy(Dsymbol *s);
Scope *newScope(Scope *sc);
const char *toChars();
void accept(Visitor *v) { v->visit(this); }
};

class ProtDeclaration : public AttribDeclaration
{
public:
Expand Down