From a88cfdbdda7d9dd18ffea8bd76c712d50d499840 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Mon, 28 Oct 2024 19:19:32 +0100 Subject: [PATCH 1/7] Move newScope method from dclass to dsymbolsem --- compiler/src/dmd/dclass.d | 26 -------------------------- compiler/src/dmd/dsymbolsem.d | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 27 deletions(-) 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..9ffefe140015 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7482,8 +7482,32 @@ private extern(C++) class NewScopeVisitor : Visitor } sc = sc2; } -} + override void visit(ClassDeclaration cld) + { + auto sc2 = 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 = 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) { From fc528567cb0172e6bae2dfdd3295dff41051b2cf Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Tue, 29 Oct 2024 23:20:54 +0100 Subject: [PATCH 2/7] Update frontend --- compiler/src/dmd/dsymbol.h | 1 + compiler/src/dmd/frontend.h | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 7b33ed2910bf..ef777ac8033c 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -433,4 +433,5 @@ namespace dmd Dsymbols *include(Dsymbol *d, Scope *sc); void setScope(Dsymbol *d, Scope *sc); void importAll(Dsymbol *d, Scope *sc); + Scope* newScope(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; From aaf9c8a97ea891f7de8dd126460faf526ea04510 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Fri, 1 Nov 2024 10:50:01 +0100 Subject: [PATCH 3/7] Fix newScope --- compiler/src/dmd/dsymbolsem.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 9ffefe140015..d7c3b4879cd6 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7485,7 +7485,7 @@ private extern(C++) class NewScopeVisitor : Visitor override void visit(ClassDeclaration cld) { - auto sc2 = cld.newScope(sc); + auto sc2 = (cast(AggregateDeclaration)cld).newScope(sc); if (cld.isCOMclass()) { /* This enables us to use COM objects under Linux and @@ -7498,7 +7498,7 @@ private extern(C++) class NewScopeVisitor : Visitor override void visit(InterfaceDeclaration ifd) { - auto sc2 = ifd.newScope(sc); + auto sc2 = (cast(ClassDeclaration)ifd).newScope(sc); if (ifd.com) sc2.linkage = LINK.windows; else if (ifd.classKind == ClassKind.cpp) From 1bc2057ad95e88d7ed7ed440b71f33830632ccd8 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Tue, 5 Nov 2024 23:14:29 +0100 Subject: [PATCH 4/7] Add a newScope visitor of AggregateDeclaration --- compiler/src/dmd/dsymbolsem.d | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index d7c3b4879cd6..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); @@ -7482,6 +7482,24 @@ private extern(C++) class NewScopeVisitor : Visitor } sc = sc2; } +} + +//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) { From 252eb9a3d1b3b3188c2a438e6a22a3f7adc1ea6f Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Thu, 7 Nov 2024 15:16:43 +0100 Subject: [PATCH 5/7] Fix test suits errors --- compiler/src/dmd/aggregate.h | 3 --- compiler/src/dmd/dsymbol.h | 3 ++- compiler/src/tests/cxxfrontend.cc | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/src/dmd/aggregate.h b/compiler/src/dmd/aggregate.h index 8fd12e1d168a..585c6f92a196 100644 --- a/compiler/src/dmd/aggregate.h +++ b/compiler/src/dmd/aggregate.h @@ -117,7 +117,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 +280,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 +311,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/dsymbol.h b/compiler/src/dmd/dsymbol.h index ef777ac8033c..28899e3e0702 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -433,5 +433,6 @@ namespace dmd Dsymbols *include(Dsymbol *d, Scope *sc); void setScope(Dsymbol *d, Scope *sc); void importAll(Dsymbol *d, Scope *sc); - Scope* newScope(Dsymbol *d, Scope *sc); + Scope* newScope(AggregateDeclaration d, Scope* sc); + Scope* newScope(AttribDeclaration d, Scope* sc); } diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 51669b51a8e1..9ece3bc4e26c 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -233,7 +233,8 @@ void test_visitors() ClassDeclaration *cd = ClassDeclaration::create(loc, Identifier::idPool("TypeInfo"), NULL, NULL, true); assert(cd->isClassDeclaration() == cd); - assert(cd->vtblOffset() == 1); + //assert(cd->vtblOffset() == 1); + assert(vtblOffset(cd) == 1); cd->accept(&tv); assert(tv.aggr == true); From fde12114358e0e81228ccf76f9e6ff8aaf6b65c3 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Mon, 11 Nov 2024 12:01:45 +0100 Subject: [PATCH 6/7] fix test errors --- compiler/src/dmd/dsymbol.h | 2 -- compiler/src/tests/cxxfrontend.cc | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 28899e3e0702..7b33ed2910bf 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -433,6 +433,4 @@ namespace dmd Dsymbols *include(Dsymbol *d, Scope *sc); void setScope(Dsymbol *d, Scope *sc); void importAll(Dsymbol *d, Scope *sc); - Scope* newScope(AggregateDeclaration d, Scope* sc); - Scope* newScope(AttribDeclaration d, Scope* sc); } diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 9ece3bc4e26c..6a8e53d9ab66 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -233,8 +233,8 @@ void test_visitors() ClassDeclaration *cd = ClassDeclaration::create(loc, Identifier::idPool("TypeInfo"), NULL, NULL, true); assert(cd->isClassDeclaration() == cd); - //assert(cd->vtblOffset() == 1); - assert(vtblOffset(cd) == 1); + assert(cd->vtblOffset() == 1); + //assert(vtblOffset(cd) == 1); cd->accept(&tv); assert(tv.aggr == true); From 2fc1a5914b3d9770e64b73dcff29ae365c85e5ed Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Thu, 14 Nov 2024 00:47:50 +0100 Subject: [PATCH 7/7] update aggregate.h --- compiler/src/dmd/aggregate.h | 2 ++ compiler/src/tests/cxxfrontend.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dmd/aggregate.h b/compiler/src/dmd/aggregate.h index 585c6f92a196..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 diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 6a8e53d9ab66..2a44bf2995c3 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -234,7 +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(vtblOffset(cd) == 1); + //assert(dmd::vtblOffset(cd) == 1); cd->accept(&tv); assert(tv.aggr == true);