Dsymbol.toParentDecl

parent field returns a lexically enclosing scope symbol this is a member of.

toParent() returns a logically enclosing scope symbol this is a member of. It skips over TemplateMixin's.

toParent2() returns an enclosing scope symbol this is living at runtime. It skips over both TemplateInstance's and TemplateMixin's. It's used when looking for the 'this' pointer of the enclosing function/class.

toParentDecl() similar to toParent2() but always follows the template declaration scope instead of the instantiation scope.

toParentLocal() similar to toParentDecl() but follows the instantiation scope if a template declaration is non-local i.e. global or static.

class Dsymbol
final inout
inout(Dsymbol)
toParentDecl
()

Examples

module mod; template Foo(alias a) { mixin Bar!(); } mixin template Bar() { public { // ProtDeclaration void baz() { a = 2; } } } void test() { int v = 1; alias foo = Foo!(v); foo.baz(); assert(v == 2); }

// s == FuncDeclaration('mod.test.Foo!().Bar!().baz()') // s.parent == TemplateMixin('mod.test.Foo!().Bar!()') // s.toParent() == TemplateInstance('mod.test.Foo!()') // s.toParent2() == FuncDeclaration('mod.test') // s.toParentDecl() == Module('mod') // s.toParentLocal() == FuncDeclaration('mod.test')

Meta