[cfe-dev] what order it is in TraverseDecl, TraverseType and TraverseStmt?

Philip Craig philipjcraig at gmail.com
Sat Dec 8 20:26:24 PST 2012


On Fri, Dec 7, 2012 at 10:24 PM, Rambo <hunanlwm at sina.cn> wrote:
> Hi,everyone
>
> From this  page
> <http://clang.llvm.org/doxygen/RecursiveASTVisitor_8h_source.html>   we can
> see that Traverse* invoke  WalkUpFrom* and WalkUpFrom* invoke  Visit*,but it
> don't tell us what order it is in TraverseDecl,TraverseType and
> TraverseStmt.In other words,which is executed
> first,TraverseDecl,TraverseType or TraverseStmt?If TraverseDecl is first,How
> it invoke other two methods?

A node can be only one of Decl, Type or Stmt, so for a given node,
only one of Traverse* is executed.

It is up to the user of RecursiveASTVisitor to invoke the first
traversal method. For example, you might start the traversal by
calling TraverseDecl for the TranslationUnitDecl.

The Traverse* methods will then recursively invoke the Traverse*
methods for each child of a node. For example, calling TraverseDecl
for a FunctionDecl will result in TraverseStmt being called for the
body of the function, if it exists.



More information about the cfe-dev mailing list