Understanding the AST...

joe joe at example.com
Thu Feb 22 13:21:04 UTC 2018


On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote:
> Hi Joe,
>
> /SNIP
>
> On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote:
>>[...]
>
> The FuncDeclaration node contains all the information for that.
> For example, you can access fd.parent to see if the function is
> declared at top-level (in which case, the parent is going to be 
> a module
> declaration ) or if it is a nested function (in a class, in a 
> struct, in a function).
> Every AST node contains information about the position in the 
> AST, all you
> have to do is find how to get that information: which field to 
> access or which
> member function to call.
>
> /SNIP
>
> Cheers,
> RazvanN

Follow up question...

Why is *.parent always null?
e.g.:

extern(C++) class MyVisitor(AST): ParseTimeTransitiveVisitor!AST
{
   override void visit(AST.Import i)
   {
     assert(i.parent is null); // always true
   }

   override void visitFuncBody(AST.FuncDeclaration f)
   {
     assert(f.parent is null); // always true
   }
}


More information about the Digitalmars-d-learn mailing list