From d17094f0fa1e87647b0a018ea629f2b9a83b54b4 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 16 Feb 2015 10:29:51 +0000 Subject: [PATCH] ASTMatchers: Make VariadicOperatorMatcher a real variadic template. llvm-svn: 229370 --- .../clang/ASTMatchers/ASTMatchersInternal.h | 134 ++---------------- 1 file changed, 15 insertions(+), 119 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index 7a722c567920..2b98e9a6c43b 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1144,82 +1144,36 @@ private: /// \brief VariadicOperatorMatcher related types. /// @{ -/// \brief "No argument" placeholder to use as template paratemers. -struct VariadicOperatorNoArg {}; - /// \brief Polymorphic matcher object that uses a \c /// DynTypedMatcher::VariadicOperator operator. /// /// Input matchers can have any type (including other polymorphic matcher /// types), and the actual Matcher is generated on demand with an implicit /// coversion operator. -template -class VariadicOperatorMatcher { +template class VariadicOperatorMatcher { public: - VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, - const P1 &Param1, - const P2 &Param2 = VariadicOperatorNoArg(), - const P3 &Param3 = VariadicOperatorNoArg(), - const P4 &Param4 = VariadicOperatorNoArg(), - const P5 &Param5 = VariadicOperatorNoArg(), - const P6 &Param6 = VariadicOperatorNoArg(), - const P7 &Param7 = VariadicOperatorNoArg(), - const P8 &Param8 = VariadicOperatorNoArg(), - const P9 &Param9 = VariadicOperatorNoArg()) - : Op(Op), Param1(Param1), Param2(Param2), Param3(Param3), - Param4(Param4), Param5(Param5), Param6(Param6), Param7(Param7), - Param8(Param8), Param9(Param9) {} + VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, Ps &&... Params) + : Op(Op), Params(std::forward(Params)...) {} template operator Matcher() const { - std::vector Matchers; - addMatcher(Param1, Matchers); - addMatcher(Param2, Matchers); - addMatcher(Param3, Matchers); - addMatcher(Param4, Matchers); - addMatcher(Param5, Matchers); - addMatcher(Param6, Matchers); - addMatcher(Param7, Matchers); - addMatcher(Param8, Matchers); - addMatcher(Param9, Matchers); - return DynTypedMatcher::constructVariadic(Op, std::move(Matchers)) + return DynTypedMatcher::constructVariadic( + Op, getMatchers(llvm::index_sequence_for())) .template unconditionalConvertTo(); } private: - template - static void addMatcher(const Matcher &M, - std::vector &Matchers) { - Matchers.push_back(M); + // Helper method to unpack the tuple into a vector. + template + std::vector getMatchers(llvm::index_sequence) const { + return {Matcher(std::get(Params))...}; } - /// \brief Overload to ignore \c VariadicOperatorNoArg arguments. - template - static void addMatcher(VariadicOperatorNoArg, - std::vector &Matchers) {} - const DynTypedMatcher::VariadicOperator Op; - const P1 Param1; - const P2 Param2; - const P3 Param3; - const P4 Param4; - const P5 Param5; - const P6 Param6; - const P7 Param7; - const P8 Param8; - const P9 Param9; + std::tuple Params; }; /// \brief Overloaded function object to generate VariadicOperatorMatcher /// objects from arbitrary matchers. -/// -/// It supports 1-9 argument overloaded operator(). More can be added if needed. template struct VariadicOperatorMatcherFunc { DynTypedMatcher::VariadicOperator Op; @@ -1228,69 +1182,11 @@ struct VariadicOperatorMatcherFunc { struct EnableIfValidArity : public std::enable_if {}; - template - typename EnableIfValidArity<1, VariadicOperatorMatcher >::type - operator()(const M1 &P1) const { - return VariadicOperatorMatcher(Op, P1); - } - template - typename EnableIfValidArity<2, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2) const { - return VariadicOperatorMatcher(Op, P1, P2); - } - template - typename EnableIfValidArity<3, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3) const { - return VariadicOperatorMatcher(Op, P1, P2, P3); - } - template - typename EnableIfValidArity<4, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4) const { - return VariadicOperatorMatcher(Op, P1, P2, P3, P4); - } - template - typename EnableIfValidArity< - 5, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, - const M5 &P5) const { - return VariadicOperatorMatcher(Op, P1, P2, P3, P4, P5); - } - template - typename EnableIfValidArity< - 6, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, - const M5 &P5, const M6 &P6) const { - return VariadicOperatorMatcher( - Op, P1, P2, P3, P4, P5, P6); - } - template - typename EnableIfValidArity< - 7, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, - const M5 &P5, const M6 &P6, const M7 &P7) const { - return VariadicOperatorMatcher( - Op, P1, P2, P3, P4, P5, P6, P7); - } - template - typename EnableIfValidArity< - 8, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, - const M5 &P5, const M6 &P6, const M7 &P7, const M8 &P8) const { - return VariadicOperatorMatcher( - Op, P1, P2, P3, P4, P5, P6, P7, P8); - } - template - typename EnableIfValidArity< - 9, VariadicOperatorMatcher >::type - operator()(const M1 &P1, const M2 &P2, const M3 &P3, const M4 &P4, - const M5 &P5, const M6 &P6, const M7 &P7, const M8 &P8, - const M9 &P9) const { - return VariadicOperatorMatcher( - Op, P1, P2, P3, P4, P5, P6, P7, P8, P9); + template + typename EnableIfValidArity>::type + operator()(Ms &&... Ps) const { + return VariadicOperatorMatcher(Op, std::forward(Ps)...); } };