[PATCH] D72233: Add a new AST matcher 'optionally'.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 6 11:22:33 PST 2020
aaron.ballman added a comment.
Just to make sure I understand the purpose -- the goal here is to optionally match one or more inner matchers without failing even if none of the inner matchers match anything, and this is a different use case than `anyOf()` because that would fail when none of the inner matchers match?
================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2538
+/// Usable as: Any Matcher
+extern const internal::VariadicOperatorMatcherFunc<
+ 1, std::numeric_limits<unsigned>::max()>
----------------
This needs to be registered in the dynamic matcher registry (Registry.cpp) as well. Also, you should regenerate the documentation by running `clang\docs\tools\dump_ast_matchers.py`.
I think this matcher could use some example uses in the documentation as well.
================
Comment at: clang/lib/ASTMatchers/ASTMatchersInternal.cpp:362
+ BoundNodesTreeBuilder BuilderInner(*Builder);
+ if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) {
+ Result.addMatch(BuilderInner);
----------------
You can elide the braces here.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72233/new/
https://reviews.llvm.org/D72233
More information about the cfe-commits
mailing list