Getting parameter information from FunctionDecl class in clang

How to get parameter information as a string from FunctionDecl class in clang. I try, but am confused by so many inheritances. The compiler also says that getReturnType () is not a member of FunctionDecl, but the doxygen documentation says otherwise. Please help. http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html

using namespace std;
using namespace clang;
using namespace clang::driver;
using namespace clang::tooling;
using namespace llvm;

.......
class ExampleVisitor : public RecursiveASTVisitor<ExampleVisitor> 
{
    ......
    virtual bool VisitFunctionDecl(FunctionDecl *func) 
    {
            numFunctions++;
            string funcName = func->getNameInfo().getName().getAsString();
            string retName = func->getReturnType().getAsString();
            ...
            return true;
    }

}

Errors: -

'class clang :: FunctionDecl has no member named getReturnType

+4
source share
3 answers

, ,

std::string retType = F->getReturnType().getAsString();
std::string arg0;
if(F->getNumParams() > 0)
  arg0 = F->parameters()[0]->getQualifiedNameAsString();

getAsString().


: , Clang. , . !

+3

,

getResultType() 

getReturnType()

llvm 3.4 getReturnType(), , getResultType().

+2

To get a list of all parameters dynamically, below code will help.

string retName = func->getReturnType().getAsString();
for(int i=0; i<func->getNumParams(); i++)
{
    std::cout << " " << func->parameters()[i]->getQualifiedNameAsString();
}
...     
0
source

Source: https://habr.com/ru/post/1545654/


All Articles