[clang] [llvm] [clang] Add hasAdjSubstatements matcher (PR #169965)
Yanzuo Liu via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 05:53:40 PST 2025
================
@@ -5911,6 +5911,30 @@ AST_POLYMORPHIC_MATCHER_P(hasAnySubstatement,
Builder) != CS->body_end();
}
+/// Matches compound statements that contain adjacent substatements matching
+/// the provided sequence of matchers. Also matches StmtExprs that have
+/// CompoundStmt as children.
+///
+/// Given
+/// \code
+/// { {}; 1+2; }
+/// \endcode
+/// hasAdjSubstatements(compoundStmt(), binaryOperator())
+/// matches '{ {}; 1+2; }'
+/// with compoundStmt()
+/// matching '{}'
+/// with binaryOperator()
+/// matching '1+2'
+///
+/// hasAdjSubstatements(compoundStmt(), binaryOperator(), returnStmt())
+/// Is equivalent to matching a compound statement that contains
+/// a compound statement immediately followed by a binary operator
+/// immediately followed by a return statement.
+extern const internal::VariadicFunction<
+ internal::HasAdjSubstatementsMatcherType, internal::Matcher<Stmt>,
+ internal::hasAdjSubstatementsFunc>
+ hasAdjSubstatements;
----------------
zwuis wrote:
```cpp
VariadicFunction<
PolymorphicMatcher<
HasAdjSubstatementsMatcher,
AST_POLYMORPHIC_SUPPORTED_TYPES(...),
std::vector<Matcher<Stmt>>>,
Matcher<Stmt>,
hasAdjSubstatementsFunc>
```
Like `hasAnyOperatorName`.
Hope it works. Combining variadic matcher and polymorphic matcher breaks my brain. Sorry for wasting your time.
https://github.com/llvm/llvm-project/pull/169965
More information about the llvm-commits
mailing list