<div class="gmail_quote">On Mon Nov 03 2014 at 4:00:27 AM Xiaohui Chen <<a href="mailto:xchen422@uwo.ca">xchen422@uwo.ca</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Dear all:<br><span><div><br>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.<br>PS: i am a newbie. <br><br><pre><span>These tasks are done by three groups of methods, respectively:</span>
<a name="msg-f:1483717872411799884_l00089"></a>00089 <span>///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point</span>
<a name="msg-f:1483717872411799884_l00090"></a>00090 <span>///      for traversing an AST rooted at x.  This method simply</span>
<a name="msg-f:1483717872411799884_l00091"></a>00091 <span>///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo</span>
<a name="msg-f:1483717872411799884_l00092"></a>00092 <span>///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and</span>
<a name="msg-f:1483717872411799884_l00093"></a>00093 <span>///      then recursively visits the child nodes of x.</span>
<a name="msg-f:1483717872411799884_l00094"></a>00094 <span>///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work</span>
<a name="msg-f:1483717872411799884_l00095"></a>00095 <span>///      similarly.</span>
<a name="msg-f:1483717872411799884_l00096"></a>00096 <span>///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit</span>
<a name="msg-f:1483717872411799884_l00097"></a>00097 <span>///      any child node of x.  Instead, it first calls WalkUpFromBar(x)</span>
<a name="msg-f:1483717872411799884_l00098"></a>00098 <span>///      where Bar is the direct parent class of Foo (unless Foo has</span>
<a name="msg-f:1483717872411799884_l00099"></a>00099 <span>///      no parent), and then calls VisitFoo(x) (see the next list item).</span>
<a name="msg-f:1483717872411799884_l00100"></a>00100 <span>///   3. VisitFoo(Foo *x) does task #3.</span>
<a name="msg-f:1483717872411799884_l00101"></a>00101 <span>///</span>
<a name="msg-f:1483717872411799884_l00102"></a>00102 <span>/// These three method groups are tiered (Traverse* > WalkUpFrom* ></span>
<a name="msg-f:1483717872411799884_l00103"></a>00103 <span>/// Visit*).  A method (e.g. Traverse*) may call methods from the same</span>
<a name="msg-f:1483717872411799884_l00104"></a>00104 <span>/// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).</span>
<a name="msg-f:1483717872411799884_l00105"></a>00105 <span>/// It may not call methods from a higher tier.</span></pre>According to the above statement, the calling relationship between these<br>functions are organized in this way in general:<br><br>Traversal*()<br>{<br>        .......<br>        WalkUpFrom*();<br>        .......<br>}<br><br>WalkUpFrom*()<br>{<br>         .......<br>         Visit*();<br>         .......<br><br>}<br><br>am i right?<br><br>For this statement:<br><pre>00096 <span>///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit</span>
<a name="msg-f:1483717872411799884_l00097"></a>00097 <span>///      any child node of x.  Instead, it first calls WalkUpFromBar(x)</span>
<a name="msg-f:1483717872411799884_l00098"></a>00098 <span>///      where Bar is the direct parent class of Foo (unless Foo has</span>
<a name="msg-f:1483717872411799884_l00099"></a>00099 <span>///      no parent), and then calls VisitFoo(x) (see the next list item).</span></pre>what do you mean by saying "the direct parent class of Foo"?<br></div></span></blockquote><div><br></div><div>For example, if you are currently traversing a CXXRecordDecl, the direct parent class is the RecordDecl (<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html</a>)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div>why i need to visit the parent class before i visit the current class?</div></span></blockquote><div><br></div><div>You don't need to visit anything - the RAV is doing the visitation for you.</div><div>You only need to know those details if you plan to change the traversal.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div>what is the purpose? Could you please give me a short example?<br></div></span></blockquote><div><br></div><div>This way you can implement the Visit(RecordDecl*) method and get a call to it if the real type is a CXXRecordDecl.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div><br>Thank you in advance!<br><br>Sincerely<br>xiaohui<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div><br><br></span>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>