steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
When debugging a matcher it is convenient to be able to comment out
nested matchers experimentally. This stops working when we have less
than two matchers.
Additionally, the removal of the contraint makes it possible to use
these matchers in generic code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94126
Files:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -184,6 +184,10 @@
hasArgument(1, hasType(pointsTo(recordDecl(hasName("T"))))),
hasArgument(2, integerLiteral(equals(3))),
hasArgument(3, integerLiteral(equals(4)))))));
+
+ EXPECT_TRUE(
+ matches("int F() { return 1; }", integerLiteral(allOf(equals(1)))));
+ EXPECT_TRUE(matches("int F() { return 1; }", integerLiteral(allOf())));
}
TEST_P(ASTMatchersTest, Has) {
@@ -463,6 +467,10 @@
EXPECT_TRUE(
matches("void f() try { } catch (int) { } catch (...) { }",
cxxCatchStmt(anyOf(hasDescendant(varDecl()), isCatchAll()))));
+
+ EXPECT_TRUE(
+ matches("int F() { return 1; }", integerLiteral(anyOf(equals(1)))));
+ EXPECT_TRUE(matches("int F() { return 1; }", integerLiteral(anyOf())));
}
TEST_P(ASTMatchersTest, IsDerivedFrom) {
@@ -2451,6 +2459,10 @@
recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
has(fieldDecl(hasName("b")).bind("v")))),
std::make_unique<VerifyIdIsBoundTo<FieldDecl>>("v", 2)));
+
+ EXPECT_TRUE(
+ matches("int F() { return 1; }", integerLiteral(eachOf(equals(1)))));
+ EXPECT_TRUE(matches("int F() { return 1; }", integerLiteral(eachOf())));
}
TEST_P(ASTMatchersTest, EachOf_BehavesLikeAnyOfUnlessBothMatch) {
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -399,6 +399,8 @@
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder,
ArrayRef<DynTypedMatcher> InnerMatchers) {
+ if (InnerMatchers.empty())
+ return true;
BoundNodesTreeBuilder Result;
bool Matched = false;
for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
@@ -416,6 +418,8 @@
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder,
ArrayRef<DynTypedMatcher> InnerMatchers) {
+ if (InnerMatchers.empty())
+ return true;
for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
BoundNodesTreeBuilder Result = *Builder;
if (InnerMatcher.matches(DynNode, Finder, &Result)) {
@@ -952,13 +956,13 @@
const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
designatedInitExpr;
const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
eachOf = {internal::DynTypedMatcher::VO_EachOf};
const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
anyOf = {internal::DynTypedMatcher::VO_AnyOf};
const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
allOf = {internal::DynTypedMatcher::VO_AllOf};
const internal::VariadicOperatorMatcherFunc<1, 1> optionally = {
internal::DynTypedMatcher::VO_Optionally};
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2637,21 +2637,21 @@
///
/// Usable as: Any Matcher
extern const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
eachOf;
/// Matches if any of the given matchers matches.
///
/// Usable as: Any Matcher
extern const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
anyOf;
/// Matches if all given matchers match.
///
/// Usable as: Any Matcher
extern const internal::VariadicOperatorMatcherFunc<
- 2, std::numeric_limits<unsigned>::max()>
+ 0, std::numeric_limits<unsigned>::max()>
allOf;
/// Matches any node regardless of the submatcher.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits