Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print the type of a parameter (ParmVarDecl) with clang API

Tags:

c++

llvm

clang

I need to print the type of a parameter in a C++ source file using the clang API.

If I have a parameter representation in clang (ParmVarDecl* param) I can print the name of the parameter using param->getNameAsString(). I would need a method param->getTypeAsString(), but there is no such method. So is there another way to do this task?

like image 298
Baris Akar Avatar asked Jul 12 '11 22:07

Baris Akar


1 Answers

Got the answer to my question in the llvm irc:

There is a method std::string clang::QualType::getAsString(SplitQualType split)

So this does work for me:

ParmVarDecl* param = *someParameter;
cout << QualType::getAsString(param->getType().split()) << endl;
like image 145
Baris Akar Avatar answered Oct 20 '22 11:10

Baris Akar