On Mon, Feb 15, 2016 at 8:05 AM, Aaron Ballman <aa...@aaronballman.com>
wrote:

> On Sun, Feb 14, 2016 at 11:00 PM, Felix Berger via cfe-commits
> <cfe-commits@lists.llvm.org> wrote:
> > Author: flx
> > Date: Sun Feb 14 22:00:39 2016
> > New Revision: 260872
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=260872&view=rev
> > Log:
> > Add isAnyPointer() matchers. Register missing matchers.
> >
> > Summary:
> > The isAnyPointer() matcher is useful for http://reviews.llvm.org/D15623.
> >
> > Reviewers: alexfh, klimek
> >
> > Subscribers: cfe-commits
> >
> > Differential Revision: http://reviews.llvm.org/D15819
> >
> > Modified:
> >     cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> >     cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> >     cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=260872&r1=260871&r2=260872&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sun Feb 14
> 22:00:39 2016
> > @@ -3673,6 +3673,19 @@ AST_MATCHER(QualType, isAnyCharacter) {
> >      return Node->isAnyCharacterType();
> >  }
> >
> > +//// \brief Matches QualType nodes that are of any pointer type.
> > +///
> > +/// Given
> > +/// \code
> > +///   int *i = nullptr;
> > +///   int j;
> > +/// \endcode
> > +/// varDecl(hasType(isAnyPointer()))
> > +///   matches "int *i", but not "int j".
> > +AST_MATCHER(QualType, isAnyPointer) {
> > +  return Node->isAnyPointerType();
> > +}
>
> The whole point to isAnyPointer() is for objective C types, where
> pointers are modeled differently. Can you add documentation, an
> example, and tests for that fact?
>
>
Thanks for making me look into this further. After looking through the
existing test cases and matchers I found there is already a pointerType()
matcher which is the matcher I originally wanted to expose.

I can do one of two things now:

   1. Keep the new isAnyPointer() matcher if we think it's useful and add
   an objc pointer test for it which is already in the works.
   2. Remove the matcher again since there is no real need for it and users
   could get the same by writing anyOf(pointerType(), objcObjectPointerType())

What do you think?


> ~Aaron
>
> > +
> >  /// \brief Matches QualType nodes that are const-qualified, i.e., that
> >  /// include "top-level" const.
> >  ///
> >
> > Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=260872&r1=260871&r2=260872&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
> > +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Sun Feb 14 22:00:39
> 2016
> > @@ -264,6 +264,8 @@ RegistryMaps::RegistryMaps() {
> >    REGISTER_MATCHER(innerType);
> >    REGISTER_MATCHER(integerLiteral);
> >    REGISTER_MATCHER(isAnonymous);
> > +  REGISTER_MATCHER(isAnyCharacter);
> > +  REGISTER_MATCHER(isAnyPointer);
> >    REGISTER_MATCHER(isArrow);
> >    REGISTER_MATCHER(isBaseInitializer);
> >    REGISTER_MATCHER(isCatchAll);
> >
> > Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=260872&r1=260871&r2=260872&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
> > +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Sun Feb 14
> 22:00:39 2016
> > @@ -1479,6 +1479,14 @@ TEST(IsInteger, ReportsNoFalsePositives)
> >                            to(varDecl(hasType(isInteger()))))))));
> >  }
> >
> > +TEST(IsAnyPointer, MatchesPointers) {
> > +  EXPECT_TRUE(matches("int* i = nullptr;",
> varDecl(hasType(isAnyPointer()))));
> > +}
> > +
> > +TEST(IsAnyPointer, ReportsNoFalsePositives) {
> > +  EXPECT_TRUE(notMatches("int i = 0;",
> varDecl(hasType(isAnyPointer()))));
> > +}
> > +
> >  TEST(IsAnyCharacter, MatchesCharacters) {
> >    EXPECT_TRUE(matches("char i = 0;",
> varDecl(hasType(isAnyCharacter()))));
> >  }
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to