]> granicus.if.org Git - clang/commitdiff
Add the ability to AST match a variable declaration that is an exception variable.
authorAaron Ballman <aaron@aaronballman.com>
Wed, 15 Jul 2015 17:11:21 +0000 (17:11 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 15 Jul 2015 17:11:21 +0000 (17:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242303 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a555bb339fc176e67b80969dc287372b75889c64..f4471364f24b9bb7088a1209e29885201e0fded2 100644 (file)
@@ -1754,7 +1754,7 @@ Given
   private:   int c;
   };
 fieldDecl(isPrivate())
-  matches 'int c;' 
+  matches 'int c;'
 </pre></td></tr>
 
 
@@ -1768,7 +1768,7 @@ Given
   private:   int c;
   };
 fieldDecl(isProtected())
-  matches 'int b;' 
+  matches 'int b;'
 </pre></td></tr>
 
 
@@ -1782,7 +1782,7 @@ Given
   private:   int c;
   };
 fieldDecl(isPublic())
-  matches 'int a;' 
+  matches 'int a;'
 </pre></td></tr>
 
 
@@ -2293,6 +2293,18 @@ Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDec
 </pre></td></tr>
 
 
+<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isExceptionVariable1')"><a name="isExceptionVariable1Anchor">isExceptionVariable</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isExceptionVariable1"><pre>Matches if a variable declaration is for a C++ catch handler or Objective-C @catch variable.
+
+Example matches x (matcher = varDecl(isExceptionVariable())
+  void f(int y) {
+    try {
+    } catch (int x) {
+    }
+  }
+</pre></td></tr>
+
+
 <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isExplicitTemplateSpecialization1')"><a name="isExplicitTemplateSpecialization1Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>
 <tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or
 static member variable template instantiations.
index 281d6370e5c8f16a7a2ee901c1a28ae74c7f00fc..4e7625c1c250422a0bbba07cb20e90e327edb660 100644 (file)
@@ -2450,6 +2450,21 @@ AST_MATCHER(VarDecl, hasGlobalStorage) {
   return Node.hasGlobalStorage();
 }
 
+/// \brief Matches a variable declaration that is an exception variable from
+/// a C++ catch block, or an Objective-C \@catch statement.
+///
+/// Example matches x (matcher = varDecl(isExceptionVariable())
+/// \code
+/// void f(int y) {
+///   try {
+///   } catch (int x) {
+///   }
+/// }
+/// \endcode
+AST_MATCHER(VarDecl, isExceptionVariable) {
+  return Node.isExceptionVariable();
+}
+
 /// \brief Checks that a call expression or a constructor call expression has
 /// a specific number of arguments (including absent default arguments).
 ///
index 72713dda03c77666a625e94093eefa065952518e..2af4f0002b268224d4ee071cd508978cafc7f340 100644 (file)
@@ -245,6 +245,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isConstQualified);
   REGISTER_MATCHER(isDefinition);
   REGISTER_MATCHER(isDeleted);
+  REGISTER_MATCHER(isExceptionVariable);
   REGISTER_MATCHER(isExplicitTemplateSpecialization);
   REGISTER_MATCHER(isExpr);
   REGISTER_MATCHER(isExternC);
index 8ef3f15e4c086e166513406030ba971ae07bfb04..54aed8f3fc162d71994b0f707d48199772ca0170 100644 (file)
@@ -3329,6 +3329,10 @@ TEST(ExceptionHandling, SimpleCases) {
                       catchStmt(isCatchAll())));
   EXPECT_TRUE(notMatches("void foo() try { throw; } catch(int) { }",
                          catchStmt(isCatchAll())));
+  EXPECT_TRUE(matches("void foo() try {} catch(int X) { }",
+                      varDecl(isExceptionVariable())));
+  EXPECT_TRUE(notMatches("void foo() try { int X; } catch (...) { }",
+                         varDecl(isExceptionVariable())));
 }
 
 TEST(HasConditionVariableStatement, DoesNotMatchCondition) {