diff --git a/compiler/src/dmd/aggregate.h b/compiler/src/dmd/aggregate.h index 8fd12e1d168a..b3f5e6f05709 100644 --- a/compiler/src/dmd/aggregate.h +++ b/compiler/src/dmd/aggregate.h @@ -46,6 +46,8 @@ namespace dmd FuncDeclaration *search_toString(StructDeclaration *sd); void semanticTypeInfoMembers(StructDeclaration *sd); bool fill(StructDeclaration* sd, const Loc &loc, Expressions &elements, bool ctorinit); + Scope* newScope(AggregateDeclaration *d, Scope* sc); + Scope* newScope(AttribDeclaration *d, Scope* sc); } enum class ClassKind : uint8_t @@ -117,7 +119,6 @@ class AggregateDeclaration : public ScopeDsymbol d_bool disableNew; // disallow allocations using `new` Sizeok sizeok; // set when structsize contains valid data - virtual Scope *newScope(Scope *sc); virtual void finalizeSize() = 0; uinteger_t size(const Loc &loc) override final; Type *getType() override final; @@ -281,7 +282,6 @@ class ClassDeclaration : public AggregateDeclaration static ClassDeclaration *create(const Loc &loc, Identifier *id, BaseClasses *baseclasses, Dsymbols *members, bool inObject); const char *toPrettyChars(bool QualifyTypes = false) override; ClassDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; #define OFFSET_RUNTIME 0x76543210 #define OFFSET_FWDREF 0x76543211 @@ -313,7 +313,6 @@ class InterfaceDeclaration final : public ClassDeclaration { public: InterfaceDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; bool isBaseOf(ClassDeclaration *cd, int *poffset) override; const char *kind() const override; int vtblOffset() const override; diff --git a/compiler/src/dmd/dclass.d b/compiler/src/dmd/dclass.d index c99d27559b22..5ab004016865 100644 --- a/compiler/src/dmd/dclass.d +++ b/compiler/src/dmd/dclass.d @@ -409,19 +409,6 @@ extern (C++) class ClassDeclaration : AggregateDeclaration return cd; } - override Scope* newScope(Scope* sc) - { - auto sc2 = super.newScope(sc); - if (isCOMclass()) - { - /* This enables us to use COM objects under Linux and - * work with things like XPCOM - */ - sc2.linkage = target.systemLinkage(); - } - return sc2; - } - /********************************************* * Determine if 'this' is a base class of cd. * This is used to detect circular inheritance only. @@ -975,19 +962,6 @@ extern (C++) final class InterfaceDeclaration : ClassDeclaration return id; } - - override Scope* newScope(Scope* sc) - { - auto sc2 = super.newScope(sc); - if (com) - sc2.linkage = LINK.windows; - else if (classKind == ClassKind.cpp) - sc2.linkage = LINK.cpp; - else if (classKind == ClassKind.objc) - sc2.linkage = LINK.objc; - return sc2; - } - /******************************************* * Determine if 'this' is a base class of cd. * (Actually, if it is an interface supported by cd) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 173532af397c..9d1f8ff15fab 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7349,7 +7349,7 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } } -extern(D) Scope* newScope(Dsymbol d, Scope* sc) +extern(D) Scope* newScope(AttribDeclaration d, Scope* sc) { scope nsv = new NewScopeVisitor(sc); d.accept(nsv); @@ -7484,6 +7484,48 @@ private extern(C++) class NewScopeVisitor : Visitor } } +//newScope of Aggregate Declaration. +extern(D) Scope* newScope(AggregateDeclaration d, Scope* sc) +{ + scope nsv = new NewScopeVisitor(sc); + d.accept(nsv); + return nsv.sc; +} + +private extern(C++) class NewScopeVisitor2 : Visitor +{ + alias visit = typeof(super).visit; + Scope* sc; + this(Scope* sc) + { + this.sc = sc; + } + + override void visit(ClassDeclaration cld) + { + auto sc2 = (cast(AggregateDeclaration)cld).newScope(sc); + if (cld.isCOMclass()) + { + /* This enables us to use COM objects under Linux and + * work with things like XPCOM + */ + sc2.linkage = target.systemLinkage(); + } + sc = sc2; + } + + override void visit(InterfaceDeclaration ifd) + { + auto sc2 = (cast(ClassDeclaration)ifd).newScope(sc); + if (ifd.com) + sc2.linkage = LINK.windows; + else if (ifd.classKind == ClassKind.cpp) + sc2.linkage = LINK.cpp; + else if (ifd.classKind == ClassKind.objc) + sc2.linkage = LINK.objc; + sc = sc2; + } +} extern(C++) Dsymbols* include(Dsymbol d, Scope* sc) { diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 4162052b111f..fc76e2af86b1 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -6508,7 +6508,6 @@ class ClassDeclaration : public AggregateDeclaration static ClassDeclaration* create(const Loc& loc, Identifier* id, Array* baseclasses, Array* members, bool inObject); const char* toPrettyChars(bool qualifyTypes = false) override; ClassDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; enum : int32_t { OFFSET_RUNTIME = 1985229328 }; enum : int32_t { OFFSET_FWDREF = 1985229329 }; @@ -6536,7 +6535,6 @@ class InterfaceDeclaration final : public ClassDeclaration { public: InterfaceDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; bool isBaseOf(ClassDeclaration* cd, int32_t* poffset) override; const char* kind() const override; int32_t vtblOffset() const override; diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 51669b51a8e1..2a44bf2995c3 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -234,6 +234,7 @@ void test_visitors() ClassDeclaration *cd = ClassDeclaration::create(loc, Identifier::idPool("TypeInfo"), NULL, NULL, true); assert(cd->isClassDeclaration() == cd); assert(cd->vtblOffset() == 1); + //assert(dmd::vtblOffset(cd) == 1); cd->accept(&tv); assert(tv.aggr == true);