Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move newScope out of AST nodes to dsymbolsem.d #16880

Merged
merged 26 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c01f76b
extract newScope to dsymbolsem
dchidindu5 Sep 12, 2024
b2300c0
Extract newScope functions to dsymbolsem
dchidindu5 Sep 19, 2024
83ba750
Batch 3 errors encountered
dchidindu5 Sep 20, 2024
8ed06f1
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 20, 2024
36489c9
Extract newScope and turn to visitor
dchidindu5 Sep 22, 2024
b9eab55
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 22, 2024
21de527
Extract newScope and turn into a visitor
dchidindu5 Sep 24, 2024
311414f
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 24, 2024
cd797ca
C
dchidindu5 Sep 25, 2024
b1c7e9c
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Sep 27, 2024
fd7f928
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Sep 30, 2024
e9c9c7e
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 1, 2024
d65d3f7
Merge branch 'dlang:master' into practice1
dchidindu5 Oct 1, 2024
74a7aaf
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 1, 2024
4e90a5d
Merge branch 'practice1' of https://github.com/dchidindu5/dmd into pr…
dchidindu5 Oct 1, 2024
1f4b10d
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 2, 2024
f6d9314
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 3, 2024
78c9e42
Fix segfault when compiling druntime
RazvanN7 Oct 3, 2024
063ccba
Merge branch 'master' into practice1
thewilsonator Oct 3, 2024
02757c9
Remove newScope from attrib.h
dchidindu5 Oct 4, 2024
f5e9fc9
Merge branch 'dlang:master' into practice1
dchidindu5 Oct 4, 2024
15bab03
Merge branch 'practice1' of https://github.com/dchidindu5/dmd into pr…
dchidindu5 Oct 4, 2024
f788b09
Remove whitespace
dchidindu5 Oct 4, 2024
e0f76cd
make newScope extern(D)
dchidindu5 Oct 5, 2024
9ec7a80
Remove newScope from frontend.h
dchidindu5 Oct 5, 2024
4b0e00b
Fix newScope in frontend.h
dchidindu5 Oct 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 10 additions & 107 deletions compiler/src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

thewilsonator marked this conversation as resolved.
Show resolved Hide resolved

override void addComment(const(char)* comment)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
152 changes: 152 additions & 0 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7473,3 +7473,155 @@ 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);
d.accept(nsv);
return nsv.sc;
}

extern(C++) class newScopeVisitor : Visitor
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
//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)
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
//Scope returnScope;
if (atbd.pkg_identifiers){
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
dsymbolSemantic(atbd, sc);

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();
scx.linkage = LINK.cpp;
scx.namespace = scd;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}

override void visit(CPPMangleDeclaration cpmd)
{
sc = cpmd.createNewScope(sc, sc.stc, LINK.cpp, cpmd.cppmangle, sc.visibility, sc.explicitVisibility,
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);
}

override void visit(PragmaDeclaration prd)
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
if (prd.ident == Id.Pinline)
{
// We keep track of this pragma inside scopes,
// 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;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}

override void visit(LinkDeclaration lid)
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
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 scx = dpd.newScope(sc); //super.newScope(sc);
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
// The enclosing scope is deprecated as well
if (scx == sc)
scx = sc.push();
scx.depdecl = dpd;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}
/*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;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}*/

/**************************************
* Use the ForwardingScopeDsymbol as the parent symbol for members.
*/
override void visit(ForwardingAttribDeclaration fad)
{
sc.push(fad.sym);
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}

override void visit(StorageClassDeclaration swt)
{
StorageClass scstc = swt.stc;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
/* 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);
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
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);
return;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}

/****************************************
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
* A hook point to supply scope for members.
* addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this.
*/
override void visit(Dsymbol dc) {
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
return;
}


override void visit(UserAttributeDeclaration uac)
{
Scope* sc2 = sc;
if (uac.atts && uac.atts.length)
{
// create new one for changes
sc2 = sc.copy();
sc2.userAttribDecl = uac;
}
return;
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
}
}
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
Loading