@@ -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+ }
0 commit comments