r174967 - Adding more overloads for allOf matcher
David Blaikie
dblaikie at gmail.com
Tue Feb 12 10:09:04 PST 2013
On Tue, Feb 12, 2013 at 5:55 AM, Edwin Vane <edwin.vane at intel.com> wrote:
> Author: revane
> Date: Tue Feb 12 07:55:40 2013
> New Revision: 174967
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174967&view=rev
> Log:
> Adding more overloads for allOf matcher
>
> Adding overloads of allOf accepting 4 and 5 arguments.
Worth just adding an CXX11-conditional variadic template form?
>
> Reviewer: klimek
>
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=174967&r1=174966&r2=174967&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Feb 12 07:55:40 2013
> @@ -1175,18 +1175,40 @@ anyOf(const M1 &P1, const M2 &P2, const
> /// \brief Matches if all given matchers match.
> ///
> /// Usable as: Any Matcher
> -template<typename M1, typename M2>
> +template <typename M1, typename M2>
> internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher, M1, M2>
> allOf(const M1 &P1, const M2 &P2) {
> - return internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher,
> - M1, M2>(P1, P2);
> + return internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher, M1, M2>(
> + P1, P2);
> }
> -template<typename M1, typename M2, typename M3>
> -internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher, M1,
> +template <typename M1, typename M2, typename M3>
> +internal::PolymorphicMatcherWithParam2<
> + internal::AllOfMatcher, M1,
> internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher, M2, M3> >
> allOf(const M1 &P1, const M2 &P2, const M3 &P3) {
> return allOf(P1, allOf(P2, P3));
> }
> +template <typename M1, typename M2, typename M3, typename M4>
> +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 <typename M1, typename M2, typename M3, typename M4, typename M5>
> +internal::PolymorphicMatcherWithParam2<
> + internal::AllOfMatcher, M1,
> + internal::PolymorphicMatcherWithParam2<
> + internal::AllOfMatcher, M2,
> + internal::PolymorphicMatcherWithParam2<
> + internal::AllOfMatcher, M3,
> + internal::PolymorphicMatcherWithParam2<internal::AllOfMatcher, M4,
> + M5> > > >
> +allOf(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, const M5 &P5) {
> + return allOf(P1, allOf(P2, P3, P4, P5));
> +}
>
> /// @}
>
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=174967&r1=174966&r2=174967&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Feb 12 07:55:40 2013
> @@ -351,7 +351,9 @@ TEST(ClassTemplate, DoesNotMatchClassTem
>
> 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) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list