[cfe-dev] Clang function call expressions
Richard Trieu via cfe-dev
cfe-dev at lists.llvm.org
Fri Jul 8 14:39:02 PDT 2016
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.
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.
On Fri, Jul 8, 2016 at 7:48 AM, Georgiou, Andreas via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> 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:
>
>
> void //this is a part of the tiff library for linux. its in the source
> file tif_error.c in libtiff directory
> TIFFError(const char* module, const char* fmt, ...)
> {
> va_list ap;
> va_start(ap, fmt); <------------------------------ THIS IS THE FUNCTION
> CALL
> if (_TIFFerrorHandler)
> (*_TIFFerrorHandler)(module, fmt, ap);
> if (_TIFFerrorHandlerExt)
> (*_TIFFerrorHandlerExt)(0, module, fmt, ap);
> va_end(ap); <--------------------------------AND THIS ONE
> }
>
> My code of the ASTvisitor is this:
>
>
> bool VisitStmt(Stmt *st)
> {
> FullSourceLoc FullLocation =
> astContext->getFullLoc(st->getLocStart());
> FileID fileID = FullLocation.getFileID();
> unsigned int thisFileID = fileID.getHashValue();
> if(thisFileID == 1) //checks if the node is in the main = input file.
> {
> if (CallExpr *call = dyn_cast<CallExpr>(st))
> {
> numFuncCalls++;
> //call->dump(); //prints the corresponding line of the AST.
> FunctionDecl *func_decl;
> if(call->getDirectCallee())
> {
> func_decl = call ->getDirectCallee();
> string funcCall = func_decl->getNameInfo().getName().getAsString();
> cout << "Function call: " << funcCall << " with arguments ";
> APIs << funcCall << ",";
> for(int i=0, j = call->getNumArgs(); i<j; i++)
> {
> //For each argument it prints its type. The function must be declared
> otherwise it will return int-for unknown argument type.
> APIs << call->getArg(i)->getType().getAsString()<< ",";
> cout << call->getArg(i)->getType().getAsString() << ", ";
> }
> cout << "\n";
> }
> else
> {
> Expr *expr = call->getCallee();
> string exprCall = expr->getStmtClassName();
> cout << "Expression call: " << exprCall << " with arguments ";
> APIs << exprCall << ",";
> for(int i=0, j = call->getNumArgs(); i<j; i++)
> {
> //For each argument it prints its type. The function must be declared
> otherwise it will return int-for unknown argument type.
> APIs << call->getArg(i)->getType().getAsString()<< ",";
> cout << call->getArg(i)->getType().getAsString() << ", ";
> }
> cout << "\n";
> }
> }
> }
> return true;
> }
>
> The expression if(call->getDirectCallee()) is not true for those calls.
>
>
> How can I extract the "function name" and its arguments like I am doing
> with the "normal" function calls?
>
>
> Thank you.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160708/0d0db289/attachment.html>
More information about the cfe-dev
mailing list