Skip to content

Commit 69b2b10

Browse files
authored
Extracted Dsymbol.hasPointers to visitor in dsymbolsem (dlang#21140)
1 parent 857d4a6 commit 69b2b10

File tree

16 files changed

+61
-44
lines changed

16 files changed

+61
-44
lines changed

compiler/src/dmd/attrib.d

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
110110
return "attribute";
111111
}
112112

113-
override final bool hasPointers()
114-
{
115-
return this.include(null).foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
116-
}
117-
118113
/****************************************
119114
*/
120115
override final void addObjcSymbols(ClassDeclarations* classes, ClassDeclarations* categories)

compiler/src/dmd/attrib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class AttribDeclaration : public Dsymbol
2929
public:
3030
Dsymbols *decl; // array of Dsymbol's
3131
const char *kind() const override;
32-
bool hasPointers() override final;
3332
void accept(Visitor *v) override { v->visit(this); }
3433
};
3534

compiler/src/dmd/cxxfrontend.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ bool isAbstract(ClassDeclaration cd)
198198
return dmd.dsymbolsem.isAbstract(cd);
199199
}
200200

201+
bool hasPointers(Dsymbol d)
202+
{
203+
import dmd.dsymbolsem;
204+
return dmd.dsymbolsem.hasPointers(d);
205+
}
206+
201207
/***********************************************************
202208
* dtemplate.d
203209
*/

compiler/src/dmd/declaration.d

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,6 @@ extern (C++) class VarDeclaration : Declaration
10351035
vbitoffset < bitoffset + tbitsize;
10361036
}
10371037

1038-
override final bool hasPointers()
1039-
{
1040-
//printf("VarDeclaration::hasPointers() %s, ty = %d\n", toChars(), type.ty);
1041-
return (!isDataseg() && type.hasPointers());
1042-
}
1043-
10441038
/*************************************
10451039
* Return true if we can take the address of this variable.
10461040
*/

compiler/src/dmd/declaration.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ class VarDeclaration : public Declaration
298298
bool isThreadlocal() override final;
299299
bool isCTFE();
300300
bool isOverlappedWith(VarDeclaration *v);
301-
bool hasPointers() override final;
302301
bool canTakeAddressOf();
303302
bool needsScopeDtor();
304303
Dsymbol *toAlias() override final;

compiler/src/dmd/dstruct.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ extern (C++) class StructDeclaration : AggregateDeclaration
158158
return;
159159
foreach (vd; fields)
160160
{
161+
import dmd.dsymbolsem : hasPointers;
161162
if (vd.storage_class & STC.ref_ || vd.hasPointers())
162163
{
163164
hasPointerField = true;
164165
hasUnsafeBitpatterns = true;
165166
}
166167

167-
if (vd._init && vd._init.isVoidInitializer() && vd.type.hasPointers())
168+
if (vd._init && vd._init.isVoidInitializer() && vd.hasPointers())
168169
hasVoidInitPointers = true;
169170

170171
if (vd.storage_class & STC.system || vd.type.hasUnsafeBitpatterns())

compiler/src/dmd/dsymbol.d

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,15 +963,6 @@ extern (C++) class Dsymbol : ASTNode
963963
return true;
964964
}
965965

966-
/*****************************************
967-
* Is Dsymbol a variable that contains pointers?
968-
*/
969-
bool hasPointers()
970-
{
971-
//printf("Dsymbol::hasPointers() %s\n", toChars());
972-
return false;
973-
}
974-
975966
void addObjcSymbols(ClassDeclarations* classes, ClassDeclarations* categories)
976967
{
977968
}

compiler/src/dmd/dsymbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ class Dsymbol : public ASTNode
243243
virtual bool needThis(); // need a 'this' pointer?
244244
virtual Visibility visible();
245245
virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
246-
virtual bool hasPointers();
247246
virtual void addObjcSymbols(ClassDeclarations *, ClassDeclarations *) { }
248247

249248
virtual void addComment(const utf8_t *comment);
@@ -428,4 +427,5 @@ namespace dmd
428427
Dsymbols *include(Dsymbol *d, Scope *sc);
429428
void setScope(Dsymbol *d, Scope *sc);
430429
void importAll(Dsymbol *d, Scope *sc);
430+
bool hasPointers(Dsymbol *d);
431431
}

compiler/src/dmd/dsymbolsem.d

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,8 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
953953
if (dsym.storage_class & STC.constscoperef)
954954
dsym.storage_class |= STC.scope_;
955955

956+
import dmd.typesem : hasPointers;
957+
956958
if (dsym.storage_class & STC.scope_)
957959
{
958960
STC stc = dsym.storage_class & (STC.static_ | STC.extern_ | STC.manifest | STC.gshared);
@@ -8641,3 +8643,50 @@ private extern(C++) class FinalizeSizeVisitor : Visitor
86418643
sd.argTypes = target.toArgTypes(sd.type);
86428644
}
86438645
}
8646+
8647+
/*****************************************
8648+
* Is Dsymbol a variable that contains pointers?
8649+
*/
8650+
bool hasPointers(Dsymbol d)
8651+
{
8652+
scope v = new HasPointersVisitor();
8653+
d.accept(v);
8654+
return v.result;
8655+
}
8656+
8657+
private extern(C++) class HasPointersVisitor : Visitor
8658+
{
8659+
import dmd.mtype : Type;
8660+
8661+
alias visit = Visitor.visit;
8662+
bool result;
8663+
8664+
override void visit(AttribDeclaration ad)
8665+
{
8666+
result = ad.include(null).foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
8667+
}
8668+
8669+
override void visit(VarDeclaration vd)
8670+
{
8671+
import dmd.typesem : hasPointers;
8672+
result = (!vd.isDataseg() && vd.type.hasPointers());
8673+
}
8674+
8675+
override void visit(Dsymbol d)
8676+
{
8677+
//printf("Dsymbol::hasPointers() %s\n", toChars());
8678+
result = false;
8679+
}
8680+
8681+
override void visit(TemplateMixin tm)
8682+
{
8683+
//printf("TemplateMixin.hasPointers() %s\n", toChars());
8684+
result = tm.members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
8685+
}
8686+
8687+
override void visit(Nspace ns)
8688+
{
8689+
//printf("Nspace::hasPointers() %s\n", toChars());
8690+
result = ns.members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
8691+
}
8692+
}

compiler/src/dmd/dtemplate.d

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,12 +5490,6 @@ extern (C++) final class TemplateMixin : TemplateInstance
54905490
return "mixin";
54915491
}
54925492

5493-
override bool hasPointers()
5494-
{
5495-
//printf("TemplateMixin.hasPointers() %s\n", toChars());
5496-
return members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
5497-
}
5498-
54995493
extern (D) bool findTempDecl(Scope* sc)
55005494
{
55015495
// Follow qualifications to find the TemplateDeclaration

0 commit comments

Comments
 (0)