forked from OSchip/llvm-project
Add ObjC exception statement AST matchers
Summary: Add AST matchers for Objective-C @throw, @try, @catch and @finally. Reviewers: aaron.ballman, malcolm.parsons, alexshap, compnerd Reviewed By: aaron.ballman Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39940 llvm-svn: 317992
This commit is contained in:
parent
ac250825c6
commit
0934fdc3a5
|
@ -1225,6 +1225,24 @@ nullStmt()
|
|||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcCatchStmt0')"><a name="objcCatchStmt0Anchor">objcCatchStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ObjCAtCatchStmt.html">ObjCAtCatchStmt</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="objcCatchStmt0"><pre>Matches Objective-C @catch statements.
|
||||
|
||||
Example matches @catch
|
||||
@try {}
|
||||
@catch (...) {}
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcFinallyStmt0')"><a name="objcFinallyStmt0Anchor">objcFinallyStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ObjCAtFinallyStmt.html">ObjCAtFinallyStmt</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="objcFinallyStmt0"><pre>Matches Objective-C @finally statements.
|
||||
|
||||
Example matches @finally
|
||||
@try {}
|
||||
@finally {}
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcMessageExpr0')"><a name="objcMessageExpr0Anchor">objcMessageExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="objcMessageExpr0"><pre>Matches ObjectiveC Message invocation expressions.
|
||||
|
||||
|
@ -1236,6 +1254,23 @@ NSString's "alloc". This matcher should match both message sends.
|
|||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcThrowStmt0')"><a name="objcThrowStmt0Anchor">objcThrowStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ObjCAtThrowStmt.html">ObjCAtThrowStmt</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="objcThrowStmt0"><pre>Matches Objective-C @try statements.
|
||||
|
||||
Example matches @throw
|
||||
@throw obj;
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcTryStmt0')"><a name="objcTryStmt0Anchor">objcTryStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ObjCAtTryStmt.html">ObjCAtTryStmt</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="objcTryStmt0"><pre>Matches Objective-C @try statements.
|
||||
|
||||
Example matches @try
|
||||
@try {}
|
||||
@catch (...) {}
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('opaqueValueExpr0')"><a name="opaqueValueExpr0Anchor">opaqueValueExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers
|
||||
to reference another expressions and can be met
|
||||
|
|
|
@ -1265,6 +1265,49 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
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.
|
||||
///
|
||||
|
|
|
@ -388,8 +388,10 @@ RegistryMaps::RegistryMaps() {
|
|||
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 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(objcObjectPointerType);
|
||||
REGISTER_MATCHER(objcPropertyDecl);
|
||||
REGISTER_MATCHER(objcProtocolDecl);
|
||||
REGISTER_MATCHER(objcThrowStmt);
|
||||
REGISTER_MATCHER(objcTryStmt);
|
||||
REGISTER_MATCHER(on);
|
||||
REGISTER_MATCHER(onImplicitObjectArgument);
|
||||
REGISTER_MATCHER(opaqueValueExpr);
|
||||
|
|
|
@ -1639,5 +1639,28 @@ TEST(ObjCDeclMatcher, CoreDecls) {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue