[cfe-dev] Find Type by name

Roman Popov via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 28 14:12:25 PST 2018


Thanks Artem. This is what I've tried before writing original mail. However
it does not work, I got zero matches.

Here is reproducer:

*namespace my_nm {*
*template<typename T, unsigned U>*
*struct my_type {  };*
*}*


*my_nm::my_type<int, 10> m;*


I got types from LLVM IR analysis, and then want to find them in Clang AST.

>From LLVM I got mangled name:
*N5my_nm7my_typeIiLj10EEE*

Demangled to:
*my_nm::my_type<int, 10u>*

However I can't find it by any matcher:

auto matches = match(qualType(asString("*my_nm::my_type<int,
10u>*")).bind("types"),
astCtx);  // Zero matches

auto matches = match(qualType(asString("*N5my_nm7my_typeIiLj10EEE*")).bind("types"),
astCtx);  // Zero matches

Probably there is some other way to go back from LLVM IR to Clang AST?


Thanks,
Roman


2018-02-28 12:36 GMT-08:00 Artem Dergachev <noqnoqneo at gmail.com>:

> I don't think it's possible via straightforward lookup - you might need to
> scan the AST to do this.
>
> Eg. using ASTMatchers:
>
>     qualType(asString("my_nm::my_type<int, 10u>"))
>
> Or, if you're not using ASTMatchers (likely), you can do the same with a
> RecursiveASTVisitor. Or manually.
>
>
> On 27/02/2018 10:56 AM, Roman Popov via cfe-dev wrote:
>
>> Hello,
>>
>> Is it possible to find type in AST by it's qualified type?
>>
>> For example I have string "my_nm::my_type<int, 10u>", how can I get
>> clang::QualType if type is present in translation unit?
>>
>> Thanks,
>> Roman
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180228/f36d4a05/attachment.html>


More information about the cfe-dev mailing list