[cfe-dev] Find Type by name

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 28 17:37:44 PST 2018


Sorry i don't have a quick way of trying this at the moment; Does it 
work with "struct my_nm::my_type<int, 10>"? - because that's what i see 
in clang's -ast-dump. Does varDecl(hasType(asString(...))) work? If you 
match qualType() and dump .getAsString() on all results, what do you see?

Cause i think it should ultimately work.

On 28/02/2018 2:12 PM, Roman Popov wrote:
> 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 
> <mailto: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 <mailto:cfe-dev at lists.llvm.org>
>         http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>         <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>
>
>




More information about the cfe-dev mailing list