forked from OSchip/llvm-project
[clang] Add AST matcher for block expressions 🔍
Summary: This change adds a new AST matcher for block expressions. Test Notes: Ran the clang unit tests. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55546 llvm-svn: 349004
This commit is contained in:
parent
6071e1aa58
commit
3897b2dca1
|
@ -707,6 +707,14 @@ Example matches a || b
|
|||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('blockExpr0')"><a name="blockExpr0Anchor">blockExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockExpr.html">BlockExpr</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="blockExpr0"><pre>MAtches a reference to a block.
|
||||
|
||||
Example: matches "^{}":
|
||||
void f() { ^{}(); }
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('breakStmt0')"><a name="breakStmt0Anchor">breakStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html">BreakStmt</a>>...</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements.
|
||||
|
||||
|
|
|
@ -1798,6 +1798,14 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr>
|
|||
extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr>
|
||||
objcIvarRefExpr;
|
||||
|
||||
/// Matches a reference to a block.
|
||||
///
|
||||
/// Example: matches "^{}":
|
||||
/// \code
|
||||
/// void f() { ^{}(); }
|
||||
/// \endcode
|
||||
extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
|
||||
|
||||
/// Matches if statements.
|
||||
///
|
||||
/// Example matches 'if (x) {}'
|
||||
|
|
|
@ -688,6 +688,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
|
|||
const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt;
|
||||
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
|
||||
|
|
|
@ -139,6 +139,7 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(binaryConditionalOperator);
|
||||
REGISTER_MATCHER(binaryOperator);
|
||||
REGISTER_MATCHER(blockDecl);
|
||||
REGISTER_MATCHER(blockExpr);
|
||||
REGISTER_MATCHER(blockPointerType);
|
||||
REGISTER_MATCHER(booleanType);
|
||||
REGISTER_MATCHER(breakStmt);
|
||||
|
|
|
@ -1386,6 +1386,10 @@ TEST(ObjCIvarRefExprMatcher, IvarExpr) {
|
|||
hasDeclaration(namedDecl(hasName("y"))))));
|
||||
}
|
||||
|
||||
TEST(BlockExprMatcher, BlockExpr) {
|
||||
EXPECT_TRUE(matchesObjC("void f() { ^{}(); }", blockExpr()));
|
||||
}
|
||||
|
||||
TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) {
|
||||
EXPECT_TRUE(matches("void f() { }",
|
||||
compoundStmt(statementCountIs(0))));
|
||||
|
|
Loading…
Reference in New Issue