<div dir="ltr"><div>Can you get the AST dump of the function call so we can have a look at it?  The output from "call->dump();" will help since va_start and va_end may be implemented differently on different systems.</div><div><br></div><div>Also another thing to consider is that the functions may actually be function-like macros, which may given an unexpected location for you.  Removing the check "if(thisFileID == 1)" may help.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 8, 2016 at 7:48 AM, Georgiou, Andreas via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hello I have implemented an AST visitor which is working quite good and it can print me on the console the information I want from the AST such as variable declarations, function declarations and function calls. Today while I was experimenting I came across
 a function call which is not recognized as a function call. syntacticaly is the same as a function call. Here is the code:</p>
<p><br>
</p>
<p></p>
<div>void  //this is a part of the tiff library for linux. its in the source file tif_error.c in libtiff directory</div>
<div>TIFFError(const char* module, const char* fmt, ...)</div>
<div>{</div>
<div><span style="white-space:pre-wrap"></span>va_list ap;</div>
<div><span style="white-space:pre-wrap"></span>va_start(ap, fmt);    <------------------------------ THIS IS THE FUNCTION CALL</div>
<div><span style="white-space:pre-wrap"></span>if (_TIFFerrorHandler)</div>
<div><span style="white-space:pre-wrap"></span>(*_TIFFerrorHandler)(module, fmt, ap);</div>
<div><span style="white-space:pre-wrap"></span>if (_TIFFerrorHandlerExt)</div>
<div><span style="white-space:pre-wrap"></span>(*_TIFFerrorHandlerExt)(0, module, fmt, ap);</div>
<div><span style="white-space:pre-wrap"></span>va_end(ap);            <--------------------------------AND THIS ONE</div>
<div>}</div>
<br>
<p></p>
<p>My code of the ASTvisitor is this:</p>
<p><br>
</p>
<p></p>
<div> bool VisitStmt(Stmt *st)</div>
<div>    {</div>
<div>    <span style="white-space:pre-wrap"></span>FullSourceLoc FullLocation = astContext->getFullLoc(st->getLocStart());</div>
<div>    <span style="white-space:pre-wrap"></span>FileID fileID = FullLocation.getFileID();</div>
<div>    <span style="white-space:pre-wrap"></span>unsigned int thisFileID = fileID.getHashValue();</div>
<div>    <span style="white-space:pre-wrap"></span>if(thisFileID == 1) //checks if the node is in the main = input file.</div>
<div>    <span style="white-space:pre-wrap"></span>{</div>
<div>    <span style="white-space:pre-wrap"></span>if (CallExpr *call = dyn_cast<CallExpr>(st))</div>
<div>    <span style="white-space:pre-wrap"></span>{</div>
<div>    <span style="white-space:pre-wrap"></span>numFuncCalls++;</div>
<div><span style="white-space:pre-wrap"></span>//call->dump(); //prints the corresponding line of the AST.</div>
<div> <span style="white-space:pre-wrap"> </span>FunctionDecl *func_decl;</div>
<div><span style="white-space:pre-wrap"></span>if(call->getDirectCallee())</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>func_decl = call ->getDirectCallee();</div>
<div><span style="white-space:pre-wrap"></span>string funcCall = func_decl->getNameInfo().getName().getAsString();</div>
<div><span style="white-space:pre-wrap"></span>cout << "Function call: " << funcCall << " with arguments ";</div>
<div><span style="white-space:pre-wrap"></span>APIs << funcCall << ",";</div>
<div><span style="white-space:pre-wrap"></span>for(int i=0, j = call->getNumArgs(); i<j; i++)</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>//For each argument it prints its type. The function must be declared otherwise it will return int-for unknown argument type.</div>
<div><span style="white-space:pre-wrap"></span>APIs << call->getArg(i)->getType().getAsString()<< ",";</div>
<div><span style="white-space:pre-wrap"></span>cout << call->getArg(i)->getType().getAsString() << ", ";</div>
<div><span style="white-space:pre-wrap"></span>}</div>
<div><span style="white-space:pre-wrap"></span>cout << "\n";</div>
<div><span style="white-space:pre-wrap"></span>}</div>
<div><span style="white-space:pre-wrap"></span>else</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>Expr *expr = call->getCallee();</div>
<div><span style="white-space:pre-wrap"></span>string exprCall = expr->getStmtClassName();</div>
<div><span style="white-space:pre-wrap"></span>cout << "Expression call: " << exprCall << " with arguments ";</div>
<div><span style="white-space:pre-wrap"></span>APIs << exprCall << ",";</div>
<div><span style="white-space:pre-wrap"></span>for(int i=0, j = call->getNumArgs(); i<j; i++)</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>//For each argument it prints its type. The function must be declared otherwise it will return int-for unknown argument type.</div>
<div><span style="white-space:pre-wrap"></span>APIs << call->getArg(i)->getType().getAsString()<< ",";</div>
<div><span style="white-space:pre-wrap"></span>cout << call->getArg(i)->getType().getAsString() << ", ";</div>
<div><span style="white-space:pre-wrap"></span>}</div>
<div><span style="white-space:pre-wrap"></span>cout << "\n";</div>
<div><span style="white-space:pre-wrap"></span>}</div>
<div><span style="white-space:pre-wrap"></span>}</div>
<div>    <span style="white-space:pre-wrap"></span>}</div>
<div>    <span style="white-space:pre-wrap"></span>return true;</div>
<div>    }</div>
<br>
<p></p>
<p>The expression if(call->getDirectCallee()) is not true for those calls. </p>
<p><br>
</p>
<p>How can I extract the "function name" and its arguments like I am doing with the "normal" function calls?</p>
<p><br>
</p>
<p>Thank you.</p>
</div>
</div>

<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>