[cfe-dev] How to get the template argument type from AST matcher?

Manuel Klimek klimek at google.com
Mon Jul 20 02:32:45 PDT 2015


It actually depends on what you want :) Do you want
a) the name of the class (then what Nicola wrote is good)
b) what the user wrote as template argument; in that case, you'd want to
get the TypeLoc at that point, and then use Lexer::getSourceText

On Mon, Jul 20, 2015 at 9:39 AM Han Wang <wanghan02 at gmail.com> wrote:

> Hi Jason,
>
> Thanks! It works. :)
>
> Best regards,
> Han
>
> On Mon, Jul 20, 2015 at 9:14 AM, Jason Haslam <jason.haslam at gmail.com>
> wrote:
>
>> Call the version of getAsString that takes a PrintingPolicy with the
>> SuppressTagKeyword field set. Something like:
>>
>> PrintingPolicy pp;
>> pp.SuppressTagKeyword = true;
>> type.getAsString(pp);
>>
>> Jason
>>
>>
>> > On Jul 17, 2015, at 10:45 AM, Han Wang <wanghan02 at gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > Let's say we have code like this,
>> >
>> > class MyClass {};
>> > vector<MyClass> a;
>> >
>> > I would like to get MyClass out as a string. We could use this matcher
>> to get the TemplateArgument.
>> >
>> > varDecl(hasType(classTemplateSpecializationDecl(hasTemplateArgument(0,
>> templateArgument().bind("TemplateType")))))
>> >
>> > We could also use xxx->getAsType().getAsString() to get the type
>> string. But the thing is I can only get the type "class MyClass". How can I
>> get only "MyClass" without "class"?
>> >
>> > Thanks!
>> > Best regards,
>> > Han
>> > _______________________________________________
>> > cfe-dev mailing list
>> > cfe-dev at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150720/1da6276f/attachment.html>


More information about the cfe-dev mailing list