From 7f43fcf5d9406788ce95c9f3b785e0a6bc75a7f7 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 12 Feb 2013 13:55:40 +0000 Subject: [PATCH] Adding more overloads for allOf matcher Adding overloads of allOf accepting 4 and 5 arguments. Reviewer: klimek git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174967 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 32 +++++++++++++++++++---- unittests/ASTMatchers/ASTMatchersTest.cpp | 17 +++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index b439717d2a..fe2c14f58b 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -1175,18 +1175,40 @@ anyOf(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, const M5 &P5) { /// \brief Matches if all given matchers match. /// /// Usable as: Any Matcher -template +template internal::PolymorphicMatcherWithParam2 allOf(const M1 &P1, const M2 &P2) { - return internal::PolymorphicMatcherWithParam2(P1, P2); + return internal::PolymorphicMatcherWithParam2( + P1, P2); } -template -internal::PolymorphicMatcherWithParam2 +internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M1, internal::PolymorphicMatcherWithParam2 > allOf(const M1 &P1, const M2 &P2, const M3 &P3) { return allOf(P1, allOf(P2, P3)); } +template +internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M1, + internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M2, internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M3, M4> > > +allOf(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4) { + return allOf(P1, allOf(P2, P3, P4)); +} +template +internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M1, + internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M2, + internal::PolymorphicMatcherWithParam2< + internal::AllOfMatcher, M3, + internal::PolymorphicMatcherWithParam2 > > > +allOf(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, const M5 &P5) { + return allOf(P1, allOf(P2, P3, P4, P5)); +} /// @} diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 618ac6ec51..129f90f2dc 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -351,7 +351,9 @@ TEST(ClassTemplate, DoesNotMatchClassTemplatePartialSpecialization) { TEST(AllOf, AllOverloadsWork) { const char Program[] = - "struct T { }; int f(int, T*); void g(int x) { T t; f(x, &t); }"; + "struct T { };" + "int f(int, T*, int, int);" + "void g(int x) { T t; f(x, &t, 3, 4); }"; EXPECT_TRUE(matches(Program, callExpr(allOf(callee(functionDecl(hasName("f"))), hasArgument(0, declRefExpr(to(varDecl()))))))); @@ -360,6 +362,19 @@ TEST(AllOf, AllOverloadsWork) { hasArgument(0, declRefExpr(to(varDecl()))), hasArgument(1, hasType(pointsTo( recordDecl(hasName("T"))))))))); + EXPECT_TRUE(matches(Program, + callExpr(allOf(callee(functionDecl(hasName("f"))), + hasArgument(0, declRefExpr(to(varDecl()))), + hasArgument(1, hasType(pointsTo( + recordDecl(hasName("T"))))), + hasArgument(2, integerLiteral(equals(3))))))); + EXPECT_TRUE(matches(Program, + callExpr(allOf(callee(functionDecl(hasName("f"))), + hasArgument(0, declRefExpr(to(varDecl()))), + hasArgument(1, hasType(pointsTo( + recordDecl(hasName("T"))))), + hasArgument(2, integerLiteral(equals(3))), + hasArgument(3, integerLiteral(equals(4))))))); } TEST(DeclarationMatcher, MatchAnyOf) { -- 2.40.0