Skip to content

Commit ecf6966

Browse files
committed
[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
1 parent 3471455 commit ecf6966

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,13 @@ struct ArgumentAdaptingMatcherFunc {
14431443
operator()(const Matcher<T> &InnerMatcher) const {
14441444
return create(InnerMatcher);
14451445
}
1446+
1447+
template <typename... T>
1448+
ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT,
1449+
typename GetClade<T...>::Type, ToTypes>
1450+
operator()(const MapAnyOfHelper<T...> &InnerMatcher) const {
1451+
return create(InnerMatcher.with());
1452+
}
14461453
};
14471454

14481455
template <typename T> class TraversalMatcher : public MatcherInterface<T> {

clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ void F() {
491491
Code, traverse(TK_IgnoreUnlessSpelledInSource,
492492
mapAnyOf(ifStmt, forStmt).with(hasCondition(falseExpr)))));
493493

494+
EXPECT_TRUE(
495+
matches(Code, cxxBoolLiteral(equals(true),
496+
hasAncestor(mapAnyOf(ifStmt, forStmt)))));
497+
498+
EXPECT_TRUE(
499+
matches(Code, cxxBoolLiteral(equals(false),
500+
hasAncestor(mapAnyOf(ifStmt, forStmt)))));
501+
502+
EXPECT_TRUE(
503+
notMatches(Code, floatLiteral(hasAncestor(mapAnyOf(ifStmt, forStmt)))));
504+
494505
Code = R"cpp(
495506
void func(bool b) {}
496507
struct S {

0 commit comments

Comments
 (0)