获取AST访客叮当的函数声明类型

问题描述:

我已经实现了一个使用Clang的AST访问器。 有了这段代码,我可以检索函数调用名称correclty。获取AST访客叮当的函数声明类型

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; 

} 

我想提取函数声明类型。例如 int my_func(int a,int b){..} 我想提取int类型。它实现的方式将返回除函数名外的整个函数声明。上面这段代码在funcType中将返回int(int a,int b)

我该如何解决这个问题? 谢谢!

这听起来像你试图找到返回类型,而不是函数的声明类型。为此,请使用getReturnType()

+0

想使用getReturnType(),虽然在文档中我可以看到,这个方法在类FunctionDecl类的编译器给了我这个 存在错误:“类铿锵:: FunctionDecl”没有名为成员“getReturnType” –

+0

你是对的!虽然自从使用llvm/clang 3.4以来,getReturnType()不存在,但存在getResultType()。它的功能相同。 –