I'm working on some clang tool, and I need to generate source code with types, that aren't specified explicitly.
The strings with types I get from clang::QualType
is something like: class std::initializer_list<int>
. The issue is to get type without keyword.
I've tried to dyn_cast<>
types (clang::Type
) to all heirs of TypeWithKeyword
but the result is always null.
Of course I can delete all occurrence of "class", "struct", etc. from the string with type name, but I would like to solve this in "clang way".
The answer was simple.
Instead of using QualType::getAsString()
, just needed QualType::getAsString (const PrintingPolicy &Policy)
.
So the code:
PrintingPolicy pp(f_context->getLangOpts());
string typeName = qualType.getAsString(pp);
Works well without changing fields of PrintingPolicy
.