Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -1225,6 +1225,24 @@ +
Matches Objective-C @catch statements. + +Example matches @catch + @try {} + @catch (...) {} +
Matches Objective-C @finally statements. + +Example matches @finally + @try {} + @finally {} +
Matches ObjectiveC Message invocation expressions. @@ -1236,6 +1254,23 @@
Matches Objective-C @try statements. + +Example matches @throw + @throw obj; +
Matches Objective-C @try statements. + +Example matches @try + @try {} + @catch (...) {} +
Matches opaque value expressions. They are used as helpers to reference another expressions and can be met Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -1265,6 +1265,49 @@ Decl, ObjCPropertyDecl> objcPropertyDecl; +/// \brief Matches Objective-C @try statements. +/// +/// Example matches @throw +/// \code +/// @throw obj; +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Stmt, + ObjCAtThrowStmt> objcThrowStmt; + +/// \brief Matches Objective-C @try statements. +/// +/// Example matches @try +/// \code +/// @try {} +/// @catch (...) {} +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Stmt, + ObjCAtTryStmt> objcTryStmt; + +/// \brief Matches Objective-C @catch statements. +/// +/// Example matches @catch +/// \code +/// @try {} +/// @catch (...) {} +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Stmt, + ObjCAtCatchStmt> objcCatchStmt; + +/// \brief Matches Objective-C @finally statements. +/// +/// Example matches @finally +/// \code +/// @try {} +/// @finally {} +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Stmt, + ObjCAtFinallyStmt> objcFinallyStmt; + /// \brief Matches expressions that introduce cleanups to be run at the end /// of the sub-expression's evaluation. /// Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp @@ -388,8 +388,10 @@ REGISTER_MATCHER(nullStmt); REGISTER_MATCHER(numSelectorArgs); REGISTER_MATCHER(ofClass); + REGISTER_MATCHER(objcCatchStmt); REGISTER_MATCHER(objcCategoryDecl); REGISTER_MATCHER(objcCategoryImplDecl); + REGISTER_MATCHER(objcFinallyStmt); REGISTER_MATCHER(objcImplementationDecl); REGISTER_MATCHER(objcInterfaceDecl); REGISTER_MATCHER(objcIvarDecl); @@ -398,6 +400,8 @@ REGISTER_MATCHER(objcObjectPointerType); REGISTER_MATCHER(objcPropertyDecl); REGISTER_MATCHER(objcProtocolDecl); + REGISTER_MATCHER(objcThrowStmt); + REGISTER_MATCHER(objcTryStmt); REGISTER_MATCHER(on); REGISTER_MATCHER(onImplicitObjectArgument); REGISTER_MATCHER(opaqueValueExpr); Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1639,5 +1639,28 @@ objcPropertyDecl(hasName("enabled")))); } +TEST(ObjCStmtMatcher, ExceptionStmts) { + std::string ObjCString = + "void f(id obj) {" + " @try {" + " @throw obj;" + " } @catch (...) {" + " } @finally {}" + "}"; + + EXPECT_TRUE(matchesObjC( + ObjCString, + objcTryStmt())); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcThrowStmt())); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcCatchStmt())); + EXPECT_TRUE(matchesObjC( + ObjCString, + objcFinallyStmt())); +} + } // namespace ast_matchers } // namespace clang