r178487 - Adding parenType() and innerType() AST Matchers

Manuel Klimek klimek at google.com
Tue Apr 2 12:19:15 PDT 2013


On Mon, Apr 1, 2013 at 8:33 PM, Edwin Vane <edwin.vane at intel.com> wrote:

> Author: revane
> Date: Mon Apr  1 13:33:34 2013
> New Revision: 178487
>
> URL: http://llvm.org/viewvc/llvm-project?rev=178487&view=rev
> Log:
> Adding parenType() and innerType() AST Matchers
>
> Updated docs and tests.
>
>
> Modified:
>     cfe/trunk/docs/LibASTMatchersReference.html
>     cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>     cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>
> Modified: cfe/trunk/docs/LibASTMatchersReference.html
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=178487&r1=178486&r2=178487&view=diff
>
> ==============================================================================
> --- cfe/trunk/docs/LibASTMatchersReference.html (original)
> +++ cfe/trunk/docs/LibASTMatchersReference.html Mon Apr  1 13:33:34 2013
> @@ -1000,6 +1000,18 @@ memberPointerType()
>  </pre></td></tr>
>
>
> +<tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td
> class="name" onclick="toggle('parenTypeLoc0')"><a
> name="parenTypeLoc0Anchor">parenTypeLoc</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1ParenTypeLoc.html
> ">ParenTypeLoc</a>>...</td></tr>
> +<tr><td colspan="4" class="doc" id="parenTypeLoc0"><pre>Matches ParenType
> nodes.
> +
> +Given
> +  int (*ptr_to_array)[4];
> +  int *array_of_ptrs[4];
> +
> +varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not
> +array_of_ptrs.
> +</pre></td></tr>
> +
> +
>  <tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td
> class="name" onclick="toggle('pointerTypeLoc0')"><a
> name="pointerTypeLoc0Anchor">pointerTypeLoc</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html
> ">PointerTypeLoc</a>>...</td></tr>
>  <tr><td colspan="4" class="doc" id="pointerTypeLoc0"><pre>Matches pointer
> types.
>
> @@ -1267,6 +1279,18 @@ memberPointerType()
>  </pre></td></tr>
>
>
> +<tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td
> class="name" onclick="toggle('parenType0')"><a
> name="parenType0Anchor">parenType</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1ParenType.html
> ">ParenType</a>>...</td></tr>
> +<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType
> nodes.
> +
> +Given
> +  int (*ptr_to_array)[4];
> +  int *array_of_ptrs[4];
> +
> +varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not
> +array_of_ptrs.
> +</pre></td></tr>
> +
> +
>  <tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td
> class="name" onclick="toggle('pointerType0')"><a
> name="pointerType0Anchor">pointerType</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1PointerType.html
> ">PointerType</a>>...</td></tr>
>  <tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer
> types.
>
> @@ -2991,6 +3015,20 @@ nestedNameSpecifier(specifiesType(hasDec
>  </pre></td></tr>
>
>
> +<tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>></td><td
> class="name" onclick="toggle('innerType0')"><a
> name="innerType0Anchor">innerType</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1Type.html
> ">Type</a>></td></tr>
> +<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType
> nodes where the inner type is a specific type.
> +
> +Given
> +  int (*ptr_to_array)[4];
> +  int (*ptr_to_func)(int);
> +
> +varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches
> +ptr_to_func but not ptr_to_array.
> +
> +Usable as: Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1ParenType.html
> ">ParenType</a>>
> +</pre></td></tr>
> +
> +
>  <tr><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html">PointerTypeLoc</a>></td><td
> class="name" onclick="toggle('pointeeLoc1')"><a
> name="pointeeLoc1Anchor">pointeeLoc</a></td><td>Matcher&lt<a href="
> http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html
> ">TypeLoc</a>></td></tr>
>  <tr><td colspan="4" class="doc" id="pointeeLoc1"><pre>Narrows PointerType
> (and similar) matchers to those where the
>  pointee matches a given matcher.
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=178487&r1=178486&r2=178487&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Apr  1 13:33:34
> 2013
> @@ -2894,6 +2894,32 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType
>  ///   matches "int (*f)(int)" and the type of "g".
>  AST_TYPE_MATCHER(FunctionType, functionType);
>
> +/// \brief Matches \c ParenType nodes.
> +///
> +/// Given
> +/// \code
> +///   int (*ptr_to_array)[4];
> +///   int *array_of_ptrs[4];
> +/// \endcode
> +///
> +/// \c varDecl(hasType(pointsTo(parenType()))) matches \c ptr_to_array
> but not
> +/// \c array_of_ptrs.
> +AST_TYPE_MATCHER(ParenType, parenType);
> +
> +/// \brief Matches \c ParenType nodes where the inner type is a specific
> type.
> +///
> +/// Given
> +/// \code
> +///   int (*ptr_to_array)[4];
> +///   int (*ptr_to_func)(int);
> +/// \endcode
> +///
> +/// \c varDecl(hasType(pointsTo(parenType(innerType(functionType())))))
> matches
> +/// \c ptr_to_func but not \c ptr_to_array.
> +///
> +/// Usable as: Matcher<ParenType>
> +AST_TYPE_TRAVERSE_MATCHER(innerType, getInnerType);
>

Sorry that I missed that in the precommit review, but I think we really
want to call this hasInnerType. For a matcher called innerType I would
expect an AST node InnerType (or CXXInnerType) to exist.

Cheers,
/Manuel


> +
>  /// \brief Matches block pointer types, i.e. types syntactically
> represented as
>  /// "void (^)(int)".
>  ///
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=178487&r1=178486&r2=178487&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Mon Apr  1
> 13:33:34 2013
> @@ -3387,6 +3387,19 @@ TEST(TypeMatching, MatchesFunctionTypes)
>    EXPECT_TRUE(matches("void f(int i) {}", functionType()));
>  }
>
> +TEST(TypeMatching, MatchesParenType) {
> +  EXPECT_TRUE(
> +      matches("int (*array)[4];",
> varDecl(hasType(pointsTo(parenType())))));
> +  EXPECT_TRUE(notMatches("int *array[4];",
> varDecl(hasType(parenType()))));
> +
> +  EXPECT_TRUE(matches(
> +      "int (*ptr_to_func)(int);",
> +      varDecl(hasType(pointsTo(parenType(innerType(functionType())))))));
> +  EXPECT_TRUE(notMatches(
> +      "int (*ptr_to_array)[4];",
> +      varDecl(hasType(pointsTo(parenType(innerType(functionType())))))));
> +}
> +
>  TEST(TypeMatching, PointerTypes) {
>    // FIXME: Reactive when these tests can be more specific (not matching
>    // implicit code on certain platforms), likely when we have
> hasDescendant for
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130402/4bacff43/attachment.html>


More information about the cfe-commits mailing list