diff options
author | Eric Liu <ioeric@google.com> | 2017-03-28 12:56:47 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2017-03-28 12:56:47 +0000 |
commit | 54a8f5f00ec601038e1fb67c1f480a75f6a95707 (patch) | |
tree | cb18d61e5512d2d3399f10d166f7efc6c3bf385e | |
parent | 121956bde3695cafabb07a61866ad2432fb31ae9 (diff) |
[ASTMatchers] add typeAliasTemplateDecl matcher.
Reviewers: hokein, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: aaron.ballman, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D28671
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298912 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | docs/LibASTMatchersReference.html | 9 | ||||
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 10 | ||||
-rw-r--r-- | lib/ASTMatchers/Dynamic/Registry.cpp | 1 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 16 |
4 files changed, 36 insertions, 0 deletions
diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index dd29149e63..736e1dfcab 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -469,6 +469,15 @@ typeAliasDecl() </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typeAliasTemplateDecl0')"><a name="typeAliasTemplateDecl0Anchor">typeAliasTemplateDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeAliasTemplateDecl.html">TypeAliasTemplateDecl</a>>...</td></tr> +<tr><td colspan="4" class="doc" id="typeAliasTemplateDecl0"><pre>Matches type alias template declarations. + +typeAliasTemplateDecl() matches + template <typename T> + using Y = X<T>; +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typedefDecl0')"><a name="typedefDecl0Anchor">typedefDecl</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefDecl.html">TypedefDecl</a>>...</td></tr> <tr><td colspan="4" class="doc" id="typedefDecl0"><pre>Matches typedef declarations. diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 1f11c71cf8..7a436956cb 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -180,6 +180,16 @@ const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> /// matches "using Y = int", but not "typedef int X" const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl; +/// \brief Matches type alias template declarations. +/// +/// typeAliasTemplateDecl() matches +/// \code +/// template <typename T> +/// using Y = X<T>; +/// \endcode +const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> + typeAliasTemplateDecl; + /// \brief Matches AST nodes that were expanded within the main-file. /// /// Example matches X but not Y diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index a73f522efc..59070ff458 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/lib/ASTMatchers/Dynamic/Registry.cpp @@ -417,6 +417,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(typedefNameDecl); REGISTER_MATCHER(typedefType); REGISTER_MATCHER(typeAliasDecl); + REGISTER_MATCHER(typeAliasTemplateDecl); REGISTER_MATCHER(typeLoc); REGISTER_MATCHER(unaryExprOrTypeTraitExpr); REGISTER_MATCHER(unaryOperator); diff --git a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp index 4c13acfaf0..5c29334222 100644 --- a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1494,6 +1494,22 @@ TEST(TypedefNameDeclMatcher, Match) { typedefNameDecl(hasName("typedefNameDeclTest2")))); } +TEST(TypeAliasTemplateDeclMatcher, Match) { + std::string Code = R"( + template <typename T> + class X { T t; }; + + template <typename T> + using typeAliasTemplateDecl = X<T>; + + using typeAliasDecl = X<int>; + )"; + EXPECT_TRUE( + matches(Code, typeAliasTemplateDecl(hasName("typeAliasTemplateDecl")))); + EXPECT_TRUE( + notMatches(Code, typeAliasTemplateDecl(hasName("typeAliasDecl")))); +} + TEST(ObjCMessageExprMatcher, SimpleExprs) { // don't find ObjCMessageExpr where none are present EXPECT_TRUE(notMatchesObjC("", objcMessageExpr(anything()))); |