[cfe-dev] Traversing a function body for call expressions. How ?
Manasij Mukherjee
manasij7479 at gmail.com
Fri Dec 12 02:39:19 PST 2014
Hi,
Here is my code, sorry for the delay.
class FunctionBodyVisitor : public clang::StmtVisitor<FunctionBodyVisitor> {
public:
void VisitCallExpr(clang::CallExpr* Expr) {
llvm::outs() << Expr->getCalleeDecl()->getAsFunction()->getName() << "\n";
//this is never called
}
};
class DummyVisitor : public clang::RecursiveASTVisitor<DummyVisitor> {
public:
bool VisitFunctionDecl(clang::FunctionDecl* Decl) {
llvm::outs() << Decl->getName() << "\n"; // this part visibly works
stmtVisitor.Visit(Decl->getBody());
return true;
}
private:
FunctionBodyVisitor stmtVisitor;
};
The code on which this is called is:
void foo()
{
}
int main()
{
foo(); // I want to get to this call expression
}
Manasij
On Sat, Dec 6, 2014 at 8:18 AM, Gabor Kozar <kozargabor at gmail.com> wrote:
> Hi,
>
> It should work. Define an StmtVisitor subclass, provide a VisitCallExpr.
> Then in your Visitor::VisitFunctionDecl, construct an StmtVisitor object,
> then call its Visit method with the function's body.
>
> In the future, please also provide source code, to allow us to spot any bugs
> and problems in your code (e.g. you may believe that the code does what you
> say it does, but you might have a bug, etc.).
>
> ---
> Best regards,
>
> Gábor 'ShdNx' Kozár
> http://gaborkozar.me
>
>
>
> On Wed, Dec 3, 2014, at 07:11, Manasij Mukherjee wrote:
>
> Hi,
> In a RecursiveASTVisitor implementation, I implement VisitFunctionDecl.
> Now, from the FunctionDecl I have, I can call getBody and get a Stmt.
>
> How can I visit all the functions this function calls ?
> I have tried creating a StmtVisitor and ..err..defining VisitCallExpr !
> That didn't work.
>
> Can anyone point me to what I should be doing ?
>
> Manasij Mukherjee
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> 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