Skip to content

Commit

Permalink
Move toChars overrides to hdrgen.d (#20804)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 30, 2025
1 parent bfbac11 commit f4558fe
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 168 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
3 changes: 0 additions & 3 deletions compiler/src/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
};

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

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

Expand Down
15 changes: 0 additions & 15 deletions compiler/src/dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,6 @@ extern (C++) final class DebugCondition : DVCondition
{
v.visit(this);
}

override const(char)* toChars() const
{
return ident ? ident.toChars() : "debug".ptr;
}
}

/**
Expand Down Expand Up @@ -887,11 +882,6 @@ extern (C++) final class VersionCondition : DVCondition
{
v.visit(this);
}

override const(char)* toChars() const
{
return ident ? ident.toChars() : "version".ptr;
}
}

/***********************************************************
Expand Down Expand Up @@ -961,11 +951,6 @@ extern (C++) final class StaticIfCondition : Condition
{
return this;
}

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


Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dmd/ctfe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
};

Expand All @@ -58,6 +57,4 @@ class ThrownExceptionExp final : public Expression

class CTFEExp final : public Expression
{
public:
const char *toChars() const override;
};
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
3 changes: 0 additions & 3 deletions compiler/src/dmd/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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;
Expand All @@ -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;
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
2 changes: 1 addition & 1 deletion compiler/src/dmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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
4 changes: 1 addition & 3 deletions compiler/src/dmd/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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); }
};

Expand Down
Loading

0 comments on commit f4558fe

Please sign in to comment.