r242303 - Add the ability to AST match a variable declaration that is an exception variable.
Aaron Ballman
aaron at aaronballman.com
Wed Jul 15 10:11:21 PDT 2015
Author: aaronballman
Date: Wed Jul 15 12:11:21 2015
New Revision: 242303
URL: http://llvm.org/viewvc/llvm-project?rev=242303&view=rev
Log:
Add the ability to AST match a variable declaration that is an exception variable.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=242303&r1=242302&r2=242303&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Jul 15 12:11:21 2015
@@ -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<<a href="http://cla
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></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<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></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.
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=242303&r1=242302&r2=242303&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Jul 15 12:11:21 2015
@@ -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).
///
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=242303&r1=242302&r2=242303&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Wed Jul 15 12:11:21 2015
@@ -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);
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=242303&r1=242302&r2=242303&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Jul 15 12:11:21 2015
@@ -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) {
More information about the cfe-commits
mailing list