r241256 - Implement an AST matcher for C++ exception catch handlers that can catch any exception type (...).
Aaron Ballman
aaron at aaronballman.com
Thu Jul 2 05:53:23 PDT 2015
Author: aaronballman
Date: Thu Jul 2 07:53:22 2015
New Revision: 241256
URL: http://llvm.org/viewvc/llvm-project?rev=241256&view=rev
Log:
Implement an AST matcher for C++ exception catch handlers that can catch any exception type (...).
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=241256&r1=241255&r2=241256&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Jul 2 07:53:22 2015
@@ -1434,6 +1434,16 @@ Usable as: Matcher<<a href="http://cla
Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>></td><td class="name" onclick="toggle('isCatchAll1')"><a name="isCatchAll1Anchor">isCatchAll</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isCatchAll1"><pre>Matches a C++ catch statement that has a handler that catches any exception type.
+
+Example matches catch(...) (matcher = catchStmt(isCatchAll()))
+ try {
+ // ...
+ } catch(...) {
+ }
+</pre></td></tr>
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountIs1')"><a name="argumentCountIs1Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>
<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=241256&r1=241255&r2=241256&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Jul 2 07:53:22 2015
@@ -2528,6 +2528,23 @@ AST_MATCHER_P2(DeclStmt, containsDeclara
return InnerMatcher.matches(**Iterator, Finder, Builder);
}
+/// \brief Matches a C++ catch statement that has a catch-all handler.
+///
+/// Given
+/// \code
+/// try {
+/// // ...
+/// } catch (int) {
+/// // ...
+/// } catch (...) {
+/// // ...
+/// }
+/// /endcode
+/// catchStmt(isCatchAll()) matches catch(...) but not catch(int).
+AST_MATCHER(CXXCatchStmt, isCatchAll) {
+ return Node.getExceptionDecl() == nullptr;
+}
+
/// \brief Matches a constructor initializer.
///
/// Given
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=241256&r1=241255&r2=241256&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Jul 2 07:53:22 2015
@@ -240,6 +240,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(innerType);
REGISTER_MATCHER(integerLiteral);
REGISTER_MATCHER(isArrow);
+ REGISTER_MATCHER(isCatchAll);
REGISTER_MATCHER(isConst);
REGISTER_MATCHER(isConstQualified);
REGISTER_MATCHER(isDefinition);
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=241256&r1=241255&r2=241256&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Thu Jul 2 07:53:22 2015
@@ -3321,6 +3321,10 @@ TEST(ExceptionHandling, SimpleCases) {
throwExpr()));
EXPECT_TRUE(matches("void foo() try { throw 5;} catch(int X) { }",
throwExpr()));
+ EXPECT_TRUE(matches("void foo() try { throw; } catch(...) { }",
+ catchStmt(isCatchAll())));
+ EXPECT_TRUE(notMatches("void foo() try { throw; } catch(int) { }",
+ catchStmt(isCatchAll())));
}
TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
More information about the cfe-commits
mailing list