mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
Extract Dsymbol.checkCtorConstInit and make it a visitor in dsymbolsem (#20819)
This commit is contained in:
parent
60a3060cdf
commit
f88520c3c1
8 changed files with 29 additions and 26 deletions
|
@ -32,7 +32,7 @@ import dmd.declaration;
|
|||
import dmd.dmodule;
|
||||
import dmd.dscope;
|
||||
import dmd.dsymbol;
|
||||
import dmd.dsymbolsem : setScope, addMember, include;
|
||||
import dmd.dsymbolsem : include;
|
||||
import dmd.expression;
|
||||
import dmd.func;
|
||||
import dmd.globals;
|
||||
|
@ -125,11 +125,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
|
|||
return this.include(null).foreachDsymbol( (s) { return s.hasStaticCtorOrDtor(); } ) != 0;
|
||||
}
|
||||
|
||||
override final void checkCtorConstInit()
|
||||
{
|
||||
this.include(null).foreachDsymbol( s => s.checkCtorConstInit() );
|
||||
}
|
||||
|
||||
/****************************************
|
||||
*/
|
||||
override final void addObjcSymbols(ClassDeclarations* classes, ClassDeclarations* categories)
|
||||
|
|
|
@ -32,7 +32,6 @@ public:
|
|||
bool oneMember(Dsymbol *&ps, Identifier *ident) override;
|
||||
bool hasPointers() override final;
|
||||
bool hasStaticCtorOrDtor() override final;
|
||||
void checkCtorConstInit() override final;
|
||||
AttribDeclaration *isAttribDeclaration() override { return this; }
|
||||
|
||||
void accept(Visitor *v) override { v->visit(this); }
|
||||
|
|
|
@ -1129,16 +1129,6 @@ extern (C++) class VarDeclaration : Declaration
|
|||
return e;
|
||||
}
|
||||
|
||||
override final void checkCtorConstInit()
|
||||
{
|
||||
version (none)
|
||||
{
|
||||
/* doesn't work if more than one static ctor */
|
||||
if (ctorinit == 0 && isCtorinit() && !isField())
|
||||
error("missing initializer in static constructor for const variable");
|
||||
}
|
||||
}
|
||||
|
||||
/************************************
|
||||
* Check to see if this variable is actually in an enclosing function
|
||||
* rather than the current one.
|
||||
|
|
|
@ -298,7 +298,6 @@ public:
|
|||
bool hasPointers() override final;
|
||||
bool canTakeAddressOf();
|
||||
bool needsScopeDtor();
|
||||
void checkCtorConstInit() override final;
|
||||
Dsymbol *toAlias() override final;
|
||||
// Eliminate need for dynamic_cast
|
||||
VarDeclaration *isVarDeclaration() override final { return (VarDeclaration *)this; }
|
||||
|
|
|
@ -916,10 +916,6 @@ extern (C++) class Dsymbol : ASTNode
|
|||
{
|
||||
}
|
||||
|
||||
void checkCtorConstInit()
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* Add documentation comment to Dsymbol.
|
||||
* Ignore NULL comments.
|
||||
|
|
|
@ -241,7 +241,6 @@ public:
|
|||
virtual bool hasPointers();
|
||||
virtual bool hasStaticCtorOrDtor();
|
||||
virtual void addObjcSymbols(ClassDeclarations *, ClassDeclarations *) { }
|
||||
virtual void checkCtorConstInit() { }
|
||||
|
||||
virtual void addComment(const utf8_t *comment);
|
||||
const utf8_t *comment(); // current value of comment
|
||||
|
|
|
@ -7939,3 +7939,31 @@ extern (C++) class AddCommentVisitor: Visitor
|
|||
}
|
||||
override void visit(StaticForeachDeclaration sfd) {}
|
||||
}
|
||||
|
||||
void checkCtorConstInit(Dsymbol d)
|
||||
{
|
||||
scope v = new CheckCtorConstInitVisitor();
|
||||
d.accept(v);
|
||||
}
|
||||
|
||||
private extern(C++) class CheckCtorConstInitVisitor : Visitor
|
||||
{
|
||||
alias visit = Visitor.visit;
|
||||
|
||||
override void visit(AttribDeclaration ad)
|
||||
{
|
||||
ad.include(null).foreachDsymbol( s => s.checkCtorConstInit() );
|
||||
}
|
||||
|
||||
override void visit(VarDeclaration vd)
|
||||
{
|
||||
version (none)
|
||||
{
|
||||
/* doesn't work if more than one static ctor */
|
||||
if (vd.ctorinit == 0 && vd.isCtorinit() && !vd.isField())
|
||||
error("missing initializer in static constructor for const variable");
|
||||
}
|
||||
}
|
||||
|
||||
override void visit(Dsymbol d){}
|
||||
}
|
||||
|
|
|
@ -514,7 +514,6 @@ public:
|
|||
virtual bool hasPointers();
|
||||
virtual bool hasStaticCtorOrDtor();
|
||||
virtual void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories);
|
||||
virtual void checkCtorConstInit();
|
||||
virtual void addComment(const char* comment);
|
||||
const char* comment();
|
||||
void comment(const char* comment);
|
||||
|
@ -6328,7 +6327,6 @@ public:
|
|||
bool oneMember(Dsymbol*& ps, Identifier* ident) override;
|
||||
bool hasPointers() final override;
|
||||
bool hasStaticCtorOrDtor() final override;
|
||||
void checkCtorConstInit() final override;
|
||||
void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories) final override;
|
||||
AttribDeclaration* isAttribDeclaration() override;
|
||||
void accept(Visitor* v) override;
|
||||
|
@ -6831,7 +6829,6 @@ public:
|
|||
bool hasPointers() final override;
|
||||
bool canTakeAddressOf();
|
||||
bool needsScopeDtor();
|
||||
void checkCtorConstInit() final override;
|
||||
Dsymbol* toAlias() final override;
|
||||
VarDeclaration* isVarDeclaration() final override;
|
||||
void accept(Visitor* v) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue