<div dir="ltr"><div><div class="gmail_signature" data-smartmail="gmail_signature">Hi All, <br></div></div><div class="gmail_quote"><div dir="ltr"><div><br></div><div>I have looked thru the previous posts on this topic in the mailing-list archives, and still can't get things to work. Hence the repost --- for which I apologize. </div><div><br></div><div>I would like to get the body of a called function when visiting a CallExpr. </div><div>I create a recursive AST visitor, and handle the translation units correctly (to the best of my knowledge), and still am not able to get the body. The function is declared in a header file and implemented in a .c file. For brevity, I am recreating a toy example here: </div><div><br></div><div>def.h: </div><div> void foo();</div><div><br></div><div>impl.c: </div><div> #include "def.h"</div><div> </div><div> void foo(){</div><div> printf("in func foo\n");</div><div> }</div><div><br></div><div>main.c: </div><div> #include "def.h"</div><div><br></div><div> int main(){</div><div> foo();</div><div> }</div><div><br></div><div>Running my Visitor code here is able to parse the call expression, but returns nullptr on </div><div>callexpr->getDirectCallee()->getBody(). Similarly, callexpr->getDirectCallee()->hasBody() </div><div>returns false. </div><div>Could anyone kindly suggest what should I do? </div><div><br></div><div>Here is the simplified code for my visitor: </div>class FVisitor : public RecursiveASTVisitor<FVisitor> {<br> public:<br> bool VisitCallExpr(CallExpr *C){<br> const FunctionDecl *FD = C->getDirectCallee();<br> // try both variants of getBody<br> if(FD->getBody())<br> cout << "found body"<<endl;<br> else if(FD->getBody(FD))<br> cout << "found body"<<endl;<br> return true;<br> }<br>};</div><div dir="ltr"><br><div>Thanks,</div><div><div><div data-smartmail="gmail_signature">--<div>Himanshu</div></div></div>
</div></div>
</div><br></div>