1

I have implemented an AST visitor using Clang. With this piece of code and I can retrieve the function call name correclty.

virtual bool VisitFunctionDecl(FunctionDecl *func)

{

    numFunctions++;

    string funcName = func->getNameInfo().getName().getAsString();

string funcType = func->getType().getAsString();

APIs << funcType << endl;

    APIs << "\n" << funcName <<": ";

    return true;

}

I want to extract also the function declaration type. for example int my_func(int a, int b){..} I want to extract the type int. The way its implemented it returns me the whole function declaration except the name. The above piece of code in funcType will return int (int a, int b)

How can I fix this?? Thank you!

Andreas Geo
  • 365
  • 2
  • 15

1 Answers1

1

It sounds like you're trying to find the return type, not the declared type of the function. Use getReturnType() for this.

Jonathan Sharman
  • 636
  • 6
  • 16
  • Am trying to use getReturnType() and although in the documentation I can see that this method exists in the class FunctionDecl class the compiler gives me this error: ‘class clang::FunctionDecl’ has no member named ‘getReturnType’ – Andreas Geo Jun 20 '16 at 12:25
  • you were right! Although since am using llvm/clang 3.4 the getReturnType() does not exist but getResultType() exists. Its the same function. – Andreas Geo Jun 25 '16 at 16:18