]> granicus.if.org Git - clang/commitdiff
Add an AST node matcher for TemplateTypeParmDecl objects.
authorEric Fiselier <eric@efcs.ca>
Sat, 17 Oct 2015 02:34:44 +0000 (02:34 +0000)
committerEric Fiselier <eric@efcs.ca>
Sat, 17 Oct 2015 02:34:44 +0000 (02:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250602 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LibASTMatchersReference.html
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 10b7339165fd3f8ff517cd41a987022eaa178bdd..1f681e7f9a0a6cb2623c06542e57b77f874ac940 100644 (file)
@@ -321,7 +321,7 @@ namespaceDecl()
 \r
 Given\r
   template &lt;typename T, int N&gt; struct C {};\r
-templateArgument()\r
+nonTypeTemplateParmDecl()\r
   matches 'N', but not 'T'.\r
 </pre></td></tr>\r
 \r
@@ -371,6 +371,16 @@ in
 </pre></td></tr>\r
 \r
 \r
+<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('templateTypeParmDecl0')"><a name="templateTypeParmDecl0Anchor">templateTypeParmDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmDecl.html">TemplateTypeParmDecl</a>&gt;...</td></tr>\r
+<tr><td colspan="4" class="doc" id="templateTypeParmDecl0"><pre>Matches template type parameter declarations.\r
+\r
+Given\r
+  template &lt;typename T, int N&gt; struct C {};\r
+templateTypeParmDecl()\r
+  matches 'T', but not 'N'.\r
+</pre></td></tr>\r
+\r
+\r
 <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('translationUnitDecl0')"><a name="translationUnitDecl0Anchor">translationUnitDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TranslationUnitDecl.html">TranslationUnitDecl</a>&gt;...</td></tr>\r
 <tr><td colspan="4" class="doc" id="translationUnitDecl0"><pre>Matches the top declaration context.\r
 \r
index 3c827cd6592fc4fe3978ca9126a7e65df472ca0c..484cc943ea9ef2792cf30cab8fbb8772fc816e95 100644 (file)
@@ -418,12 +418,24 @@ const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument;
 /// \code
 ///   template <typename T, int N> struct C {};
 /// \endcode
-/// templateArgument()
+/// nonTypeTemplateParmDecl()
 ///   matches 'N', but not 'T'.
 const internal::VariadicDynCastAllOfMatcher<
   Decl,
   NonTypeTemplateParmDecl> nonTypeTemplateParmDecl;
 
+/// \brief Matches template type parameter declarations.
+///
+/// Given
+/// \code
+///   template <typename T, int N> struct C {};
+/// \endcode
+/// templateTypeParmDecl()
+///   matches 'T', but not 'N'.
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  TemplateTypeParmDecl> templateTypeParmDecl;
+
 /// \brief Matches public C++ declarations.
 ///
 /// Given
index 828e71b35ca206cd1d52a35232f7f300b15ac19b..f671cd14cd878c09a4b885639f58336caac68e68 100644 (file)
@@ -1179,6 +1179,13 @@ TEST(Matcher, NonTypeTemplateParmDecl) {
       notMatches("template <typename T> void f();", nonTypeTemplateParmDecl()));
 }
 
+TEST(Matcher, templateTypeParmDecl) {
+  EXPECT_TRUE(matches("template <typename T> void f();",
+                      templateTypeParmDecl(hasName("T"))));
+  EXPECT_TRUE(
+      notMatches("template <int N> void f();", templateTypeParmDecl()));
+}
+
 TEST(Matcher, UserDefinedLiteral) {
   EXPECT_TRUE(matches("constexpr char operator \"\" _inc (const char i) {"
                       "  return i + 1;"