[PATCH] D116518: [ast-matchers] Add hasSubstatementSequence matcher
Richard via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 3 11:44:45 PST 2022
LegalizeAdulthood marked an inline comment as done.
LegalizeAdulthood added inline comments.
================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5435-5442
+/// Matches two consecutive statements within a compound statement.
+///
+/// Given
+/// \code
+/// { if (x > 0) return true; return false; }
+/// \endcode
+/// compoundStmt(hasSubstatementSequence(ifStmt(), returnStmt()))
----------------
aaron.ballman wrote:
> How do we extend this to support testing arbitrary sequences of statements? (If this supports two statements, someone will find a need for three, etc).
Yeah, I was wondering that too. I didn't see (but didn't look extensively) any support for variadic matchers taking a parameter pack.
I stopped at 2 because this suits my immediate needs with `readability-simplify-boolean-expr` where I have to manually loop over `CompoundStmt` matches in order to verify that the `if (x) return true; return false;` constructs consist of two adjacent statements.
================
Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:2636
+
+TEST_P(ASTMatchersTest, HasSubstatementSequenceComplex) {
+ const char *Text = R"code(
----------------
aaron.ballman wrote:
> Some more complex-ish tests: can we match within function try or catch blocks and GNU statement expressions?
Adding something for GNU statement expressions is a good idea.
I'm open for other suggestions that might improve coverage.
At the moment, I believe I have 100% coverage of the new matcher, with the exception of GNU statement expressions (honestly, I just copy/pasted that from another matcher on `CompoundStmt`, I wasn't even aware of this GNU extension).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116518/new/
https://reviews.llvm.org/D116518
More information about the cfe-commits
mailing list