[clang] f4dccf1 - [clang] Add a matcher for template template parameters.
Bruno Ricci via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 11 08:01:51 PDT 2020
Author: Bruno Ricci
Date: 2020-08-11T16:01:36+01:00
New Revision: f4dccf115cc198e552b520fda0ee623457015db7
URL: https://github.com/llvm/llvm-project/commit/f4dccf115cc198e552b520fda0ee623457015db7
DIFF: https://github.com/llvm/llvm-project/commit/f4dccf115cc198e552b520fda0ee623457015db7.diff
LOG: [clang] Add a matcher for template template parameters.
There are already matchers for type template parameters and non-type template
parameters, but somehow no matcher exists for template template parameters
and I need it to write unit tests.
Differential Revision: https://reviews.llvm.org/D85536
Reviewed By: aaron.ballman
Added:
Modified:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index e37c68a8f156..f5c4fe63182f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -562,6 +562,18 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl,
extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;
+/// Matches template template parameter declarations.
+///
+/// Given
+/// \code
+/// template <template <typename> class Z, int N> struct C {};
+/// \endcode
+/// templateTypeParmDecl()
+/// matches 'Z', but not 'N'.
+extern const internal::VariadicDynCastAllOfMatcher<Decl,
+ TemplateTemplateParmDecl>
+ templateTemplateParmDecl;
+
/// Matches public C++ declarations and C++ base specifers that specify public
/// inheritance.
///
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 5b9476f3098a..6b17bd0cda0b 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -740,6 +740,9 @@ const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl>
nonTypeTemplateParmDecl;
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;
+const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl>
+ templateTemplateParmDecl;
+
const internal::VariadicAllOfMatcher<QualType> qualType;
const internal::VariadicAllOfMatcher<Type> type;
const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index ec2215804c09..058dab3333de 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -514,6 +514,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(templateArgumentCountIs);
REGISTER_MATCHER(templateName);
REGISTER_MATCHER(templateSpecializationType);
+ REGISTER_MATCHER(templateTemplateParmDecl);
REGISTER_MATCHER(templateTypeParmDecl);
REGISTER_MATCHER(templateTypeParmType);
REGISTER_MATCHER(throughUsingDecl);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 895c8ae48adc..f4e929752ea0 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -408,6 +408,15 @@ TEST_P(ASTMatchersTest, TemplateTypeParmDecl) {
EXPECT_TRUE(notMatches("template <int N> void f();", templateTypeParmDecl()));
}
+TEST_P(ASTMatchersTest, TemplateTemplateParmDecl) {
+ if (!GetParam().isCXX())
+ return;
+ EXPECT_TRUE(matches("template <template <typename> class Z> void f();",
+ templateTemplateParmDecl(hasName("Z"))));
+ EXPECT_TRUE(notMatches("template <typename, int> void f();",
+ templateTemplateParmDecl()));
+}
+
TEST_P(ASTMatchersTest, UserDefinedLiteral) {
if (!GetParam().isCXX11OrLater()) {
return;
More information about the cfe-commits
mailing list