From c01f76b25b4eb210d92d0ab858dd025ee72bfc6a Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Thu, 12 Sep 2024 04:39:06 +0200 Subject: [PATCH 01/17] extract newScope to dsymbolsem --- compiler/src/dmd/attrib.d | 119 +++-------------------------- compiler/src/dmd/dsymbolsem.d | 136 ++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 108 deletions(-) diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index db14f9a1cc3f..e38788bf1c84 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -32,7 +32,7 @@ import dmd.declaration; import dmd.dmodule; import dmd.dscope; import dmd.dsymbol; -import dmd.dsymbolsem; +//import dmd.dsymbolsem; import dmd.errors; import dmd.expression; import dmd.func; @@ -113,14 +113,7 @@ extern (C++) abstract class AttribDeclaration : Dsymbol return sc2; } - /**************************************** - * A hook point to supply scope for members. - * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. - */ - Scope* newScope(Scope* sc) - { - return sc; - } + override void addComment(const(char)* comment) { @@ -202,27 +195,7 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration return new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - StorageClass scstc = sc.stc; - /* These sets of storage classes are mutually exclusive, - * so choose the innermost or most recent one. - */ - if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) - scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest); - if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) - scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared); - if (stc & (STC.const_ | STC.immutable_ | STC.manifest)) - scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest); - if (stc & (STC.gshared | STC.shared_)) - scstc &= ~(STC.gshared | STC.shared_); - if (stc & (STC.safe | STC.trusted | STC.system)) - scstc &= ~(STC.safe | STC.trusted | STC.system); - scstc |= stc; - //printf("scstc = x%llx\n", scstc); - return createNewScope(sc, scstc, sc.linkage, sc.cppmangle, - sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); - } + override final bool oneMember(out Dsymbol ps, Identifier ident) { @@ -286,24 +259,7 @@ extern (C++) final class DeprecatedDeclaration : StorageClassDeclaration return new DeprecatedDeclaration(msg.syntaxCopy(), Dsymbol.arraySyntaxCopy(decl)); } - /** - * Provides a new scope with `STC.deprecated_` and `Scope.depdecl` set - * - * Calls `StorageClassDeclaration.newScope` (as it must be called or copied - * in any function overriding `newScope`), then set the `Scope`'s depdecl. - * - * Returns: - * Always a new scope, to use for this `DeprecatedDeclaration`'s members. - */ - override Scope* newScope(Scope* sc) - { - auto scx = super.newScope(sc); - // The enclosing scope is deprecated as well - if (scx == sc) - scx = sc.push(); - scx.depdecl = this; - return scx; - } + override void accept(Visitor v) { @@ -339,11 +295,6 @@ extern (C++) final class LinkDeclaration : AttribDeclaration return new LinkDeclaration(loc, linkage, Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - return createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, - sc.aligndecl, sc.inlining); - } override const(char)* toChars() const { @@ -386,11 +337,7 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration return new CPPMangleDeclaration(loc, cppmangle, Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - return createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, - sc.aligndecl, sc.inlining); - } + override const(char)* toChars() const { @@ -462,17 +409,7 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration this.loc, this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.cppnamespace); } - /** - * Returns: - * A copy of the parent scope, with `this` as `namespace` and C++ linkage - */ - override Scope* newScope(Scope* sc) - { - auto scx = sc.copy(); - scx.linkage = LINK.cpp; - scx.namespace = this; - return scx; - } + override const(char)* toChars() const { @@ -545,12 +482,7 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration return new VisibilityDeclaration(this.loc, visibility, Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - if (pkg_identifiers) - dsymbolSemantic(this, sc); - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); - } + override const(char)* kind() const { @@ -621,10 +553,7 @@ extern (C++) final class AlignDeclaration : AttribDeclaration Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); - } + override void accept(Visitor v) { @@ -694,16 +623,7 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration return new PragmaDeclaration(loc, ident, Expression.arraySyntaxCopy(args), Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - if (ident == Id.Pinline) - { - // We keep track of this pragma inside scopes, - // then it's evaluated on demand in function semantic - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this); - } - return sc; - } + override const(char)* kind() const { @@ -1005,13 +925,7 @@ extern(C++) final class ForwardingAttribDeclaration : AttribDeclaration sym.symtab = new DsymbolTable(); } - /************************************** - * Use the ForwardingScopeDsymbol as the parent symbol for members. - */ - override Scope* newScope(Scope* sc) - { - return sc.push(sym); - } + override inout(ForwardingAttribDeclaration) isForwardingAttribDeclaration() inout { @@ -1088,18 +1002,7 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration return new UserAttributeDeclaration(Expression.arraySyntaxCopy(this.atts), Dsymbol.arraySyntaxCopy(decl)); } - override Scope* newScope(Scope* sc) - { - Scope* sc2 = sc; - if (atts && atts.length) - { - // create new one for changes - sc2 = sc.copy(); - sc2.userAttribDecl = this; - } - return sc2; - } - + extern (D) static Expressions* concat(Expressions* udas1, Expressions* udas2) { Expressions* udas; diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index e0eebb4c6cdc..c32bf32282da 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7473,3 +7473,139 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } } } + +// newly imported sem func +extern(C++) void newScope(Dsymbol d, Scope* sc) +{ + scope iav = new newScopeVisitor(sc); + d.accept(iav); +} + +extern(C++) class newScopeVisitor : Visitor +{ + alias visit = typeof(super).visit; + Scope* sc; + + this(Scope* sc) + { + this.sc = sc; + } + +override Scope* visit(Scope* sc) + { + if (pkg_identifiers) + dsymbolSemantic(this, sc); + return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); + } + + /** + * Returns: + * A copy of the parent scope, with `this` as `namespace` and C++ linkage + */ + override Scope* visit(Scope* sc) + { + auto scx = sc.copy(); + scx.linkage = LINK.cpp; + scx.namespace = this; + return scx; + } + + override Scope* newScope(Scope* sc) + { + return createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, + sc.aligndecl, sc.inlining); + } + +override Scope* newScope(Scope* sc) + { + return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); + } + +override Scope* newScope(Scope* sc) + { + if (ident == Id.Pinline) + { + // We keep track of this pragma inside scopes, + // then it's evaluated on demand in function semantic + return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this); + } + return sc; + } + +override Scope* newScope(Scope* sc) + { + return createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, + sc.aligndecl, sc.inlining); + } + +/** + * Provides a new scope with `STC.deprecated_` and `Scope.depdecl` set + * + * Calls `StorageClassDeclaration.newScope` (as it must be called or copied + * in any function overriding `newScope`), then set the `Scope`'s depdecl. + * + * Returns: + * Always a new scope, to use for this `DeprecatedDeclaration`'s members. + */ + override Scope* newScope(Scope* sc) + { + auto scx = super.newScope(sc); + // The enclosing scope is deprecated as well + if (scx == sc) + scx = sc.push(); + scx.depdecl = this; + return scx; + } + + /************************************** + * Use the ForwardingScopeDsymbol as the parent symbol for members. + */ + override Scope* newScope(Scope* sc) + { + return sc.push(sym); + } + + override Scope* newScope(Scope* sc) + { + StorageClass scstc = sc.stc; + /* These sets of storage classes are mutually exclusive, + * so choose the innermost or most recent one. + */ + if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) + scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest); + if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) + scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared); + if (stc & (STC.const_ | STC.immutable_ | STC.manifest)) + scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest); + if (stc & (STC.gshared | STC.shared_)) + scstc &= ~(STC.gshared | STC.shared_); + if (stc & (STC.safe | STC.trusted | STC.system)) + scstc &= ~(STC.safe | STC.trusted | STC.system); + scstc |= stc; + //printf("scstc = x%llx\n", scstc); + return createNewScope(sc, scstc, sc.linkage, sc.cppmangle, + sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); + } + +/**************************************** + * A hook point to supply scope for members. + * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. + */ + Scope* newScope(Scope* sc) + { + return sc; + } + + +override Scope* newScope(Scope* sc) + { + Scope* sc2 = sc; + if (atts && atts.length) + { + // create new one for changes + sc2 = sc.copy(); + sc2.userAttribDecl = this; + } + return sc2; + } +} \ No newline at end of file From b2300c076f899434515a5811163929f2792dbea3 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Thu, 19 Sep 2024 04:13:20 +0200 Subject: [PATCH 02/17] Extract newScope functions to dsymbolsem --- compiler/src/dmd/dsymbolsem.d | 67 ++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index c32bf32282da..33df6cda55c6 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7482,59 +7482,63 @@ extern(C++) void newScope(Dsymbol d, Scope* sc) } extern(C++) class newScopeVisitor : Visitor -{ +{ + //Scope returnScope; + alias visit = typeof(super).visit; + //alias visit = Visitor.visit; Scope* sc; - this(Scope* sc) { this.sc = sc; } -override Scope* visit(Scope* sc) +//previously override void visit(Scope* sc) +override void visit(AttribDeclaration atbd) { + //Scope returnScope; if (pkg_identifiers) dsymbolSemantic(this, sc); - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); + + createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); } /** * Returns: * A copy of the parent scope, with `this` as `namespace` and C++ linkage - */ - override Scope* visit(Scope* sc) + *///override Scope* visit(Scope* sc) + override void visit(StorageClassDeclaration scd) { auto scx = sc.copy(); scx.linkage = LINK.cpp; scx.namespace = this; - return scx; } - override Scope* newScope(Scope* sc) +//override Scope* visit(Scope* sc) + override void visit(CPPMangleDeclaration _) { - return createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, + createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); } -override Scope* newScope(Scope* sc) + override void visit(VisibilityDeclaration visd) { - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); + createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); } -override Scope* newScope(Scope* sc) +override void visit(PragmaDeclaration _) { if (ident == Id.Pinline) { // We keep track of this pragma inside scopes, // then it's evaluated on demand in function semantic - return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this); + createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this); } - return sc; } -override Scope* newScope(Scope* sc) +override void visit(LinkDeclaration sc) { - return createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, + createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); } @@ -7547,27 +7551,26 @@ override Scope* newScope(Scope* sc) * Returns: * Always a new scope, to use for this `DeprecatedDeclaration`'s members. */ - override Scope* newScope(Scope* sc) + override void visit(DeprecatedDeclaration dpd) { auto scx = super.newScope(sc); // The enclosing scope is deprecated as well - if (scx == sc) - scx = sc.push(); + if (dpd.scx == sc) + dpd.scx = sc.push(); scx.depdecl = this; - return scx; } /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. */ - override Scope* newScope(Scope* sc) + override void visit(ForwardingAttribDeclaration fad) { - return sc.push(sym); + sc.push(sym); } - - override Scope* newScope(Scope* sc) + + override void visit(StorageClassDeclaration swt) { - StorageClass scstc = sc.stc; + StorageClass scstc = swt.stc; /* These sets of storage classes are mutually exclusive, * so choose the innermost or most recent one. */ @@ -7583,29 +7586,27 @@ override Scope* newScope(Scope* sc) scstc &= ~(STC.safe | STC.trusted | STC.system); scstc |= stc; //printf("scstc = x%llx\n", scstc); - return createNewScope(sc, scstc, sc.linkage, sc.cppmangle, + createNewScope(sc, scstc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); + return; } /**************************************** * A hook point to supply scope for members. * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. */ - Scope* newScope(Scope* sc) - { - return sc; - } + //previously Scope* newScope(Scope* sc) + override void visit(Dsymbol dc){} -override Scope* newScope(Scope* sc) +override void visit(UserAttributeDeclaration uac) { Scope* sc2 = sc; - if (atts && atts.length) + if (uac.atts && atts.length) { // create new one for changes sc2 = sc.copy(); sc2.userAttribDecl = this; } - return sc2; } } \ No newline at end of file From 83ba7503b7b19b957c8d449aaab4779ed92cfba0 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Fri, 20 Sep 2024 11:33:00 +0200 Subject: [PATCH 03/17] Batch 3 errors encountered --- compiler/src/dmd/dsymbolsem.d | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 33df6cda55c6..2716510383ae 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7494,20 +7494,21 @@ extern(C++) class newScopeVisitor : Visitor } //previously override void visit(Scope* sc) -override void visit(AttribDeclaration atbd) +override void visit(VisibilityDeclaration atbd) { //Scope returnScope; - if (pkg_identifiers) + if (atbd.pkg_identifiers){ dsymbolSemantic(this, sc); createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); + } } /** * Returns: * A copy of the parent scope, with `this` as `namespace` and C++ linkage *///override Scope* visit(Scope* sc) - override void visit(StorageClassDeclaration scd) + override void visit(CPPNamespaceDeclaration scd) { auto scx = sc.copy(); scx.linkage = LINK.cpp; @@ -7521,7 +7522,7 @@ override void visit(AttribDeclaration atbd) sc.aligndecl, sc.inlining); } - override void visit(VisibilityDeclaration visd) + override void visit(AttribDeclaration visd) { createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); } From 36489c94755a502f7141168ed6e006ef95339062 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Sun, 22 Sep 2024 21:25:00 +0200 Subject: [PATCH 04/17] Extract newScope and turn to visitor --- compiler/src/dmd/dsymbolsem.d | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 2716510383ae..f1e965c74d59 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7498,9 +7498,9 @@ override void visit(VisibilityDeclaration atbd) { //Scope returnScope; if (atbd.pkg_identifiers){ - dsymbolSemantic(this, sc); + dsymbolSemantic(atbd, sc); - createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining); + atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } } @@ -7512,11 +7512,11 @@ override void visit(VisibilityDeclaration atbd) { auto scx = sc.copy(); scx.linkage = LINK.cpp; - scx.namespace = this; + scx.namespace = scd; } //override Scope* visit(Scope* sc) - override void visit(CPPMangleDeclaration _) + override void visit(CPPMangleDeclaration cpmd) { createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); @@ -7527,9 +7527,9 @@ override void visit(VisibilityDeclaration atbd) createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); } -override void visit(PragmaDeclaration _) +override void visit(PragmaDeclaration prd) { - if (ident == Id.Pinline) + if (prd.ident == Id.Pinline) { // We keep track of this pragma inside scopes, // then it's evaluated on demand in function semantic @@ -7556,9 +7556,9 @@ override void visit(LinkDeclaration sc) { auto scx = super.newScope(sc); // The enclosing scope is deprecated as well - if (dpd.scx == sc) - dpd.scx = sc.push(); - scx.depdecl = this; + if (scx == sc) + scx = sc.push(); + scx.depdecl = dpd; } /************************************** @@ -7596,18 +7596,17 @@ override void visit(LinkDeclaration sc) * A hook point to supply scope for members. * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. */ - //previously Scope* newScope(Scope* sc) override void visit(Dsymbol dc){} override void visit(UserAttributeDeclaration uac) { Scope* sc2 = sc; - if (uac.atts && atts.length) + if (uac.atts && uac.atts.length) { // create new one for changes sc2 = sc.copy(); - sc2.userAttribDecl = this; + sc2.userAttribDecl = uac; } } } \ No newline at end of file From 21de527a8327d3fdddd384f8c58d37baa14ca51b Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Tue, 24 Sep 2024 15:07:26 +0200 Subject: [PATCH 05/17] Extract newScope and turn into a visitor --- compiler/src/dmd/attrib.d | 2 +- compiler/src/dmd/dsymbolsem.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index e38788bf1c84..dbbc45c4e3b3 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -32,7 +32,7 @@ import dmd.declaration; import dmd.dmodule; import dmd.dscope; import dmd.dsymbol; -//import dmd.dsymbolsem; +import dmd.dsymbolsem; import dmd.errors; import dmd.expression; import dmd.func; diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index f1e965c74d59..7499eead0295 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7566,7 +7566,7 @@ override void visit(LinkDeclaration sc) */ override void visit(ForwardingAttribDeclaration fad) { - sc.push(sym); + sc.push(fad.sym); } override void visit(StorageClassDeclaration swt) From b1c7e9cc00207333e8aa9dd5048f028c459cb2dd Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Fri, 27 Sep 2024 12:50:14 +0200 Subject: [PATCH 06/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/dsymbolsem.d | 55 ++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 7499eead0295..c511867adc39 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7475,10 +7475,12 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } // newly imported sem func -extern(C++) void newScope(Dsymbol d, Scope* sc) +//extern(C++) void newScope(Dsymbol d, Scope* sc) +Scope* newScope(Dsymbol d, Scope* sc) { - scope iav = new newScopeVisitor(sc); - d.accept(iav); + scope nsv = new newScopeVisitor(sc); + d.accept(nsv); + return nsv.sc; } extern(C++) class newScopeVisitor : Visitor @@ -7500,7 +7502,7 @@ override void visit(VisibilityDeclaration atbd) if (atbd.pkg_identifiers){ dsymbolSemantic(atbd, sc); - atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); + sc= atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } } @@ -7515,16 +7517,15 @@ override void visit(VisibilityDeclaration atbd) scx.namespace = scd; } -//override Scope* visit(Scope* sc) override void visit(CPPMangleDeclaration cpmd) { - createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility, + sc = cpmd.createNewScope(sc, sc.stc, LINK.cpp, cpmd.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); } - override void visit(AttribDeclaration visd) + override void visit(AlignDeclaration visd) { - createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining); + sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, visd, sc.inlining); } override void visit(PragmaDeclaration prd) @@ -7533,13 +7534,14 @@ override void visit(PragmaDeclaration prd) { // We keep track of this pragma inside scopes, // then it's evaluated on demand in function semantic - createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this); + sc = prd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, prd); // @suppress(dscanner.style.long_line) } + return; } -override void visit(LinkDeclaration sc) +override void visit(LinkDeclaration lid) { - createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, + sc= lid.createNewScope(sc, sc.stc, lid.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); } @@ -7552,14 +7554,24 @@ override void visit(LinkDeclaration sc) * Returns: * Always a new scope, to use for this `DeprecatedDeclaration`'s members. */ + + override void visit(DeprecatedDeclaration dpd) { - auto scx = super.newScope(sc); + auto scx = dpd.newScope(sc); //super.newScope(sc); // The enclosing scope is deprecated as well if (scx == sc) scx = sc.push(); scx.depdecl = dpd; } + /*override void visit(DeprecatedDeclaration dpd) +{ + // Create a new scope manually if newScope doesn't return anything + Scope* scx = sc.push(); // Push the current scope to create a new one + + // The enclosing scope is deprecated as well + scx.depdecl = dpd; +}*/ /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. @@ -7575,19 +7587,19 @@ override void visit(LinkDeclaration sc) /* These sets of storage classes are mutually exclusive, * so choose the innermost or most recent one. */ - if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) + if (scstc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest); - if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) + if (scstc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared); - if (stc & (STC.const_ | STC.immutable_ | STC.manifest)) + if (scstc & (STC.const_ | STC.immutable_ | STC.manifest)) scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest); - if (stc & (STC.gshared | STC.shared_)) + if (scstc & (STC.gshared | STC.shared_)) scstc &= ~(STC.gshared | STC.shared_); - if (stc & (STC.safe | STC.trusted | STC.system)) + if (scstc & (STC.safe | STC.trusted | STC.system)) scstc &= ~(STC.safe | STC.trusted | STC.system); - scstc |= stc; + scstc |= swt.stc; //printf("scstc = x%llx\n", scstc); - createNewScope(sc, scstc, sc.linkage, sc.cppmangle, + sc = swt.createNewScope(sc, scstc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); return; } @@ -7596,7 +7608,9 @@ override void visit(LinkDeclaration sc) * A hook point to supply scope for members. * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. */ - override void visit(Dsymbol dc){} + override void visit(Dsymbol dc) { + return; + } override void visit(UserAttributeDeclaration uac) @@ -7608,5 +7622,6 @@ override void visit(UserAttributeDeclaration uac) sc2 = sc.copy(); sc2.userAttribDecl = uac; } + return; } } \ No newline at end of file From fd7f928a0230e45104833f1ae3d8e59c7eff638f Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Mon, 30 Sep 2024 23:01:21 +0200 Subject: [PATCH 07/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/attrib.d | 15 ++----------- compiler/src/dmd/dsymbolsem.d | 41 ++++++++++------------------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index dbbc45c4e3b3..3fe8741f29c6 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -113,7 +113,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol return sc2; } - override void addComment(const(char)* comment) { @@ -194,7 +193,6 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration assert(!s); return new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl)); } - override final bool oneMember(out Dsymbol ps, Identifier ident) @@ -257,9 +255,7 @@ extern (C++) final class DeprecatedDeclaration : StorageClassDeclaration { assert(!s); return new DeprecatedDeclaration(msg.syntaxCopy(), Dsymbol.arraySyntaxCopy(decl)); - } - - + } override void accept(Visitor v) { @@ -409,7 +405,6 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration this.loc, this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.cppnamespace); } - override const(char)* toChars() const { @@ -481,7 +476,6 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration else return new VisibilityDeclaration(this.loc, visibility, Dsymbol.arraySyntaxCopy(decl)); } - override const(char)* kind() const @@ -552,7 +546,6 @@ extern (C++) final class AlignDeclaration : AttribDeclaration Expression.arraySyntaxCopy(exps), Dsymbol.arraySyntaxCopy(decl)); } - override void accept(Visitor v) @@ -621,9 +614,7 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration //printf("PragmaDeclaration::syntaxCopy(%s)\n", toChars()); assert(!s); return new PragmaDeclaration(loc, ident, Expression.arraySyntaxCopy(args), Dsymbol.arraySyntaxCopy(decl)); - } - - + } override const(char)* kind() const { @@ -925,7 +916,6 @@ extern(C++) final class ForwardingAttribDeclaration : AttribDeclaration sym.symtab = new DsymbolTable(); } - override inout(ForwardingAttribDeclaration) isForwardingAttribDeclaration() inout { @@ -1001,7 +991,6 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration assert(!s); return new UserAttributeDeclaration(Expression.arraySyntaxCopy(this.atts), Dsymbol.arraySyntaxCopy(decl)); } - extern (D) static Expressions* concat(Expressions* udas1, Expressions* udas2) { diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index c511867adc39..ac4edf438ec5 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7474,8 +7474,6 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } } -// newly imported sem func -//extern(C++) void newScope(Dsymbol d, Scope* sc) Scope* newScope(Dsymbol d, Scope* sc) { scope nsv = new newScopeVisitor(sc); @@ -7485,34 +7483,29 @@ Scope* newScope(Dsymbol d, Scope* sc) extern(C++) class newScopeVisitor : Visitor { - //Scope returnScope; - alias visit = typeof(super).visit; - //alias visit = Visitor.visit; Scope* sc; this(Scope* sc) { this.sc = sc; } -//previously override void visit(Scope* sc) override void visit(VisibilityDeclaration atbd) { - //Scope returnScope; - if (atbd.pkg_identifiers){ + if (atbd.pkg_identifiers) + { dsymbolSemantic(atbd, sc); - - sc= atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); + sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } } - /** * Returns: * A copy of the parent scope, with `this` as `namespace` and C++ linkage *///override Scope* visit(Scope* sc) override void visit(CPPNamespaceDeclaration scd) - { + { auto scx = sc.copy(); + sc = scx; scx.linkage = LINK.cpp; scx.namespace = scd; } @@ -7528,7 +7521,7 @@ override void visit(VisibilityDeclaration atbd) sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, visd, sc.inlining); } -override void visit(PragmaDeclaration prd) + override void visit(PragmaDeclaration prd) { if (prd.ident == Id.Pinline) { @@ -7554,31 +7547,21 @@ override void visit(LinkDeclaration lid) * Returns: * Always a new scope, to use for this `DeprecatedDeclaration`'s members. */ - - override void visit(DeprecatedDeclaration dpd) { auto scx = dpd.newScope(sc); //super.newScope(sc); // The enclosing scope is deprecated as well + sc = scx; if (scx == sc) scx = sc.push(); scx.depdecl = dpd; } - /*override void visit(DeprecatedDeclaration dpd) -{ - // Create a new scope manually if newScope doesn't return anything - Scope* scx = sc.push(); // Push the current scope to create a new one - - // The enclosing scope is deprecated as well - scx.depdecl = dpd; -}*/ - /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. */ override void visit(ForwardingAttribDeclaration fad) { - sc.push(fad.sym); + sc = sc.push(fad.sym); } override void visit(StorageClassDeclaration swt) @@ -7608,11 +7591,11 @@ override void visit(LinkDeclaration lid) * A hook point to supply scope for members. * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. */ - override void visit(Dsymbol dc) { + override void visit(Dsymbol dc) + { return; } - override void visit(UserAttributeDeclaration uac) { Scope* sc2 = sc; @@ -7622,6 +7605,6 @@ override void visit(UserAttributeDeclaration uac) sc2 = sc.copy(); sc2.userAttribDecl = uac; } - return; + sc = sc2; } -} \ No newline at end of file +} From e9c9c7e9c113f96f6f218478edad76e869d4a99b Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Tue, 1 Oct 2024 15:42:52 +0200 Subject: [PATCH 08/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/dsymbolsem.d | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index ac4edf438ec5..68ef4a2715f4 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7495,8 +7495,8 @@ override void visit(VisibilityDeclaration atbd) if (atbd.pkg_identifiers) { dsymbolSemantic(atbd, sc); - sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } + sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } /** * Returns: @@ -7529,7 +7529,6 @@ override void visit(VisibilityDeclaration atbd) // then it's evaluated on demand in function semantic sc = prd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, prd); // @suppress(dscanner.style.long_line) } - return; } override void visit(LinkDeclaration lid) @@ -7551,10 +7550,10 @@ override void visit(LinkDeclaration lid) { auto scx = dpd.newScope(sc); //super.newScope(sc); // The enclosing scope is deprecated as well - sc = scx; if (scx == sc) scx = sc.push(); scx.depdecl = dpd; + sc = scx; } /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. @@ -7584,17 +7583,13 @@ override void visit(LinkDeclaration lid) //printf("scstc = x%llx\n", scstc); sc = swt.createNewScope(sc, scstc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); - return; } /**************************************** * A hook point to supply scope for members. * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. */ - override void visit(Dsymbol dc) - { - return; - } + override void visit(Dsymbol dc){} override void visit(UserAttributeDeclaration uac) { From 74a7aaf7a6241a0bf90e936ab780185997da0749 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Tue, 1 Oct 2024 22:13:46 +0200 Subject: [PATCH 09/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/dsymbolsem.d | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 68ef4a2715f4..1d2200e60008 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7505,9 +7505,9 @@ override void visit(VisibilityDeclaration atbd) override void visit(CPPNamespaceDeclaration scd) { auto scx = sc.copy(); - sc = scx; scx.linkage = LINK.cpp; scx.namespace = scd; + sc = scx; } override void visit(CPPMangleDeclaration cpmd) @@ -7548,13 +7548,12 @@ override void visit(LinkDeclaration lid) */ override void visit(DeprecatedDeclaration dpd) { - auto scx = dpd.newScope(sc); //super.newScope(sc); - // The enclosing scope is deprecated as well - if (scx == sc) - scx = sc.push(); - scx.depdecl = dpd; - sc = scx; + auto oldsc = sc; + visit(cast(StorageClassDeclaration) dpd); + auto scx = sc; + sc = oldsc; } + /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. */ From 1f4b10d0db43d58dad51242fe495a9e99b4dccab Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Wed, 2 Oct 2024 03:14:44 +0200 Subject: [PATCH 10/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/dsymbolsem.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 584312ebebb7..b18bb6e64ffe 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7487,10 +7487,14 @@ override void visit(LinkDeclaration lid) */ override void visit(DeprecatedDeclaration dpd) { - auto oldsc = sc; + auto oldsc = sc; visit(cast(StorageClassDeclaration) dpd); auto scx = sc; sc = oldsc; + if (scx == sc) + scx = sc.push(); + scx.depdecl = dpd; + sc = scx; } /************************************** From f6d9314d5f28bc1e2137f7f734f1d2f1ff46b94e Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Thu, 3 Oct 2024 03:10:51 +0200 Subject: [PATCH 11/17] Move newScope out of AST nodes to dsymbolsem.d --- compiler/src/dmd/dsymbolsem.d | 132 +++++++++++++++++----------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index b18bb6e64ffe..27291deafb36 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7429,14 +7429,65 @@ extern(C++) class newScopeVisitor : Visitor this.sc = sc; } -override void visit(VisibilityDeclaration atbd) + /**************************************** + * A hook point to supply scope for members. + * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. + */ + override void visit(AttribDeclaration dc){} + + override void visit(StorageClassDeclaration swt) { - if (atbd.pkg_identifiers) - { - dsymbolSemantic(atbd, sc); - } - sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); + StorageClass scstc = sc.stc; + /* These sets of storage classes are mutually exclusive, + * so choose the innermost or most recent one. + */ + if (swt.stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) + scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest); + if (swt.stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) + scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared); + if (swt.stc & (STC.const_ | STC.immutable_ | STC.manifest)) + scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest); + if (swt.stc & (STC.gshared | STC.shared_)) + scstc &= ~(STC.gshared | STC.shared_); + if (swt.stc & (STC.safe | STC.trusted | STC.system)) + scstc &= ~(STC.safe | STC.trusted | STC.system); + scstc |= swt.stc; + //printf("scstc = x%llx\n", scstc); + sc = swt.createNewScope(sc, scstc, sc.linkage, sc.cppmangle, + sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); } + + /** + * Provides a new scope with `STC.deprecated_` and `Scope.depdecl` set + * + * Calls `StorageClassDeclaration.newScope` (as it must be called or copied + * in any function overriding `newScope`), then set the `Scope`'s depdecl. + * + * Returns: + * Always a new scope, to use for this `DeprecatedDeclaration`'s members. + */ + override void visit(DeprecatedDeclaration dpd) + { + auto scx = (cast(StorageClassDeclaration)dpd).newScope(sc); + // The enclosing scope is deprecated as well + if (scx == sc) + scx = sc.push(); + scx.depdecl = dpd; + sc = scx; + } + + override void visit(LinkDeclaration lid) + { + sc= lid.createNewScope(sc, sc.stc, lid.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, + sc.aligndecl, sc.inlining); + } + + override void visit(CPPMangleDeclaration cpmd) + { + sc = cpmd.createNewScope(sc, sc.stc, LINK.cpp, cpmd.cppmangle, sc.visibility, sc.explicitVisibility, + sc.aligndecl, sc.inlining); + } + /** * Returns: * A copy of the parent scope, with `this` as `namespace` and C++ linkage @@ -7449,15 +7500,19 @@ override void visit(VisibilityDeclaration atbd) sc = scx; } - override void visit(CPPMangleDeclaration cpmd) + override void visit(VisibilityDeclaration atbd) { - sc = cpmd.createNewScope(sc, sc.stc, LINK.cpp, cpmd.cppmangle, sc.visibility, sc.explicitVisibility, - sc.aligndecl, sc.inlining); + if (atbd.pkg_identifiers) + { + dsymbolSemantic(atbd, sc); + } + sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } override void visit(AlignDeclaration visd) { - sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, visd, sc.inlining); + sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, + sc.explicitVisibility, visd, sc.inlining); } override void visit(PragmaDeclaration prd) @@ -7470,33 +7525,6 @@ override void visit(VisibilityDeclaration atbd) } } -override void visit(LinkDeclaration lid) - { - sc= lid.createNewScope(sc, sc.stc, lid.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, - sc.aligndecl, sc.inlining); - } - -/** - * Provides a new scope with `STC.deprecated_` and `Scope.depdecl` set - * - * Calls `StorageClassDeclaration.newScope` (as it must be called or copied - * in any function overriding `newScope`), then set the `Scope`'s depdecl. - * - * Returns: - * Always a new scope, to use for this `DeprecatedDeclaration`'s members. - */ - override void visit(DeprecatedDeclaration dpd) - { - auto oldsc = sc; - visit(cast(StorageClassDeclaration) dpd); - auto scx = sc; - sc = oldsc; - if (scx == sc) - scx = sc.push(); - scx.depdecl = dpd; - sc = scx; - } - /************************************** * Use the ForwardingScopeDsymbol as the parent symbol for members. */ @@ -7505,35 +7533,7 @@ override void visit(LinkDeclaration lid) sc = sc.push(fad.sym); } - override void visit(StorageClassDeclaration swt) - { - StorageClass scstc = swt.stc; - /* These sets of storage classes are mutually exclusive, - * so choose the innermost or most recent one. - */ - if (scstc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest)) - scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest); - if (scstc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared)) - scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared); - if (scstc & (STC.const_ | STC.immutable_ | STC.manifest)) - scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest); - if (scstc & (STC.gshared | STC.shared_)) - scstc &= ~(STC.gshared | STC.shared_); - if (scstc & (STC.safe | STC.trusted | STC.system)) - scstc &= ~(STC.safe | STC.trusted | STC.system); - scstc |= swt.stc; - //printf("scstc = x%llx\n", scstc); - sc = swt.createNewScope(sc, scstc, sc.linkage, sc.cppmangle, - sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining); - } - -/**************************************** - * A hook point to supply scope for members. - * addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this. - */ - override void visit(Dsymbol dc){} - -override void visit(UserAttributeDeclaration uac) + override void visit(UserAttributeDeclaration uac) { Scope* sc2 = sc; if (uac.atts && uac.atts.length) From 78c9e4250065150153677dd6e896ddc0e30b4001 Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Thu, 3 Oct 2024 16:51:39 +0300 Subject: [PATCH 12/17] Fix segfault when compiling druntime --- compiler/src/dmd/dsymbolsem.d | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 27291deafb36..32ede22bda69 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7415,13 +7415,13 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor Scope* newScope(Dsymbol d, Scope* sc) { - scope nsv = new newScopeVisitor(sc); + scope nsv = new NewScopeVisitor(sc); d.accept(nsv); return nsv.sc; } -extern(C++) class newScopeVisitor : Visitor -{ +extern(C++) class NewScopeVisitor : Visitor +{ alias visit = typeof(super).visit; Scope* sc; this(Scope* sc) @@ -7468,12 +7468,15 @@ extern(C++) class newScopeVisitor : Visitor */ override void visit(DeprecatedDeclaration dpd) { - auto scx = (cast(StorageClassDeclaration)dpd).newScope(sc); + auto oldsc = sc; + visit((cast(StorageClassDeclaration)dpd)); + auto scx = sc; + sc = oldsc; // The enclosing scope is deprecated as well if (scx == sc) scx = sc.push(); - scx.depdecl = dpd; - sc = scx; + scx.depdecl = dpd; + sc = scx; } override void visit(LinkDeclaration lid) @@ -7493,7 +7496,7 @@ extern(C++) class newScopeVisitor : Visitor * A copy of the parent scope, with `this` as `namespace` and C++ linkage *///override Scope* visit(Scope* sc) override void visit(CPPNamespaceDeclaration scd) - { + { auto scx = sc.copy(); scx.linkage = LINK.cpp; scx.namespace = scd; @@ -7503,9 +7506,8 @@ extern(C++) class newScopeVisitor : Visitor override void visit(VisibilityDeclaration atbd) { if (atbd.pkg_identifiers) - { dsymbolSemantic(atbd, sc); - } + sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } From 02757c96af88a02991d78fa128170ee65d4ee2c6 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Fri, 4 Oct 2024 14:46:08 +0200 Subject: [PATCH 13/17] Remove newScope from attrib.h --- compiler/src/dmd/attrib.d | 13 +++---------- compiler/src/dmd/attrib.h | 11 ----------- compiler/src/dmd/dsymbol.h | 1 + compiler/src/dmd/dsymbolsem.d | 8 ++++---- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index 3fe8741f29c6..aaf5314309fb 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -193,7 +193,6 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration assert(!s); return new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl)); } - override final bool oneMember(out Dsymbol ps, Identifier ident) { @@ -255,7 +254,7 @@ extern (C++) final class DeprecatedDeclaration : StorageClassDeclaration { assert(!s); return new DeprecatedDeclaration(msg.syntaxCopy(), Dsymbol.arraySyntaxCopy(decl)); - } + } override void accept(Visitor v) { @@ -333,8 +332,6 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration return new CPPMangleDeclaration(loc, cppmangle, Dsymbol.arraySyntaxCopy(decl)); } - - override const(char)* toChars() const { return toString().ptr; @@ -405,7 +402,6 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration this.loc, this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.cppnamespace); } - override const(char)* toChars() const { return toString().ptr; @@ -476,7 +472,6 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration else return new VisibilityDeclaration(this.loc, visibility, Dsymbol.arraySyntaxCopy(decl)); } - override const(char)* kind() const { @@ -546,7 +541,6 @@ extern (C++) final class AlignDeclaration : AttribDeclaration Expression.arraySyntaxCopy(exps), Dsymbol.arraySyntaxCopy(decl)); } - override void accept(Visitor v) { @@ -614,7 +608,7 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration //printf("PragmaDeclaration::syntaxCopy(%s)\n", toChars()); assert(!s); return new PragmaDeclaration(loc, ident, Expression.arraySyntaxCopy(args), Dsymbol.arraySyntaxCopy(decl)); - } + } override const(char)* kind() const { @@ -991,7 +985,7 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration assert(!s); return new UserAttributeDeclaration(Expression.arraySyntaxCopy(this.atts), Dsymbol.arraySyntaxCopy(decl)); } - + extern (D) static Expressions* concat(Expressions* udas1, Expressions* udas2) { Expressions* udas; @@ -1135,7 +1129,6 @@ int foreachUdaNoSemantic(Dsymbol sym, int delegate(Expression) dg) return 0; } - /** * Returns: true if the given expression is an enum from `core.attribute` named `id` */ diff --git a/compiler/src/dmd/attrib.h b/compiler/src/dmd/attrib.h index d4c41ec94f36..403c4139be25 100644 --- a/compiler/src/dmd/attrib.h +++ b/compiler/src/dmd/attrib.h @@ -30,7 +30,6 @@ class AttribDeclaration : public Dsymbol Dsymbols *decl; // array of Dsymbol's virtual Dsymbols *include(Scope *sc); - virtual Scope *newScope(Scope *sc); void addComment(const utf8_t *comment) override; const char *kind() const override; bool oneMember(Dsymbol *&ps, Identifier *ident) override; @@ -48,7 +47,6 @@ class StorageClassDeclaration : public AttribDeclaration StorageClass stc; StorageClassDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; bool oneMember(Dsymbol *&ps, Identifier *ident) override final; StorageClassDeclaration *isStorageClassDeclaration() override { return this; } @@ -62,7 +60,6 @@ class DeprecatedDeclaration final : public StorageClassDeclaration const char *msgstr; DeprecatedDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; void accept(Visitor *v) override { v->visit(this); } }; @@ -73,7 +70,6 @@ class LinkDeclaration final : public AttribDeclaration static LinkDeclaration *create(const Loc &loc, LINK p, Dsymbols *decl); LinkDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -84,7 +80,6 @@ class CPPMangleDeclaration final : public AttribDeclaration CPPMANGLE cppmangle; CPPMangleDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -95,7 +90,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration Expression *exp; CPPNamespaceDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *toChars() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -107,7 +101,6 @@ class VisibilityDeclaration final : public AttribDeclaration DArray pkg_identifiers; VisibilityDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *kind() const override; const char *toPrettyChars(bool unused) override; VisibilityDeclaration *isVisibilityDeclaration() override { return this; } @@ -121,7 +114,6 @@ class AlignDeclaration final : public AttribDeclaration structalign_t salign; AlignDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; void accept(Visitor *v) override { v->visit(this); } }; @@ -146,7 +138,6 @@ class PragmaDeclaration final : public AttribDeclaration Expressions *args; // array of Expression's PragmaDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *kind() const override; void accept(Visitor *v) override { v->visit(this); } }; @@ -200,7 +191,6 @@ class ForwardingAttribDeclaration final : public AttribDeclaration public: ForwardingScopeDsymbol *sym; - Scope *newScope(Scope *sc) override; ForwardingAttribDeclaration *isForwardingAttribDeclaration() override { return this; } void accept(Visitor *v) override { v->visit(this); } }; @@ -230,7 +220,6 @@ class UserAttributeDeclaration final : public AttribDeclaration Expressions *atts; UserAttributeDeclaration *syntaxCopy(Dsymbol *s) override; - Scope *newScope(Scope *sc) override; const char *kind() const override; void accept(Visitor *v) override { v->visit(this); } }; diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 2c5f0e579b3a..79e3c0ebff2e 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -448,4 +448,5 @@ namespace dmd Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, SearchOptFlags flags = (SearchOptFlags)SearchOpt::localsOnly); void setScope(Dsymbol *d, Scope *sc); void importAll(Dsymbol *d, Scope *sc); + Scope* newScope(Dsymbol *d, Scope *sc); } diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 32ede22bda69..34a52d842b0a 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7413,14 +7413,14 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } } -Scope* newScope(Dsymbol d, Scope* sc) +extern(C++) Scope* newScope(Dsymbol d, Scope* sc) { scope nsv = new NewScopeVisitor(sc); d.accept(nsv); return nsv.sc; } -extern(C++) class NewScopeVisitor : Visitor +private extern(C++) class NewScopeVisitor : Visitor { alias visit = typeof(super).visit; Scope* sc; @@ -7508,7 +7508,7 @@ extern(C++) class NewScopeVisitor : Visitor if (atbd.pkg_identifiers) dsymbolSemantic(atbd, sc); - sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); + sc = atbd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, atbd.visibility, 1, sc.aligndecl, sc.inlining); } override void visit(AlignDeclaration visd) @@ -7534,7 +7534,7 @@ extern(C++) class NewScopeVisitor : Visitor { sc = sc.push(fad.sym); } - + override void visit(UserAttributeDeclaration uac) { Scope* sc2 = sc; From f788b0999a6bbe9cc8328ffded2d3a950079b9f3 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Fri, 4 Oct 2024 15:32:10 +0200 Subject: [PATCH 14/17] Remove whitespace --- compiler/src/dmd/dsymbolsem.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index b445239f596c..98c6327c98cf 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7513,7 +7513,7 @@ private extern(C++) class NewScopeVisitor : Visitor override void visit(AlignDeclaration visd) { - sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, + sc = visd.createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, visd, sc.inlining); } From e0f76cd0f5885a44487ea345272243956250f6f2 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Sat, 5 Oct 2024 02:17:12 +0200 Subject: [PATCH 15/17] make newScope extern(D) --- compiler/src/dmd/dsymbol.h | 1 - compiler/src/dmd/dsymbolsem.d | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 79e3c0ebff2e..2c5f0e579b3a 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -448,5 +448,4 @@ namespace dmd Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, SearchOptFlags flags = (SearchOptFlags)SearchOpt::localsOnly); void setScope(Dsymbol *d, Scope *sc); void importAll(Dsymbol *d, Scope *sc); - Scope* newScope(Dsymbol *d, Scope *sc); } diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 98c6327c98cf..4eed91aca3ad 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -7413,7 +7413,7 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor } } -extern(C++) Scope* newScope(Dsymbol d, Scope* sc) +extern(D) Scope* newScope(Dsymbol d, Scope* sc) { scope nsv = new NewScopeVisitor(sc); d.accept(nsv); From 9ec7a80f74e8ee79e763a091f1b0fbaf9f15df31 Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Sat, 5 Oct 2024 09:59:06 +0200 Subject: [PATCH 16/17] Remove newScope from frontend.h --- compiler/src/dmd/dsymbol.h | 1 + compiler/src/dmd/frontend.h | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 2c5f0e579b3a..79e3c0ebff2e 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -448,4 +448,5 @@ namespace dmd Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, SearchOptFlags flags = (SearchOptFlags)SearchOpt::localsOnly); 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 23d404ba6bc0..ad34ef41d526 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -6146,7 +6146,6 @@ class AggregateDeclaration : public ScopeDsymbol bool noDefaultCtor; bool disableNew; Sizeok sizeok; - virtual Scope* newScope(Scope* sc); virtual void finalizeSize() = 0; uinteger_t size(const Loc& loc) final override; bool fill(const Loc& loc, Array& elements, bool ctorinit); @@ -6214,7 +6213,6 @@ class AttribDeclaration : public Dsymbol public: Array* decl; virtual Array* include(Scope* sc); - virtual Scope* newScope(Scope* sc); void addComment(const char* comment) override; const char* kind() const override; bool oneMember(Dsymbol*& ps, Identifier* ident) override; @@ -6231,7 +6229,6 @@ class StorageClassDeclaration : public AttribDeclaration public: StorageClass stc; StorageClassDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; bool oneMember(Dsymbol*& ps, Identifier* ident) final override; StorageClassDeclaration* isStorageClassDeclaration() override; void accept(Visitor* v) override; @@ -6243,7 +6240,6 @@ class DeprecatedDeclaration final : public StorageClassDeclaration Expression* msg; const char* msgstr; DeprecatedDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; void accept(Visitor* v) override; }; @@ -6253,7 +6249,6 @@ class LinkDeclaration final : public AttribDeclaration LINK linkage; static LinkDeclaration* create(const Loc& loc, LINK p, Array* decl); LinkDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* toChars() const override; void accept(Visitor* v) override; }; @@ -6263,7 +6258,6 @@ class CPPMangleDeclaration final : public AttribDeclaration public: CPPMANGLE cppmangle; CPPMangleDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* toChars() const override; void accept(Visitor* v) override; }; @@ -6273,7 +6267,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration public: Expression* exp; CPPNamespaceDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* toChars() const override; void accept(Visitor* v) override; CPPNamespaceDeclaration* isCPPNamespaceDeclaration() override; @@ -6285,7 +6278,6 @@ class VisibilityDeclaration final : public AttribDeclaration Visibility visibility; _d_dynamicArray< Identifier* > pkg_identifiers; VisibilityDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* kind() const override; const char* toPrettyChars(bool __param_0_) override; VisibilityDeclaration* isVisibilityDeclaration() override; @@ -6298,7 +6290,6 @@ class AlignDeclaration final : public AttribDeclaration Array* exps; structalign_t salign; AlignDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; void accept(Visitor* v) override; }; @@ -6321,7 +6312,6 @@ class PragmaDeclaration final : public AttribDeclaration public: Array* args; PragmaDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* kind() const override; void accept(Visitor* v) override; }; @@ -6374,7 +6364,6 @@ class ForwardingAttribDeclaration final : public AttribDeclaration public: ForwardingScopeDsymbol* sym; ForwardingAttribDeclaration(Array* decl); - Scope* newScope(Scope* sc) override; ForwardingAttribDeclaration* isForwardingAttribDeclaration() override; void accept(Visitor* v) override; }; @@ -6396,7 +6385,6 @@ class UserAttributeDeclaration final : public AttribDeclaration public: Array* atts; UserAttributeDeclaration* syntaxCopy(Dsymbol* s) override; - Scope* newScope(Scope* sc) override; const char* kind() const override; void accept(Visitor* v) override; }; @@ -6534,7 +6522,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 }; @@ -6562,7 +6549,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 4b0e00b45d214ff3ffed53ae86bb791695626e3b Mon Sep 17 00:00:00 2001 From: dchidindu5 Date: Sat, 5 Oct 2024 10:29:00 +0200 Subject: [PATCH 17/17] Fix newScope in frontend.h --- compiler/src/dmd/frontend.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index ad34ef41d526..d47e83a44d98 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -6146,6 +6146,7 @@ class AggregateDeclaration : public ScopeDsymbol bool noDefaultCtor; bool disableNew; Sizeok sizeok; + virtual Scope* newScope(Scope* sc); virtual void finalizeSize() = 0; uinteger_t size(const Loc& loc) final override; bool fill(const Loc& loc, Array& elements, bool ctorinit); @@ -6522,6 +6523,7 @@ 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 }; @@ -6549,6 +6551,7 @@ 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;