On Thu, Oct 11, 2012 at 12:03 PM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We should make that decisions together with the Type/TypeLoc matching.<br>
I think looking through typedefs needs to be done with matchers for<br>
types. matchesName()/hasName() on declarations should always look at<br>
the name of the type used for the declaration and not at an alias<br>
defined in a typedef.<br></blockquote><div><br></div><div><br></div><div>I'm not sure I agree. It seems like the name property is really one of the decl or typedef, not one of the type.</div><div><br></div><div>I'm curious about other opinions, though...</div>
<div><br></div><div>Cheers,</div><div>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers,<br>
Daniel<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, Oct 11, 2012 at 11:47 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
> On Thu, Oct 11, 2012 at 11:05 AM, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com">xazax.hun@gmail.com</a>> wrote:<br>
>> Hi!<br>
>><br>
>> It looks like ...hasType(namedDecl(matchesName("std::set.*iterator"))) ...<br>
>> only tries to match ::std::_Rb_tree_const_iterator, but not<br>
>> std::set<foobar>::iterator, so I basicaly can't match typedefs. I think it<br>
>> is not possible to match on typedef-ed types right now.<br>
>><br>
>> There is one test case:<br>
>> EXPECT_TRUE(matches("typedef int X;", NamedX));<br>
>><br>
>> However it matches a typedef declaration. However if we wan't to match<br>
>> something like "X i;" later on, we can not do that, however it would be<br>
>> extremely useful.<br>
>><br>
>> Any comments on this?<br>
><br>
> We need to write a matcher that supports this. We already have some of<br>
> the supporting code for isDerivedFrom which looks through typedefs.<br>
> We'll basically want to have a matcher matchesNameOrTypedef (minus<br>
> finding a better name for the matcher ;) that does what you want.<br>
><br>
> Cheers,<br>
> /Manuel<br>
><br>
>><br>
>> Thanks,<br>
>> Gábor<br>
>><br>
>><br>
>><br>
>> On 11 October 2012 09:39, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com">xazax.hun@gmail.com</a>> wrote:<br>
>>><br>
>>> Hi!<br>
>>><br>
>>> More details on matching template specializations. After further trials I<br>
>>> even tried this piece of code:<br>
>>><br>
>>><br>
>>> MatcherProxy StlCOAPPred::getMatcher()<br>
>>> {<br>
>>>   TypeMatcher type = unless(anything());<br>
>>><br>
>>>   for(const auto& e : gContainers)<br>
>>>     type = anyOf(hasDeclaration(recordDecl(hasName(e))), type);<br>
>>><br>
>>>   return id("id",<br>
>>>             varDecl(allOf(hasType(<br>
>>><br>
>>> classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
>>><br>
>>> refersToType(hasDeclaration(hasDescendant(recordDecl(hasName("std::auto_ptr")))))))),<br>
>>>                           hasType(type))));<br>
>>> }<br>
>>><br>
>>> If I remove the hasDescendant, it works flawlessly for example for<br>
>>> vector<auto_ptr<int>>, however it will not fork for<br>
>>> vector<vector<auto_ptr<int>>>. If I add that hasDescendant it will not match<br>
>>> anything. The same applies to the code I pasted in my mail earlier. If you<br>
>>> have any idea what could cause this issue, please tell me.<br>
>>><br>
>>> Thanks,<br>
>>> Gábor<br>
>>><br>
>>><br>
>>><br>
>>> On 10 October 2012 15:37, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com">xazax.hun@gmail.com</a>> wrote:<br>
>>>><br>
>>>> For the second one, I altered my snippet:<br>
>>>><br>
>>>><br>
>>>> MatcherProxy StlCOAPPred::getMatcher()<br>
>>>> {<br>
>>>>   TypeMatcher type = unless(anything());<br>
>>>><br>
>>>>   for(const auto& e : gContainers)<br>
>>>>     type = anyOf(hasDeclaration(recordDecl(hasName(e))), type);<br>
>>>><br>
>>>>   return id("id",<br>
>>>>             varDecl(allOf(hasType(recordDecl(hasDescendant(<br>
>>>><br>
>>>> classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
>>>><br>
>>>> refersToType(hasDeclaration(recordDecl(hasName("std::auto_ptr"))))))))),<br>
>>>>                          hasType(type))));<br>
>>>> }<br>
>>>><br>
>>>><br>
>>>> But it does not seems to work. It do not give me any matches.<br>
>>>><br>
>>>> For the first one, I futher will investigate it later today, however my<br>
>>>> bet would be that, it tries to match "std::_Rb_tree_const_iterator".<br>
>>>><br>
>>>> Thanks,<br>
>>>> Gábor<br>
>>>><br>
>>>><br>
>>>> On 10 October 2012 13:55, Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:<br>
>>>>><br>
>>>>> +cfe-dev, please remember to include<br>
>>>>><br>
>>>>> I don't see anything generally wrong with your approach to match<br>
>>>>> iterators. What I would do to debug this is locally editing<br>
>>>>> ASTMatchers.h to add a "llvm::outs() << FullName;" debug output into<br>
>>>>> the matchesName matcher. That way, you can see what it is actually<br>
>>>>> trying to match.<br>
>>>>><br>
>>>>> The second question should work like:<br>
>>>>><br>
>>>>>   varDecl(hasType(recordDecl(<br>
>>>>>     hasDescendent(classTemplateSpecialization(hasAnyTemplateArgument(<br>
>>>>>       refersToType(hasName("std::auto_ptr")))))))).bind("id")<br>
>>>>><br>
>>>>> This is just as a general idea, it might not yet be correct.<br>
>>>>><br>
>>>>> Cheers,<br>
>>>>> Daniel<br>
>>>>><br>
>>>>> On Wed, Oct 10, 2012 at 1:23 PM, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com">xazax.hun@gmail.com</a>><br>
>>>>> wrote:<br>
>>>>> > Hi!<br>
>>>>> ><br>
>>>>> > I want to create a matcher to match things like<br>
>>>>> > std::set<int>::iterator.<br>
>>>>> ><br>
>>>>> > I come up with this one: ...<br>
>>>>> > hasType(namedDecl(matchesName("std::set.*iterator"))) ...<br>
>>>>> > however it did not give me any match.<br>
>>>>> ><br>
>>>>> > Using the internal name of the iterator class like<br>
>>>>> > std::_Rb_tree_const_iterator would work, however that is<br>
>>>>> > implementation<br>
>>>>> > defined, so I do not want to rely on that one.<br>
>>>>> ><br>
>>>>> > Do you have any idea what am I doing wrong?<br>
>>>>> ><br>
>>>>> > My another question is, for example if I want to search for auto_ptr<br>
>>>>> > as<br>
>>>>> > template arguments in containers, I want to match<br>
>>>>> > vector<auto_ptr<int>> and<br>
>>>>> > also vector<vector<auto_ptr<int>>> ... etc.<br>
>>>>> ><br>
>>>>> > Is there any proper way to do it? My current solution:<br>
>>>>> ><br>
>>>>> > MatcherProxy StlCOAPPred::getMatcher()<br>
>>>>> > {<br>
>>>>> >   TypeMatcher type = unless(anything());<br>
>>>>> ><br>
>>>>> >   for(const auto& e : gContainers)<br>
>>>>> >     type = anyOf(hasDeclaration(recordDecl(hasName(e))), type);<br>
>>>>> ><br>
>>>>> >   auto templateSpecWithArgument = [](DeclarationMatcher decl) -><br>
>>>>> > DeclarationMatcher {<br>
>>>>> >     return<br>
>>>>> ><br>
>>>>> > classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(hasDeclaration(decl))));<br>
>>>>> >   };<br>
>>>>> ><br>
>>>>> >   // 1, 2, 3 times embedded<br>
>>>>> >   DeclarationMatcher decl =<br>
>>>>> > anyOf(templateSpecWithArgument(recordDecl(hasName("std::auto_ptr"))),<br>
>>>>> ><br>
>>>>> ><br>
>>>>> > templateSpecWithArgument(templateSpecWithArgument(recordDecl(hasName("std::auto_ptr")))),<br>
>>>>> ><br>
>>>>> ><br>
>>>>> > templateSpecWithArgument(templateSpecWithArgument(templateSpecWithArgument(recordDecl(hasName("std::auto_ptr"))))));<br>
>>>>> ><br>
>>>>> ><br>
>>>>> >   return id("id",varDecl(allOf(hasType(decl),hasType(type))));<br>
>>>>> > }<br>
>>>>> ><br>
>>>>> > I use templateSpecWithArgument, and nesting it. I could write a loop<br>
>>>>> > to do<br>
>>>>> > this nesting several times, however I think that could degrade the<br>
>>>>> > performance significantly (I did not measure yet).<br>
>>>>> ><br>
>>>>> > Thanks<br>
>>>>> > Gábor<br>
>>>><br>
>>>><br>
>>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>><br>
</div></div></blockquote></div><br></div>