[cfe-dev] Question about ASTMatchers

Christian Schafmeister chris.schaf at verizon.net
Thu Feb 20 06:49:09 PST 2014


Manuel,

I completely missed those predicates - thank you!

How do I get the full name of an instantiated template recordDecl?

As in:
template <class T> class X;
class A;

X<A> xa;

If a varDecl(…) matches on xa - how do I get the "X<A>” name?

Best,

.Chris.
Christian Schafmeister
chris.schaf at verizon.net


On Feb 20, 2014, at 12:53 AM, Manuel Klimek <klimek at google.com> wrote:

> hasAncestor(decl(anyOf(recordDecl(
>   isTemplateInstantiation()),
>   functionDecl(isTemplateInstantiation()))
> 
> should do what you want.
> 
> 
> On Wed, Feb 19, 2014 at 11:01 PM, Christian Schafmeister <chris.schaf at verizon.net> wrote:
> 
> If I match a varDecl() that is in a method of a template class I get a match for the template and instantiated templates 
> - is there a way to tell the difference by matching some difference in the ancestors of the varDecl node?
> 
> I get a match for the translate::from_object<T> a0(*args);  varDecl in the method activate (see below) that has this type:
> from_object<type-parameter-0-0, struct std::__1::integral_constant<_Bool, true> >
> 
> I also get a match that I think is from the instantiation TestFunctoid<int> j(“test”) in tinyFunc - it has this type: "struct translate::from_object<int, std::true_type>"
> 
> There is a clear difference in the name - but I was looking for something that didn’t feel like a hack.
> 
> Are there differences in the AST class node for TestFunctoid when it is a template class vs when it is an instantiated template class?
> 
> 
> 
> #include <stdio.h>
> #include <core/foundation.h>
> #include <core/object.h>
> #include <core/holder.h>
> 
> namespace asttooling {
> 
> 
>     template<typename T>
>     class TestFunctoid : public core::Functoid {
>     public:
> 
>         TestFunctoid(const string& name) : core::Functoid(name) {};
>         core::T_mv activate( core::const_ActivationFrame_spREF closedOverFrame, int numArgs, ArgArray args )
>         {
>             translate::from_object<T> a0(*args);
>             printf( "Address of a0= %p\n", &a0);
>             return Values0<core::T_O>();
>         }
>     };
> 
> 
> 
>     void tinyFunc()
>     {
>         TestFunctoid<int> j("test");
>         TinyStruct x(10);
>         tinyFunc(x);
>         printf("Hi there, this is tinyFunc\n");
>     }
> 
> };
> 
> Christian Schafmeister
> Associate Professor
> Chemistry Department
> Temple University
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140220/2da3eb67/attachment.html>


More information about the cfe-dev mailing list