[cfe-dev] Question of RecursiveASTVisitor class

Xiaohui Chen xchen422 at uwo.ca
Mon Nov 3 12:14:08 PST 2014


Thanks for your reply.

I am confusing here:

1. Traverse method visits AST nodes that form a tree. CXXRecordDecl is the parent of each of its CXXMethodDecls and FieldDecls.

 CXXMethodDecls ( FieldDecls ) is not a member of CXXRecordDecl and also does not inherit from CXXRecordDecl, so how could
you define them as parent-child relationship?

2. WalkUpFrom method visits the class hierarchy of a single AST node. CXXRecordDecl inherits RecordDecl which inherits TagDecl etc.

here TagDecl has three direct parents, so will WalkUpFrom be applied to these three classes?

sincerely
xiaohui

On 11/03/14, Nikola Smiljanic  <popizdeh at gmail.com> wrote:
> There are two parent-child relationships at play.
> 
> 1. Traverse method visits AST nodes that form a tree. CXXRecordDecl is the parent of each of its CXXMethodDecls and FieldDecls. This is what you'll see with clang -cc1 -ast-dump
> 2. WalkUpFrom method visits the class hierarchy of a single AST node. CXXRecordDecl inherits RecordDecl which inherits TagDecl etc. Think of serialization, to serialize CXXRecordDecl you'd first want to serialize everything from the base class and so on recursively.
> 
> 
> On Mon, Nov 3, 2014 at 12:32 PM, Xiaohui Chen <xchen422 at uwo.ca> wrote:
> 
> >  Dear all:
> > 
> > My name is Xiaohui Chen, a computer science student in UWO in canada and i am using Clang as the frontend of my project, but i am confusing of the following statements.
> > PS: i am a newbie. 
> > 
> > 
> > These tasks are done by three groups of methods, respectively: 00089 /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point 00090 /// for traversing an AST rooted at x. This method simply 00091 /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo 00092 /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and 00093 /// then recursively visits the child nodes of x. 00094 /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work 00095 /// similarly. 00096 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit 00097 /// any child node of x. Instead, it first calls WalkUpFromBar(x) 00098 /// where Bar is the direct parent class of Foo (unless Foo has 00099 /// no parent), and then calls VisitFoo(x) (see the next list item). 00100 /// 3. VisitFoo(Foo *x) does task #3. 00101 /// 00102 /// These three method groups are tiered (Traverse* > WalkUpFrom* > 00103 /// Visit*). A method (e.g. Traverse*) may call methods from the same 00104 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*). 00105 /// It may not call methods from a higher tier.
> > According to the above statement, the calling relationship between these
> > functions are organized in this way in general:
> > 
> > Traversal*()
> > {
> >  .......
> >  WalkUpFrom*();
> >  .......
> > }
> > 
> > WalkUpFrom*()
> > {
> >  .......
> >  Visit*();
> >  .......
> > 
> > }
> > 
> > am i right?
> > 
> > For this statement:
> > 
> > 00096 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit 00097 /// any child node of x. Instead, it first calls WalkUpFromBar(x) 00098 /// where Bar is the direct parent class of Foo (unless Foo has 00099 /// no parent), and then calls VisitFoo(x) (see the next list item).
> > what do you mean by saying "the direct parent class of Foo"?
> > why i need to visit the parent class before i visit the current class? 
> > what is the purpose? Could you please give me a short example?
> > 
> > Thank you in advance!
> > 
> > Sincerely
> > xiaohui
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >  
> > 
> > 
> > 
> > 
> > _______________________________________________
> > 
> > cfe-dev mailing list
> > 
> > cfe-dev at cs.uiuc.edu
> > 
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> > 
> > 
> > 
> 
> 
> 
>  
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141103/9b87f066/attachment.html>


More information about the cfe-dev mailing list