Skip to content

Commit

Permalink
Move toChars overrides to hdrgen.d
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jan 30, 2025
1 parent bfbac11 commit 8b99f8d
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 139 deletions.
31 changes: 0 additions & 31 deletions compiler/src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,6 @@ extern (C++) final class StaticIfCondition : Condition
{
return this;
}

override const(char)* toChars() const
{
return exp ? exp.toChars() : "static if".ptr;
}
}


Expand Down
10 changes: 0 additions & 10 deletions compiler/src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dmd/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
22 changes: 0 additions & 22 deletions compiler/src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
42 changes: 6 additions & 36 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -5035,27 +5031,6 @@ extern (C++) final class CTFEExp : Expression
type = Type.tvoid;
}

override const(char)* toChars() const
{
switch (op)
{
case EXP.cantExpression:
return "<cant>";
case EXP.voidExpression:
return "cast(void)0";
case EXP.showCtfeContext:
return "<error>";
case EXP.break_:
return "<break>";
case EXP.continue_:
return "<continue>";
case EXP.goto_:
return "<goto>";
default:
assert(0);
}
}

extern (D) __gshared CTFEExp cantexp;
extern (D) __gshared CTFEExp voidexp;
extern (D) __gshared CTFEExp breakexp;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 2 additions & 17 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -3163,7 +3157,6 @@ class LoweredAssignExp final : public AssignExp
{
public:
Expression* lowering;
const char* toChars() const override;
void accept(Visitor* v) override;
};

Expand Down Expand Up @@ -3570,7 +3563,6 @@ class ThrownExceptionExp final : public Expression
{
public:
ClassReferenceExp* thrown;
const char* toChars() const override;
void accept(Visitor* v) override;
};

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -6365,7 +6355,6 @@ class LinkDeclaration final : public AttribDeclaration
LINK linkage;
static LinkDeclaration* create(const Loc& loc, LINK p, Array<Dsymbol* >* decl);
LinkDeclaration* syntaxCopy(Dsymbol* s) override;
const char* toChars() const override;
void accept(Visitor* v) override;
};

Expand All @@ -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;
};

Expand All @@ -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;
};
Expand Down Expand Up @@ -6579,7 +6566,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<uint8_t > preprocess(FileName csrcfile, const Loc& loc, OutBuffer& defines);
Expand Down Expand Up @@ -6872,7 +6858,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;
};
Expand Down
10 changes: 0 additions & 10 deletions compiler/src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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[]
Expand Down
Loading

0 comments on commit 8b99f8d

Please sign in to comment.