https://github.com/HerrCai0907 requested changes to this pull request.
I try to use it. The matcher for single and multiple is unclear.
It can give more clear matcher results.
```
AST_MATCHER_P(CompoundStmt, hasMultiple, ast_matchers::internal::Matcher<Stmt>,
InnerMatcher) {
size_t Cnt = 0;
for (const Stmt *Stmt : Node.body()) {
if (InnerMatcher.matches(*Stmt, Finder, Builder))
Cnt++;
}
return Cnt > 1;
}
AST_MATCHER_P(CompoundStmt, hasSingle, ast_matchers::internal::Matcher<Stmt>,
InnerMatcher) {
ast_matchers::internal::BoundNodesTreeBuilder Result;
size_t Cnt = 0;
for (const Stmt *Stmt : Node.body()) {
ast_matchers::internal::BoundNodesTreeBuilder TB(*Builder);
if (InnerMatcher.matches(*Stmt, Finder, &TB)) {
Cnt++;
Result.addMatch(TB);
}
}
if (Cnt == 1) {
*Builder = std::move(Result);
return true;
}
Builder->removeBindings([](const ast_matchers::internal::BoundNodesMap &) {
return true; });
return false;
}
```
https://github.com/llvm/llvm-project/pull/126434
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits