Recovering the unqualified class name from a function parameter

Hello,

I’m trying without success to recover the unqualified name for a type while parsing a CXXMethodDecl. The first problem is that the Type class doesn’t have a getNameAsString, or getAsString. The second problem is that even getting the unqualified type and dumping it still resolves to qualified types.

Suppose I have a parameter on a function named as “const ClassType& x”:

all of those:

(*param)->getType()->getUnqualifiedDesugaredType()->dump();
(*param)->getType().getUnqualifiedType()->dump();

(*param)->getType()->dump();

returns const ClassType &identifier when dumping.

How is the best way to retrieve “ClassType” as a string?

Thanks

Victor

Try (*param)->getType().getNonReferenceType().getUnqualifiedType().dump() .

-Eli

That managed to remove the const and the reference type, but when I try to use the “getAsString” method it returns to me “class Type”. I could manually remove the "class " part, just to know if there is a way to do in a non hackish way.

Thanks

This did the trick:

LangOptions lo;
PrintingPolicy pp(lo);
pp.SuppressTagKeyword = true;

std::string str = (*param)->getType().getNonReferenceType().getUnqualifiedType().getAsString(pp);

Thanks!