r337703 - [ASTMatchers] add matcher for decltypeType and its underlyingType
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 24 08:05:38 PDT 2018
Let's not forget to regenerate LibASTMatchersReference.html (see
clang/docs/tools/dump_ast_matchers.py).
On Mon, Jul 23, 2018 at 5:59 PM Jonas Toth via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: jonastoth
> Date: Mon Jul 23 08:59:27 2018
> New Revision: 337703
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337703&view=rev
> Log:
> [ASTMatchers] add matcher for decltypeType and its underlyingType
>
> Summary:
> This patch introduces a new matcher for `DecltypeType` and its underlying
> type
> in order to fix a bug in clang-tidy, see https://reviews.llvm.org/D48717
> for more.
>
> Reviewers: aaron.ballman, alexfh, NoQ, dcoughlin
>
> Reviewed By: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D48759
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
> cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=337703&r1=337702&r2=337703&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jul 23 08:59:27
> 2018
> @@ -5111,6 +5111,18 @@ AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasVal
> /// matches "auto n" and "auto i"
> extern const AstTypeMatcher<AutoType> autoType;
>
> +/// Matches types nodes representing C++11 decltype(<expr>) types.
> +///
> +/// Given:
> +/// \code
> +/// short i = 1;
> +/// int j = 42;
> +/// decltype(i + j) result = i + j;
> +/// \endcode
> +/// decltypeType()
> +/// matches "decltype(i + j)"
> +extern const AstTypeMatcher<DecltypeType> decltypeType;
> +
> /// Matches \c AutoType nodes where the deduced type is a specific type.
> ///
> /// Note: There is no \c TypeLoc for the deduced type and thus no
> @@ -5128,6 +5140,20 @@ extern const AstTypeMatcher<AutoType> au
> AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
> AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
>
> +/// Matches \c DecltypeType nodes to find out the underlying type.
> +///
> +/// Given
> +/// \code
> +/// decltype(1) a = 1;
> +/// decltype(2.0) b = 2.0;
> +/// \endcode
> +/// decltypeType(hasUnderlyingType(isInteger()))
> +/// matches "auto a"
> +///
> +/// Usable as: Matcher<DecltypeType>
> +AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
> + AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType));
> +
> /// Matches \c FunctionType nodes.
> ///
> /// Given
>
> Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
> +++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Mon Jul 23 08:59:27
> 2018
> @@ -800,6 +800,7 @@ const AstTypeMatcher<IncompleteArrayType
> const AstTypeMatcher<VariableArrayType> variableArrayType;
> const AstTypeMatcher<AtomicType> atomicType;
> const AstTypeMatcher<AutoType> autoType;
> +const AstTypeMatcher<DecltypeType> decltypeType;
> const AstTypeMatcher<FunctionType> functionType;
> const AstTypeMatcher<FunctionProtoType> functionProtoType;
> const AstTypeMatcher<ParenType> parenType;
>
> Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
> +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Jul 23 08:59:27 2018
> @@ -188,6 +188,7 @@ RegistryMaps::RegistryMaps() {
> REGISTER_MATCHER(decayedType);
> REGISTER_MATCHER(decl);
> REGISTER_MATCHER(declaratorDecl);
> + REGISTER_MATCHER(decltypeType);
> REGISTER_MATCHER(declCountIs);
> REGISTER_MATCHER(declRefExpr);
> REGISTER_MATCHER(declStmt);
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Jul 23
> 08:59:27 2018
> @@ -1206,6 +1206,12 @@ TEST(TypeMatching, MatchesAutoTypes) {
> // autoType(hasDeducedType(isInteger()))));
> }
>
> +TEST(TypeMatching, MatchesDeclTypes) {
> + EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", decltypeType()));
> + EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;",
> + decltypeType(hasUnderlyingType(isInteger()))));
> +}
> +
> TEST(TypeMatching, MatchesFunctionTypes) {
> EXPECT_TRUE(matches("int (*f)(int);", functionType()));
> EXPECT_TRUE(matches("void f(int i) {}", functionType()));
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180724/52153b6e/attachment.html>
More information about the cfe-commits
mailing list