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

Nikola Smiljanic popizdeh at gmail.com
Fri Jul 17 18:02:09 PDT 2015


I'm not sure if this is the right way to do it, but
xxx->getAsType()->getAsCXXRecordDecl()->getName() should return just the
class name. It's not generic and you have to protect yourself from
getAsCXXRecordDecl returning nullptr.

On Sat, Jul 18, 2015 at 2: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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150718/e73a58f4/attachment.html>


More information about the cfe-dev mailing list