one question about CIrewriter.cpp

Hi,everybody

I meet a trouble now.if you have a look at this page
https://github.com/loarabia/Clang-tutorial
<https://github.com/loarabia/Clang-tutorial> and understand the program
CIrewriter.cpp
deeply,I may be ask you a question:How the methods be invoked?The three
methods is located at line 82-line 84. as follows.
bool VisitStmt(Stmt *s);
bool VisitFunctionDecl(FunctionDecl *f);
Expr *VisitBinaryOperator(BinaryOperator *op);

Thanks for any help to solve my problem or answer my questions! I am looking
forward for you constructive feedback.

Rambo

They overload the methods of class RecursiveASTVisitor (clang/AST/RecursiveASTVisitor.h) and are invoked during the TraverseDecl process. The traverse starts at line 361: rv.TraverseDecl(*b);

More precisely, the VisitStmt/VisitFooStmt is called by WalkUpFromStmt/WalkUpFromFooStmt methods, which is invoked in TraverseStmt/TraverseFooStmt. You can look into “switch (S->getStmtClass())” in TraverseStmt, and the macro DEF_TRAVERSE_STMT.

The Decl thing works in a similar way. DEF_TRAVERSE_DECL of specific decls call TraverseStmt.

The BinaryOperator is a subclass of Expr, which is derived from Stmt. See DEF_TRAVERSE_STMT(BinaryOperator …

Dear,
Thanks for giving me some beautiful advices,but I have some questions at
all.

Firstly,the sentence
"More precisely, the VisitStmt/VisitFooStmt is called by
WalkUpFromStmt/WalkUpFromFooStmt methods, which is invoked in
TraverseStmt/TraverseFooStmt",you meaning is that
WalkUpFromStmt/WalkUpFromFooStmt methods invoke the VisitStmt/VisitFooStmt
and WalkUpFromStmt/WalkUpFromFooStmt methods is called by
TraverseStmt/TraverseFooStmt?I don't understand how the
WalkUpFromStmt/WalkUpFromFooStmt methods be invoked.

Secordly,What the roles the macro DEF_TRAVERSE_STMT takes in this paper?

Lastly,If I want to rewriter this program(CIrewriter.cpp),What is methods of
class MyRecursiveASTVisitor
can i add?Please tell me the function of the methods if you have one!

Thanks your attention and I look forward you respose.

Rambo

FWIW, I'm finding it really useful to run clang++ with -E on some file
which includes RecursiveASTVisitor.h. The resulting preprocessed
output has the macro-expanded definition of the template class. This
tells you all the functions. You could puzzle it all out from the
type hierarchy, and figuring out the macros, but it's faster just to
look at the real file. In fact, the result is a github gist right
here: git://gist.github.com/3980452.git
(https://gist.github.com/3980452). I elided the bodies, so that all
there is is the declarations.

If one were to do a more sophisticated edit of the macro expansion,
one could use d3.js or something like that to display the inheritance
hierarchy. I'll just bet it would be possible to define the macros in
clang/AST/StmtNodes.inc, clang/AST/TypeNodes.def and
clang/AST/DeclNodes.inc to generate the javascript for the hierarchy
display. That would be for someone with more energy and time than I
have, though.