mirror of
https://github.com/dlang/dmd.git
synced 2025-04-28 14:10:11 +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.dmodule;
|
||||||
import dmd.dscope;
|
import dmd.dscope;
|
||||||
import dmd.dsymbol;
|
import dmd.dsymbol;
|
||||||
import dmd.dsymbolsem : setScope, addMember, include;
|
import dmd.dsymbolsem : include;
|
||||||
import dmd.expression;
|
import dmd.expression;
|
||||||
import dmd.func;
|
import dmd.func;
|
||||||
import dmd.globals;
|
import dmd.globals;
|
||||||
|
@ -125,11 +125,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
|
||||||
return this.include(null).foreachDsymbol( (s) { return s.hasStaticCtorOrDtor(); } ) != 0;
|
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)
|
override final void addObjcSymbols(ClassDeclarations* classes, ClassDeclarations* categories)
|
||||||
|
|
|
@ -32,7 +32,6 @@ public:
|
||||||
bool oneMember(Dsymbol *&ps, Identifier *ident) override;
|
bool oneMember(Dsymbol *&ps, Identifier *ident) override;
|
||||||
bool hasPointers() override final;
|
bool hasPointers() override final;
|
||||||
bool hasStaticCtorOrDtor() override final;
|
bool hasStaticCtorOrDtor() override final;
|
||||||
void checkCtorConstInit() override final;
|
|
||||||
AttribDeclaration *isAttribDeclaration() override { return this; }
|
AttribDeclaration *isAttribDeclaration() override { return this; }
|
||||||
|
|
||||||
void accept(Visitor *v) override { v->visit(this); }
|
void accept(Visitor *v) override { v->visit(this); }
|
||||||
|
|
|
@ -1129,16 +1129,6 @@ extern (C++) class VarDeclaration : Declaration
|
||||||
return e;
|
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
|
* Check to see if this variable is actually in an enclosing function
|
||||||
* rather than the current one.
|
* rather than the current one.
|
||||||
|
|
|
@ -298,7 +298,6 @@ public:
|
||||||
bool hasPointers() override final;
|
bool hasPointers() override final;
|
||||||
bool canTakeAddressOf();
|
bool canTakeAddressOf();
|
||||||
bool needsScopeDtor();
|
bool needsScopeDtor();
|
||||||
void checkCtorConstInit() override final;
|
|
||||||
Dsymbol *toAlias() override final;
|
Dsymbol *toAlias() override final;
|
||||||
// Eliminate need for dynamic_cast
|
// Eliminate need for dynamic_cast
|
||||||
VarDeclaration *isVarDeclaration() override final { return (VarDeclaration *)this; }
|
VarDeclaration *isVarDeclaration() override final { return (VarDeclaration *)this; }
|
||||||
|
|
|
@ -916,10 +916,6 @@ extern (C++) class Dsymbol : ASTNode
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkCtorConstInit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************
|
/****************************************
|
||||||
* Add documentation comment to Dsymbol.
|
* Add documentation comment to Dsymbol.
|
||||||
* Ignore NULL comments.
|
* Ignore NULL comments.
|
||||||
|
|
|
@ -241,7 +241,6 @@ public:
|
||||||
virtual bool hasPointers();
|
virtual bool hasPointers();
|
||||||
virtual bool hasStaticCtorOrDtor();
|
virtual bool hasStaticCtorOrDtor();
|
||||||
virtual void addObjcSymbols(ClassDeclarations *, ClassDeclarations *) { }
|
virtual void addObjcSymbols(ClassDeclarations *, ClassDeclarations *) { }
|
||||||
virtual void checkCtorConstInit() { }
|
|
||||||
|
|
||||||
virtual void addComment(const utf8_t *comment);
|
virtual void addComment(const utf8_t *comment);
|
||||||
const utf8_t *comment(); // current value of comment
|
const utf8_t *comment(); // current value of comment
|
||||||
|
|
|
@ -7939,3 +7939,31 @@ extern (C++) class AddCommentVisitor: Visitor
|
||||||
}
|
}
|
||||||
override void visit(StaticForeachDeclaration sfd) {}
|
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 hasPointers();
|
||||||
virtual bool hasStaticCtorOrDtor();
|
virtual bool hasStaticCtorOrDtor();
|
||||||
virtual void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories);
|
virtual void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories);
|
||||||
virtual void checkCtorConstInit();
|
|
||||||
virtual void addComment(const char* comment);
|
virtual void addComment(const char* comment);
|
||||||
const char* comment();
|
const char* comment();
|
||||||
void comment(const char* comment);
|
void comment(const char* comment);
|
||||||
|
@ -6328,7 +6327,6 @@ public:
|
||||||
bool oneMember(Dsymbol*& ps, Identifier* ident) override;
|
bool oneMember(Dsymbol*& ps, Identifier* ident) override;
|
||||||
bool hasPointers() final override;
|
bool hasPointers() final override;
|
||||||
bool hasStaticCtorOrDtor() final override;
|
bool hasStaticCtorOrDtor() final override;
|
||||||
void checkCtorConstInit() final override;
|
|
||||||
void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories) final override;
|
void addObjcSymbols(Array<ClassDeclaration* >* classes, Array<ClassDeclaration* >* categories) final override;
|
||||||
AttribDeclaration* isAttribDeclaration() override;
|
AttribDeclaration* isAttribDeclaration() override;
|
||||||
void accept(Visitor* v) override;
|
void accept(Visitor* v) override;
|
||||||
|
@ -6831,7 +6829,6 @@ public:
|
||||||
bool hasPointers() final override;
|
bool hasPointers() final override;
|
||||||
bool canTakeAddressOf();
|
bool canTakeAddressOf();
|
||||||
bool needsScopeDtor();
|
bool needsScopeDtor();
|
||||||
void checkCtorConstInit() final override;
|
|
||||||
Dsymbol* toAlias() final override;
|
Dsymbol* toAlias() final override;
|
||||||
VarDeclaration* isVarDeclaration() final override;
|
VarDeclaration* isVarDeclaration() final override;
|
||||||
void accept(Visitor* v) override;
|
void accept(Visitor* v) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue