LegalizeAdulthood updated this revision to Diff 396543. LegalizeAdulthood added a comment.
Correct HTML copy/paste error for labelStmt() traversal CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116328/new/ https://reviews.llvm.org/D116328 Files: clang/docs/LibASTMatchersReference.html clang/include/clang/ASTMatchers/ASTMatchers.h clang/lib/ASTMatchers/Dynamic/Registry.cpp clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp =================================================================== --- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -145,6 +145,24 @@ HasDescendantVariableI)); } +TEST_P(ASTMatchersTest, HasCaseSubstmt) { + EXPECT_TRUE(matches( + "void f() { switch (1) { case 1: return; break; default: break; } }", + traverse(TK_AsIs, caseStmt(hasSubstmt(returnStmt()))))); +} + +TEST_P(ASTMatchersTest, HasDefaultSubstmt) { + EXPECT_TRUE(matches( + "void f() { switch (1) { case 1: return; break; default: break; } }", + traverse(TK_AsIs, defaultStmt(hasSubstmt(breakStmt()))))); +} + +TEST_P(ASTMatchersTest, HasLabelSubstmt) { + EXPECT_TRUE(matches( + "void f() { while (1) { bar: break; foo: return; } }", + traverse(TK_AsIs, labelStmt(hasSubstmt(breakStmt()))))); +} + TEST(TypeMatcher, MatchesClassType) { TypeMatcher TypeA = hasDeclaration(recordDecl(hasName("A"))); Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -66,7 +66,7 @@ #define REGISTER_MATCHER(name) \ registerMatcher(#name, internal::makeMatcherAutoMarshall( \ - ::clang::ast_matchers::name, #name)); + ::clang::ast_matchers::name, #name)) #define REGISTER_MATCHER_OVERLOAD(name) \ registerMatcher(#name, \ @@ -143,7 +143,7 @@ REGISTER_MATCHER(atomicType); REGISTER_MATCHER(attr); REGISTER_MATCHER(autoType); - REGISTER_MATCHER(autoreleasePoolStmt) + REGISTER_MATCHER(autoreleasePoolStmt); REGISTER_MATCHER(binaryConditionalOperator); REGISTER_MATCHER(binaryOperator); REGISTER_MATCHER(binaryOperation); @@ -355,6 +355,7 @@ REGISTER_MATCHER(hasSpecializedTemplate); REGISTER_MATCHER(hasStaticStorageDuration); REGISTER_MATCHER(hasStructuredBlock); + REGISTER_MATCHER(hasSubstmt); REGISTER_MATCHER(hasSyntacticForm); REGISTER_MATCHER(hasTargetDecl); REGISTER_MATCHER(hasTemplateArgument); Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -2429,6 +2429,7 @@ /// Matches co_await expressions where the type of the promise is dependent extern const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr> dependentCoawaitExpr; + /// Matches co_yield expressions. /// /// Given @@ -7716,6 +7717,29 @@ return InnerMatcher.matches(*Node.getLHS(), Finder, Builder); } +/// Matches the substatement associated with a case, default or label statement. +/// +/// Given +/// \code +/// switch (1) { case 1: break; case 2: return; break; default: return; break; +/// } +/// foo: return; +/// bar: break; +/// \endcode +/// +/// caseStmt(hasSubstmt(returnStmt())) +/// matches "case 2: return;" +/// defaultStmt(hasSubstmt(returnStmt())) +/// matches "default: return;" +/// labelStmt(hasSubstmt(breakStmt())) +/// matches "bar: break;" +AST_POLYMORPHIC_MATCHER_P(hasSubstmt, + AST_POLYMORPHIC_SUPPORTED_TYPES(CaseStmt, DefaultStmt, + LabelStmt), + internal::Matcher<Stmt>, InnerMatcher) { + return InnerMatcher.matches(*Node.getSubStmt(), Finder, Builder); +} + /// Matches declaration that has a given attribute. /// /// Given Index: clang/docs/LibASTMatchersReference.html =================================================================== --- clang/docs/LibASTMatchersReference.html +++ clang/docs/LibASTMatchersReference.html @@ -7298,6 +7298,16 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>></td><td class="name" onclick="toggle('hasSubstmt0')"><a name="hasSubstmt0Anchor">hasSubstmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="hasSubstmt0"><pre>Matches the substatement associated with a case statement. + +Given + switch (1) { case 1: break; case 2: return; break; default: return; break; } +caseStmt(hasSubstmt(returnStmt())) + matches "case 2: return;" +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>></td><td class="name" onclick="toggle('hasSourceExpression0')"><a name="hasSourceExpression0Anchor">hasSourceExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression or opaque value's source expression matches the given matcher. @@ -7653,6 +7663,16 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DefaultStmt.html">DefaultStmt</a>></td><td class="name" onclick="toggle('hasSubstmt1')"><a name="hasSubstmt1Anchor">hasSubstmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="hasSubstmt1"><pre>Matches the substatement associated with a default statement. + +Given + switch (1) { case 1: break; case 2: return; break; default: return; break; } +defaultStmt(hasSubstmt(returnStmt())) + matches "default: return;" +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>></td><td class="name" onclick="toggle('hasBody0')"><a name="hasBody0Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasBody0"><pre></pre></td></tr> @@ -8359,6 +8379,17 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>></td><td class="name" onclick="toggle('hasSubstmt2')"><a name="hasSubstmt2Anchor">hasSubstmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="hasSubstmt2"><pre>Matches the substatement associated with a label statement. + +Given + foo: return; + bar: break; +labelStmt(hasSubstmt(breakStmt())) + matches "bar: break;" +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>></td><td class="name" onclick="toggle('capturesVar0')"><a name="capturesVar0Anchor">capturesVar</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="capturesVar0"><pre>Matches a `LambdaCapture` that refers to the specified `VarDecl`. The `VarDecl` can be a separate variable that is captured by value or
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits