Author: Stephen Kelly Date: 2021-01-19T22:10:09Z New Revision: ecf696641e6ce4b22e8c8ea3c7476b9c1f0f200b
URL: https://github.com/llvm/llvm-project/commit/ecf696641e6ce4b22e8c8ea3c7476b9c1f0f200b DIFF: https://github.com/llvm/llvm-project/commit/ecf696641e6ce4b22e8c8ea3c7476b9c1f0f200b.diff LOG: [ASTMatchers] Allow use of mapAnyOf in more contexts Add an operator overload to ArgumentAdaptingMatcherFunc to allow use of mapAnyOf within hasAncestor, hasParent etc. Differential Revision: https://reviews.llvm.org/D94864 Added: Modified: clang/include/clang/ASTMatchers/ASTMatchersInternal.h clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index aa78a893dcf6b..2af4e6e88109b 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1443,6 +1443,13 @@ struct ArgumentAdaptingMatcherFunc { operator()(const Matcher<T> &InnerMatcher) const { return create(InnerMatcher); } + + template <typename... T> + ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, + typename GetClade<T...>::Type, ToTypes> + operator()(const MapAnyOfHelper<T...> &InnerMatcher) const { + return create(InnerMatcher.with()); + } }; template <typename T> class TraversalMatcher : public MatcherInterface<T> { diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index b3582a02243a2..d681620cf5483 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -491,6 +491,17 @@ void F() { Code, traverse(TK_IgnoreUnlessSpelledInSource, mapAnyOf(ifStmt, forStmt).with(hasCondition(falseExpr))))); + EXPECT_TRUE( + matches(Code, cxxBoolLiteral(equals(true), + hasAncestor(mapAnyOf(ifStmt, forStmt))))); + + EXPECT_TRUE( + matches(Code, cxxBoolLiteral(equals(false), + hasAncestor(mapAnyOf(ifStmt, forStmt))))); + + EXPECT_TRUE( + notMatches(Code, floatLiteral(hasAncestor(mapAnyOf(ifStmt, forStmt))))); + Code = R"cpp( void func(bool b) {} struct S { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits