[cfe-dev] How to get Function Definition from CallExpr

Eli Friedman eli.friedman at gmail.com
Tue Jul 16 17:31:19 PDT 2013


n Tue, Jul 16, 2013 at 5:05 PM, Kevin Boos <kevinaboos at gmail.com> wrote:
> Ah, I see now that there are multiple hasBody() functions. I just tried
> using that hasBody(FunctionDecl *&), and it returns false. Makes sense
> because it's essentially the same as me manually iterating over each redecl.
>
> I am indeed using ASTConsumer alongside a RecursiveASTVisitor in the
> libtooling environment. So you're saying that my code (some analysis inside
> VisitFunctionDecl or VisitStmt, per se) will be unaware of the existence of
> a future foo() definition until VisitFunctionDecl is called on that foo()
> definition?
>
> If so, then there is no way to inspect the body/definition of foo() until
> VisitFunctionDecl visits it, right? Specifically, while visiting the main()
> FunctionDecl*, I cannot access the Stmts inside the foo() definition? That's
> really what I need.

You can... you just have to call your visitor from the
HandleTranslationUnit callback.

-Eli



More information about the cfe-dev mailing list