diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index 5da4721bba5..7a60ecbd408 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -271,17 +271,6 @@ extern (C++) final class LinkDeclaration : AttribDeclaration return new LinkDeclaration(loc, linkage, Dsymbol.arraySyntaxCopy(decl)); } - - override const(char)* toChars() const - { - return toString().ptr; - } - - extern(D) override const(char)[] toString() const - { - return "extern ()"; - } - override void accept(Visitor v) { v.visit(this); @@ -313,16 +302,6 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration return new CPPMangleDeclaration(loc, cppmangle, Dsymbol.arraySyntaxCopy(decl)); } - override const(char)* toChars() const - { - return toString().ptr; - } - - extern(D) override const(char)[] toString() const - { - return "extern ()"; - } - override void accept(Visitor v) { v.visit(this); @@ -383,16 +362,6 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration this.loc, this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.cppnamespace); } - override const(char)* toChars() const - { - return toString().ptr; - } - - extern(D) override const(char)[] toString() const - { - return "extern (C++, `namespace`)"; - } - override void accept(Visitor v) { v.visit(this); diff --git a/compiler/src/dmd/attrib.h b/compiler/src/dmd/attrib.h index ef01d0f9538..1c9bd96fa9c 100644 --- a/compiler/src/dmd/attrib.h +++ b/compiler/src/dmd/attrib.h @@ -67,7 +67,6 @@ class LinkDeclaration final : public AttribDeclaration static LinkDeclaration *create(const Loc &loc, LINK p, Dsymbols *decl); LinkDeclaration *syntaxCopy(Dsymbol *s) override; - const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -77,7 +76,6 @@ class CPPMangleDeclaration final : public AttribDeclaration CPPMANGLE cppmangle; CPPMangleDeclaration *syntaxCopy(Dsymbol *s) override; - const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -87,7 +85,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration Expression *exp; CPPNamespaceDeclaration *syntaxCopy(Dsymbol *s) override; - const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; diff --git a/compiler/src/dmd/cond.d b/compiler/src/dmd/cond.d index 2f3f4bcb200..186efb07282 100644 --- a/compiler/src/dmd/cond.d +++ b/compiler/src/dmd/cond.d @@ -605,11 +605,6 @@ extern (C++) final class DebugCondition : DVCondition { v.visit(this); } - - override const(char)* toChars() const - { - return ident ? ident.toChars() : "debug".ptr; - } } /** @@ -887,11 +882,6 @@ extern (C++) final class VersionCondition : DVCondition { v.visit(this); } - - override const(char)* toChars() const - { - return ident ? ident.toChars() : "version".ptr; - } } /*********************************************************** @@ -961,11 +951,6 @@ extern (C++) final class StaticIfCondition : Condition { return this; } - - override const(char)* toChars() const - { - return exp ? exp.toChars() : "static if".ptr; - } } diff --git a/compiler/src/dmd/ctfe.h b/compiler/src/dmd/ctfe.h index 72d895c7150..73f1939490a 100644 --- a/compiler/src/dmd/ctfe.h +++ b/compiler/src/dmd/ctfe.h @@ -48,7 +48,6 @@ class ThrownExceptionExp final : public Expression { public: ClassReferenceExp *thrown; // the thing being tossed - const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -58,6 +57,4 @@ class ThrownExceptionExp final : public Expression class CTFEExp final : public Expression { -public: - const char *toChars() const override; }; diff --git a/compiler/src/dmd/declaration.d b/compiler/src/dmd/declaration.d index e6fb1ed65cd..c94443de396 100644 --- a/compiler/src/dmd/declaration.d +++ b/compiler/src/dmd/declaration.d @@ -1379,16 +1379,6 @@ extern (C++) class TypeInfoDeclaration : VarDeclaration assert(0); // should never be produced by syntax } - override final const(char)* toChars() const - { - //printf("TypeInfoDeclaration::toChars() tinfo = %s\n", tinfo.toChars()); - OutBuffer buf; - buf.writestring("typeid("); - buf.writestring(tinfo.toChars()); - buf.writeByte(')'); - return buf.extractChars(); - } - override final inout(TypeInfoDeclaration) isTypeInfoDeclaration() inout @nogc nothrow pure @safe { return this; diff --git a/compiler/src/dmd/declaration.h b/compiler/src/dmd/declaration.h index 7f37f89d224..e2ac13ee04a 100644 --- a/compiler/src/dmd/declaration.h +++ b/compiler/src/dmd/declaration.h @@ -342,7 +342,6 @@ class TypeInfoDeclaration : public VarDeclaration static TypeInfoDeclaration *create(Type *tinfo); TypeInfoDeclaration *syntaxCopy(Dsymbol *) override final; - const char *toChars() const override final; TypeInfoDeclaration *isTypeInfoDeclaration() override final { return this; } void accept(Visitor *v) override { v->visit(this); } @@ -787,7 +786,6 @@ class CtorDeclaration final : public FuncDeclaration d_bool isMoveCtor; CtorDeclaration *syntaxCopy(Dsymbol *) override; const char *kind() const override; - const char *toChars() const override; bool isVirtual() const override; bool addPreInvariant() override; bool addPostInvariant() override; @@ -814,7 +812,6 @@ class DtorDeclaration final : public FuncDeclaration public: DtorDeclaration *syntaxCopy(Dsymbol *) override; const char *kind() const override; - const char *toChars() const override; bool isVirtual() const override; bool addPreInvariant() override; bool addPostInvariant() override; diff --git a/compiler/src/dmd/doc.d b/compiler/src/dmd/doc.d index a9a0ff69ccb..0e77cdfc982 100644 --- a/compiler/src/dmd/doc.d +++ b/compiler/src/dmd/doc.d @@ -691,9 +691,7 @@ bool emitAnchorName(ref OutBuffer buf, Dsymbol s, Scope* sc, bool includeParent) } else { - /* We just want the identifier, not overloads like TemplateDeclaration::toChars. - * We don't want the template parameter list and constraints. */ - buf.writestring(s.Dsymbol.toChars()); + buf.writestring(s.ident ? s.ident.toString : "__anonymous"); } return true; } @@ -796,7 +794,11 @@ void emitAnchor(ref OutBuffer buf, Dsymbol s, Scope* sc, bool forHeader = false) } else { - auto symbolName = ident.toString(); + // buf.writestring("<<<"); + // buf.writestring(typeof(ident).stringof); + // buf.writestring(">>>"); + // auto symbolName = ident.toString(); + auto symbolName = ident.toChars().toDString(); buf.printf("$(%.*s %.*s", cast(int) macroName.length, macroName.ptr, cast(int) symbolName.length, symbolName.ptr); diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index 2b19f176102..2f2c017ed81 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -297,9 +297,10 @@ extern (C++) class Dsymbol : ASTNode return new Dsymbol(ident); } - override const(char)* toChars() const + final override const(char)* toChars() const { - return ident ? ident.toHChars2() : "__anonymous"; + import dmd.hdrgen : toChars; + return toChars(this); } // Getters / setters for fields stored in `DsymbolAttributes` diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 3936c3e4cfb..c83b8d1b6af 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -187,7 +187,7 @@ class Dsymbol : public ASTNode PASS semanticRun; unsigned short localNum; // perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab static Dsymbol *create(Identifier *); - const char *toChars() const override; + const char *toChars() const final override; DeprecatedDeclaration* depdecl(); CPPNamespaceDeclaration* cppnamespace(); UserAttributeDeclaration* userAttribDecl(); diff --git a/compiler/src/dmd/dtemplate.d b/compiler/src/dmd/dtemplate.d index 38298c04681..296c10c7593 100644 --- a/compiler/src/dmd/dtemplate.d +++ b/compiler/src/dmd/dtemplate.d @@ -746,14 +746,6 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol return (onemember && onemember.isAggregateDeclaration()) ? onemember.kind() : "template"; } - override const(char)* toChars() const - { - HdrGenState hgs; - OutBuffer buf; - toCharsMaybeConstraints(this, buf, hgs); - return buf.extractChars(); - } - /**************************** * Similar to `toChars`, but does not print the template constraints */ @@ -3830,13 +3822,6 @@ extern (C++) class TemplateInstance : ScopeDsymbol return true; } - override const(char)* toChars() const - { - OutBuffer buf; - toCBufferInstance(this, buf); - return buf.extractChars(); - } - override final const(char)* toPrettyCharsHelper() { OutBuffer buf; @@ -5524,13 +5509,6 @@ extern (C++) final class TemplateMixin : TemplateInstance return members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0; } - override const(char)* toChars() const - { - OutBuffer buf; - toCBufferInstance(this, buf); - return buf.extractChars(); - } - extern (D) bool findTempDecl(Scope* sc) { // Follow qualifications to find the TemplateDeclaration diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index 101e5872439..c8e7309e6f3 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -381,8 +381,13 @@ extern (C++) abstract class Expression : ASTNode return DYNCAST.expression; } - override const(char)* toChars() const + final override const(char)* toChars() const { + // FIXME: Test suite relies on lambda's being printed as __lambdaXXX in errors and .stringof + // Printing a (truncated) lambda body is more user friendly + if (auto fe = isFuncExp()) + return fe.fd.toChars(); + return .toChars(this); } @@ -2694,11 +2699,6 @@ extern (C++) final class FuncExp : Expression return new FuncExp(loc, fd); } - override const(char)* toChars() const - { - return fd.toChars(); - } - override bool checkType() { if (td) @@ -4126,10 +4126,6 @@ extern (C++) final class LoweredAssignExp : AssignExp this.lowering = lowering; } - override const(char)* toChars() const - { - return lowering.toChars(); - } override void accept(Visitor v) { v.visit(this); @@ -5035,27 +5031,6 @@ extern (C++) final class CTFEExp : Expression type = Type.tvoid; } - override const(char)* toChars() const - { - switch (op) - { - case EXP.cantExpression: - return ""; - case EXP.voidExpression: - return "cast(void)0"; - case EXP.showCtfeContext: - return ""; - case EXP.break_: - return ""; - case EXP.continue_: - return ""; - case EXP.goto_: - return ""; - default: - assert(0); - } - } - extern (D) __gshared CTFEExp cantexp; extern (D) __gshared CTFEExp voidexp; extern (D) __gshared CTFEExp breakexp; @@ -5092,11 +5067,6 @@ extern (C++) final class ThrownExceptionExp : Expression this.type = victim.type; } - override const(char)* toChars() const - { - return "CTFE ThrownException"; - } - override void accept(Visitor v) { v.visit(this); diff --git a/compiler/src/dmd/expression.h b/compiler/src/dmd/expression.h index 1ee669b24cb..09ed60fad91 100644 --- a/compiler/src/dmd/expression.h +++ b/compiler/src/dmd/expression.h @@ -91,7 +91,7 @@ class Expression : public ASTNode // kludge for template.isExpression() DYNCAST dyncast() const override final { return DYNCAST_EXPRESSION; } - const char *toChars() const override; + const char* toChars() const final override; virtual dinteger_t toInteger(); virtual uinteger_t toUInteger(); @@ -602,7 +602,6 @@ class FuncExp final : public Expression bool equals(const RootObject * const o) const override; FuncExp *syntaxCopy() override; - const char *toChars() const override; bool checkType() override; void accept(Visitor *v) override { v->visit(this); } @@ -1049,7 +1048,6 @@ class LoweredAssignExp final : public AssignExp public: Expression *lowering; - const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 1d94e24b307..a4ae246abcb 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -467,7 +467,7 @@ class Dsymbol : public ASTNode PASS semanticRun; uint16_t localNum; static Dsymbol* create(Identifier* ident); - const char* toChars() const override; + const char* toChars() const final override; DeprecatedDeclaration* depdecl(); CPPNamespaceDeclaration* cppnamespace(); UserAttributeDeclaration* userAttribDecl(); @@ -1591,7 +1591,6 @@ class TemplateDeclaration final : public ScopeDsymbol bool overloadInsert(Dsymbol* s) override; bool hasStaticCtorOrDtor() override; const char* kind() const override; - const char* toChars() const override; const char* toCharsNoConstraints() const; Visibility visible() override; const char* getConstraintEvalError(const char*& tip); @@ -1639,7 +1638,6 @@ class TemplateInstance : public ScopeDsymbol Dsymbol* toAlias() final override; const char* kind() const override; bool oneMember(Dsymbol*& ps, Identifier* ident) override; - const char* toChars() const override; const char* toPrettyCharsHelper() final override; Identifier* getIdent() final override; bool equalsx(TemplateInstance* ti); @@ -1666,7 +1664,6 @@ class TemplateMixin final : public TemplateInstance const char* kind() const override; bool oneMember(Dsymbol*& ps, Identifier* ident) override; bool hasPointers() override; - const char* toChars() const override; TemplateMixin* isTemplateMixin() override; void accept(Visitor* v) override; }; @@ -2229,7 +2226,7 @@ class Expression : public ASTNode static void deinitialize(); virtual Expression* syntaxCopy(); DYNCAST dyncast() const final override; - const char* toChars() const override; + const char* toChars() const final override; virtual dinteger_t toInteger(); virtual uinteger_t toUInteger(); virtual _d_real toReal(); @@ -2518,8 +2515,6 @@ class BlitExp final : public AssignExp class CTFEExp final : public Expression { -public: - const char* toChars() const override; }; class CallExp final : public UnaExp @@ -3039,7 +3034,6 @@ class FuncExp final : public Expression TOK tok; bool equals(const RootObject* const o) const override; FuncExp* syntaxCopy() override; - const char* toChars() const override; bool checkType() override; void accept(Visitor* v) override; }; @@ -3163,7 +3157,6 @@ class LoweredAssignExp final : public AssignExp { public: Expression* lowering; - const char* toChars() const override; void accept(Visitor* v) override; }; @@ -3570,7 +3563,6 @@ class ThrownExceptionExp final : public Expression { public: ClassReferenceExp* thrown; - const char* toChars() const override; void accept(Visitor* v) override; }; @@ -3925,7 +3917,6 @@ class CtorDeclaration final : public FuncDeclaration bool isMoveCtor; CtorDeclaration* syntaxCopy(Dsymbol* s) override; const char* kind() const override; - const char* toChars() const override; bool isVirtual() const override; bool addPreInvariant() override; bool addPostInvariant() override; @@ -3938,7 +3929,6 @@ class DtorDeclaration final : public FuncDeclaration public: DtorDeclaration* syntaxCopy(Dsymbol* s) override; const char* kind() const override; - const char* toChars() const override; bool isVirtual() const override; bool addPreInvariant() override; bool addPostInvariant() override; @@ -6365,7 +6355,6 @@ class LinkDeclaration final : public AttribDeclaration LINK linkage; static LinkDeclaration* create(const Loc& loc, LINK p, Array* decl); LinkDeclaration* syntaxCopy(Dsymbol* s) override; - const char* toChars() const override; void accept(Visitor* v) override; }; @@ -6374,7 +6363,6 @@ class CPPMangleDeclaration final : public AttribDeclaration public: CPPMANGLE cppmangle; CPPMangleDeclaration* syntaxCopy(Dsymbol* s) override; - const char* toChars() const override; void accept(Visitor* v) override; }; @@ -6383,7 +6371,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration public: Expression* exp; CPPNamespaceDeclaration* syntaxCopy(Dsymbol* s) override; - const char* toChars() const override; void accept(Visitor* v) override; CPPNamespaceDeclaration* isCPPNamespaceDeclaration() override; }; @@ -6557,7 +6544,6 @@ class DebugCondition final : public DVCondition int32_t include(Scope* sc) override; DebugCondition* isDebugCondition() override; void accept(Visitor* v) override; - const char* toChars() const override; }; class VersionCondition final : public DVCondition @@ -6568,7 +6554,6 @@ class VersionCondition final : public DVCondition int32_t include(Scope* sc) override; VersionCondition* isVersionCondition() override; void accept(Visitor* v) override; - const char* toChars() const override; }; class StaticIfCondition final : public Condition @@ -6579,7 +6564,6 @@ class StaticIfCondition final : public Condition int32_t include(Scope* sc) override; void accept(Visitor* v) override; StaticIfCondition* isStaticIfCondition() override; - const char* toChars() const override; }; extern DArray preprocess(FileName csrcfile, const Loc& loc, OutBuffer& defines); @@ -6872,7 +6856,6 @@ class TypeInfoDeclaration : public VarDeclaration Type* tinfo; static TypeInfoDeclaration* create(Type* tinfo); TypeInfoDeclaration* syntaxCopy(Dsymbol* s) final override; - const char* toChars() const final override; TypeInfoDeclaration* isTypeInfoDeclaration() final override; void accept(Visitor* v) override; }; diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index 887878c8cff..613dc1c01aa 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -1390,11 +1390,6 @@ extern (C++) final class CtorDeclaration : FuncDeclaration return isCpCtor ? "copy constructor" : "constructor"; } - override const(char)* toChars() const - { - return "this"; - } - override bool isVirtual() const { return false; @@ -1496,11 +1491,6 @@ extern (C++) final class DtorDeclaration : FuncDeclaration return "destructor"; } - override const(char)* toChars() const - { - return "~this"; - } - override bool isVirtual() const { // D dtor's don't get put into the vtbl[] diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index af0bcccf7bb..c0fcf64be31 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -140,6 +140,42 @@ public const(char)* toChars(const Type t) return buf.extractChars(); } +public const(char)* toChars(const Dsymbol d) +{ + if (auto td = d.isTemplateDeclaration()) + { + HdrGenState hgs; + OutBuffer buf; + toCharsMaybeConstraints(td, buf, hgs); + return buf.extractChars(); + } + + if (auto ti = d.isTemplateInstance()) + { + OutBuffer buf; + toCBufferInstance(ti, buf); + return buf.extractChars(); + } + + if (auto tm = d.isTemplateMixin()) + { + OutBuffer buf; + toCBufferInstance(tm, buf); + return buf.extractChars(); + } + + if (auto tid = d.isTypeInfoDeclaration()) + { + OutBuffer buf; + buf.writestring("typeid("); + buf.writestring(tid.tinfo.toChars()); + buf.writeByte(')'); + return buf.extractChars(); + } + + return d.ident ? d.ident.toHChars2() : "__anonymous"; +} + public const(char)[] toString(const Initializer i) { OutBuffer buf; @@ -4504,7 +4540,15 @@ string EXPtoString(EXP op) EXP.declaration : "declaration", EXP.interval : "interval", - EXP.loweredAssignExp : "=" + EXP.loweredAssignExp : "=", + + EXP.thrownException : "CTFE ThrownException", + EXP.cantExpression : "", + EXP.voidExpression : "cast(void)0", + EXP.showCtfeContext : "", + EXP.break_ : "", + EXP.continue_ : "", + EXP.goto_ : "", ]; const p = strings[op]; if (!p) diff --git a/compiler/src/dmd/identifier.d b/compiler/src/dmd/identifier.d index ee7b57a0901..c3ea0f76b5d 100644 --- a/compiler/src/dmd/identifier.d +++ b/compiler/src/dmd/identifier.d @@ -108,7 +108,8 @@ nothrow: const(char)* p = null; if (this == Id.ctor) p = "this"; - else if (this == Id.dtor) + else if (this == Id.dtor || this == Id.__xdtor || this == Id.__fieldDtor || + this == Id.__aggrDtor || this == Id.cppdtor || this == Id.ticppdtor) p = "~this"; else if (this == Id.unitTest) p = "unittest"; diff --git a/compiler/src/dmd/template.h b/compiler/src/dmd/template.h index e751eadb5ae..cdb1c852f4b 100644 --- a/compiler/src/dmd/template.h +++ b/compiler/src/dmd/template.h @@ -79,7 +79,6 @@ class TemplateDeclaration final : public ScopeDsymbol bool overloadInsert(Dsymbol *s) override; bool hasStaticCtorOrDtor() override; const char *kind() const override; - const char *toChars() const override; Visibility visible() override; @@ -272,7 +271,6 @@ class TemplateInstance : public ScopeDsymbol Dsymbol *toAlias() override final; // resolve real symbol const char *kind() const override; bool oneMember(Dsymbol *&ps, Identifier *ident) override; - const char *toChars() const override; const char* toPrettyCharsHelper() override final; Identifier *getIdent() override final; @@ -292,7 +290,6 @@ class TemplateMixin final : public TemplateInstance const char *kind() const override; bool oneMember(Dsymbol *&ps, Identifier *ident) override; bool hasPointers() override; - const char *toChars() const override; TemplateMixin *isTemplateMixin() override { return this; } void accept(Visitor *v) override { v->visit(this); } diff --git a/compiler/test/compilable/extra-files/json.json b/compiler/test/compilable/extra-files/json.json index 8d1b3f73f06..a4e715edc8e 100644 --- a/compiler/test/compilable/extra-files/json.json +++ b/compiler/test/compilable/extra-files/json.json @@ -385,7 +385,7 @@ }, { "kind": "alias", - "name": "__xdtor", + "name": "~this", "protection": "public" } ],