Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang tooling. Type name without keyword

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".

like image 522
Yuriy Avatar asked Oct 21 '25 17:10

Yuriy


1 Answers

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.

like image 124
Yuriy Avatar answered Oct 25 '25 04:10

Yuriy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!