ForwardingAttribDeclaration

Collection of declarations that stores foreach index variables in a local symbol table. Other symbols declared within are forwarded to another scope, like:

static foreach (i; 0 .. 10) // loop variables for different indices do not conflict. { // this body is expanded into 10 ForwardingAttribDeclarations, where i has storage class STC.local mixin("enum x" ~ to!string(i) ~ " = i"); // ok, can access current loop variable }

static foreach (i; 0.. 10) { pragma(msg, mixin("x" ~ to!string(i))); // ok, all 10 symbols are visible as they were forwarded to the global scope }

static assert (!is(typeof(i))); // loop index variable is not visible outside of the static foreach loop

A StaticForeachDeclaration generates one ForwardingAttribDeclaration for each expansion of its body. The AST of the ForwardingAttribDeclaration contains both the `static foreach variables and the respective copy of the static foreach` body. The functionality is achieved by using a ForwardingScopeDsymbol as the parent symbol for the generated declarations.

extern (C++) final
class ForwardingAttribDeclaration : AttribDeclaration {
ForwardingScopeDsymbol sym;
}

Members

Functions

addMember
void addMember(Scope* sc, ScopeDsymbol sds)

Lazily initializes the scope to forward to.

newScope
Scope* newScope(Scope* sc)

Use the ForwardingScopeDsymbol as the parent symbol for members.

Inherited Members

From AttribDeclaration

decl
Dsymbols* decl;

Dsymbol's affected by this AttribDeclaration

createNewScope
Scope* createNewScope(Scope* sc, StorageClass stc, LINK linkage, CPPMANGLE cppmangle, Visibility visibility, int explicitVisibility, AlignDeclaration aligndecl, PragmaDeclaration inlining)

Create a new scope if one or more given attributes are different from the sc's. If the returned scope != sc, the caller should pop the scope after it used.

newScope
Scope* newScope(Scope* sc)

A hook point to supply scope for members. addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this.

addLocalClass
void addLocalClass(ClassDeclarations* aclasses)
Suggestion Box / Bug Report