<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 20, 2014 at 8:08 PM, Christian Schafmeister <span dir="ltr"><<a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I’m creating AST Matchers to match recordDecls and varDecls and match the types for the varDecls to recordDecls.</div>
<div>In many cases the varDecls are instantiating template classes and some of the template classes are specialized.</div><div><br></div><div>If I use this matcher:</div><div>recordDecl(isTemplateInstantiation(), isSameOrDerivedFrom(recordDecl(hasName("BAR")))).bind(“WHOLE”)    —> FOO<A> node</div>
<div>or</div><div><div>recordDecl(isExplicitTemplateSpecialization(), isSameOrDerivedFrom(recordDecl(hasName("BAR")))).bind(“WHOLE”)   —> FOO<int> node</div></div><div><br></div><div>How do I get the full name of the nodes that match and are bound to “WHOLE”?</div>
<div><br></div><div>node.getName() —>  “FOO” not “FOO<A>”  or “FOO<int>"</div></div></blockquote><div><br></div><div>I don't have a good answer. Generally, getName() (or getNameAsString()) will print the full declaration for anything that's a declaration context. So if you match a member m in FOO, you'd get FOO<int>::m. This will be expanded for everything but the last part.</div>
<div>I don't know whether there's a good way to get the expansion for everything. I've never needed it, though; out of curiosity, what do you need it for?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div><br></div><div><br></div><div>Here is the sample code:</div><div><br></div><div><div class=""><div><font face="Courier">#include <stdio.h></font></div><div><font face="Courier">#include <core/foundation.h></font></div>
<div><font face="Courier">#include <core/object.h></font></div><div><font face="Courier">#include <core/holder.h></font></div><div><font face="Courier"><br></font></div><div><font face="Courier">namespace asttooling {</font></div>
<div><font face="Courier"><br></font></div></div><div><font face="Courier">    class BAR {};</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">    template<typename T> class FOO : public BAR {};</font></div>
<div><font face="Courier">    class A {};</font></div><div><font face="Courier">    </font></div><div><font face="Courier">    template<> class FOO<int> : public BAR {};</font></div><div><font face="Courier"><br>
</font></div><div><font face="Courier">    void tinyFunc()</font></div><div><font face="Courier">    {</font></div><div><font face="Courier">        FOO<A> xa;</font></div><div><font face="Courier">        FOO<int> xi;</font></div>
<div><font face="Courier">        printf("Hi there, this is tinyFunc @%p %p\n", &xa, &xi);</font></div><div><font face="Courier">    }</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">};</font></div>
</div><div><br></div><br><div>
Christian Schafmeister<br><a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a><br><br>

</div><div><div class="h5">
<br><div><div>On Feb 20, 2014, at 6:56 AM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:</div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Feb 20, 2014 at 3:49 PM, Christian Schafmeister <span dir="ltr"><<a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Manuel,<div><br></div><div>I completely missed those predicates - thank you!</div><div>

<br></div><div>How do I get the full name of an instantiated template recordDecl?</div><div><br></div><div>As in:</div><div>template <class T> class X;</div><div>class A;</div><div><br></div><div>X<A> xa;</div>

<div><br></div><div>If a varDecl(…) matches on xa - how do I get the "X<A>” name?</div></div></blockquote><div><br></div><div>Do you want to "get" it or "match" it. Assuming you want to "get" it, you'd say something like varDecl(hasType(qualType().bind("t"))) (untested ;), and then in the callback extract the QualType and call getAsString() on it.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Best,</div><div><br></div><div>.Chris.<span><font color="#888888"><br>

<div>
Christian Schafmeister<br><a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a><br><br>

</div>
<br></font></span><div><div><div>On Feb 20, 2014, at 12:53 AM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:</div><br></div><div><div><blockquote type="cite">
<div dir="ltr"><div>hasAncestor(decl(anyOf(recordDecl(</div><div>  isTemplateInstantiation()),</div><div>  functionDecl(isTemplateInstantiation()))</div><div><br></div><div>should do what you want.</div></div><div class="gmail_extra">


<br><br><div class="gmail_quote">On Wed, Feb 19, 2014 at 11:01 PM, Christian Schafmeister <span dir="ltr"><<a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div style="word-wrap:break-word"><div><br></div><div>If I match a varDecl() that is in a method of a template class I get a match for the template and instantiated templates </div><div>- is there a way to tell the difference by matching some difference in the ancestors of the varDecl node?</div>


<div><br></div><div>I get a match for the translate::from_object<T> a0(*args);  varDecl in the method activate (see below) that has this type:</div><div>from_object<type-parameter-0-0, struct std::__1::integral_constant<_Bool, true> ></div>


<div><br></div><div>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>"</div><div>


<br></div><div>There is a clear difference in the name - but I was looking for something that didn’t feel like a hack.</div><div><br></div><div>Are there differences in the AST class node for TestFunctoid when it is a template class vs when it is an instantiated template class?</div>


<div><br></div><div><br></div><div><font face="Courier"><br></font></div><div><div><font face="Courier">#include <stdio.h></font></div><div><font face="Courier">#include <core/foundation.h></font></div><div><font face="Courier">#include <core/object.h></font></div>


<div><font face="Courier">#include <core/holder.h></font></div><div><font face="Courier"><br></font></div><div><font face="Courier">namespace asttooling {</font></div><div><font face="Courier"><br></font></div><div>


<font face="Courier"><br></font></div><div><font face="Courier">    template<typename T></font></div><div><font face="Courier">    class TestFunctoid : public core::Functoid {</font></div><div><font face="Courier">    public:</font></div>


<div><font face="Courier"><br></font></div><div><font face="Courier">        TestFunctoid(const string& name) : core::Functoid(name) {};</font></div><div><font face="Courier">        core::T_mv activate( core::const_ActivationFrame_spREF closedOverFrame, int numArgs, ArgArray args )</font></div>


<div><font face="Courier">        {</font></div><div><font face="Courier">            translate::from_object<T> a0(*args);</font></div><div><font face="Courier">            printf( "Address of a0= %p\n", &a0);</font></div>


<div><font face="Courier">            return Values0<core::T_O>();</font></div><div><font face="Courier">        }</font></div><div><font face="Courier">    };</font></div><div><font face="Courier"><br></font></div>


<div><font face="Courier"><br></font></div><div><font face="Courier"><br></font></div><div><font face="Courier">    void tinyFunc()</font></div><div><font face="Courier">    {</font></div><div><font face="Courier">        TestFunctoid<int> j("test");</font></div>


<div><font face="Courier">        TinyStruct x(10);</font></div><div><font face="Courier">        tinyFunc(x);</font></div><div><font face="Courier">        printf("Hi there, this is tinyFunc\n");</font></div><div>


<font face="Courier">    }</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">};</font></div></div><div><br></div><div>
<div><div>Christian Schafmeister</div><div>Associate Professor</div><div>Chemistry Department</div><div>Temple University</div></div>

</div>


<br></div></blockquote></div><br></div>
</blockquote></div></div></div><br></div></div></blockquote></div><br></div></div>
</blockquote></div><br></div></div></div></blockquote></div><br></div></div>