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?
You can use
typeid
to get the name of any type. Although it will vary from compiler to compiler, and may not be a pretty name.If you need to do this for a lot of classes, you could make the call part of a base class, then any class that needs the functionality can just inherit from it.
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: