[cfe-dev] getting all function calls?
Adrien Chauve
adrien.chauve at gmail.com
Wed Jun 8 12:08:12 PDT 2011
Hi,
I'm a clang newbie but I'm also trying to write a plugin (see
http://github.com/achauve/cppanalyze) and I'm using the following
skeleton to get a hand on all declarations and statements:
class MyConsumer : public ASTConsumer, public RecursiveASTVisitor<MyConsumer>
{
//===--------------------------------------------------------------------===//
// ASTConsumer virtual interface
//===--------------------------------------------------------------------===//
virtual void HandleTranslationUnit(ASTContext &context)
{
// traverse AST to visit declarations and statements
TranslationUnitDecl* tu_decl = context.getTranslationUnitDecl();
TraverseDecl(tu_decl);
}
//===--------------------------------------------------------------------===//
// RecursiveASTVisitor implicit interface
//===--------------------------------------------------------------------===//
/// Visit call statements
bool VisitCallExpr(CallExpr *node)
{
if (node->getDirectCallee())
{
FunctionDecl *func_decl = node->getDirectCallee();
// ... do whatever you want with the function declarations
of the functions that were called
}
return true;
}
};
I'm not sure this is the best solution but as far as I tested it it works fine.
Adrien
On Wed, Jun 8, 2011 at 19:11, ret val <retval386 at gmail.com> wrote:
>
> I would like to write plugin that prints out all the functions that are called and what function they are being called from, later on I would like to know if a function pointer was called. I'm wondering what the best approach would be.
>
> I think I should use a ASTConsumer and implement the HandleTranslationUnit method. From there I would have a ASTContext and I'm not entirely sure where I could find the function calls.
>
> Thanks
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
More information about the cfe-dev
mailing list