Yeah, I need this for a tool for my thesis (finding common stl mistakes in code), but I can just use for example "std::_Rb_tree_const_iterator", and mention in my thesis, the current implementation only supports one certain STL implementation, and will be improved in the future. <br>
<br>But when some experimental patches are available, I will be happy to test them out.<br><br><br><div class="gmail_quote">On 11 October 2012 14:32, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Thu, Oct 11, 2012 at 1:28 PM, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com" target="_blank">xazax.hun@gmail.com</a>> wrote:<br>
> From my point of view, maybe something like matchesNameOrTypedef would be<br>
> clean/easy. However I will be happy with any approach that provides an<br>
> obvious interface. I think not being able to match typedefs is one of the<br>
> biggest shortcomings of the matchers right now.<br>
<br>
</div>Can you work around that by specifying the names it has been<br>
typedef'ed to for now?<br>
<div><div><br>
><br>
><br>
> On 11 October 2012 14:14, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:<br>
>><br>
>> On Thu, Oct 11, 2012 at 12:03 PM, Daniel Jasper <<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>><br>
>> wrote:<br>
>>><br>
>>> 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>
>><br>
>><br>
>><br>
>> I'm not sure I agree. It seems like the name property is really one of the<br>
>> decl or typedef, not one of the type.<br>
>><br>
>> I'm curious about other opinions, though...<br>
>><br>
>> Cheers,<br>
>> /Manuel<br>
>><br>
>>><br>
>>><br>
>>> Cheers,<br>
>>> Daniel<br>
>>><br>
>>> On Thu, Oct 11, 2012 at 11:47 AM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>><br>
>>> wrote:<br>
>>> > On Thu, Oct 11, 2012 at 11:05 AM, Gábor Horváth <<a href="mailto:xazax.hun@gmail.com" target="_blank">xazax.hun@gmail.com</a>><br>
>>> > wrote:<br>
>>> >> Hi!<br>
>>> >><br>
>>> >> It looks like ...hasType(namedDecl(matchesName("std::set.*iterator")))<br>
>>> >> ...<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<br>
>>> >> 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<br>
>>> >> 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" target="_blank">xazax.hun@gmail.com</a>> wrote:<br>
>>> >>><br>
>>> >>> Hi!<br>
>>> >>><br>
>>> >>> More details on matching template specializations. After further<br>
>>> >>> 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>
>>> >>><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<br>
>>> >>> not match<br>
>>> >>> anything. The same applies to the code I pasted in my mail earlier.<br>
>>> >>> 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" target="_blank">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>
>>> >>>><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<br>
>>> >>>> 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" target="_blank">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<br>
>>> >>>>> 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>
>>> >>>>><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<br>
>>> >>>>> <<a href="mailto:xazax.hun@gmail.com" target="_blank">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<br>
>>> >>>>> > 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>
>>> >>>>> ><br>
>>> >>>>> > classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(hasDeclaration(decl))));<br>
>>> >>>>> >   };<br>
>>> >>>>> ><br>
>>> >>>>> >   // 1, 2, 3 times embedded<br>
>>> >>>>> >   DeclarationMatcher decl =<br>
>>> >>>>> ><br>
>>> >>>>> > anyOf(templateSpecWithArgument(recordDecl(hasName("std::auto_ptr"))),<br>
>>> >>>>> ><br>
>>> >>>>> ><br>
>>> >>>>> ><br>
>>> >>>>> > templateSpecWithArgument(templateSpecWithArgument(recordDecl(hasName("std::auto_ptr")))),<br>
>>> >>>>> ><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<br>
>>> >>>>> > loop<br>
>>> >>>>> > to do<br>
>>> >>>>> > this nesting several times, however I think that could degrade<br>
>>> >>>>> > 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" target="_blank">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>
>><br>
>><br>
><br>
</div></div></blockquote></div><br>