Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1121,36 +1121,11 @@ /// \brief VariadicOperatorMatcher related types. /// @{ -/// \brief Function signature for any variadic operator. It takes the inner -/// matchers as an array of DynTypedMatcher. -typedef bool (*VariadicOperatorFunction)( - const ast_type_traits::DynTypedNode DynNode, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder, ArrayRef InnerMatchers); - -/// \brief \c MatcherInterface implementation for an variadic operator. -template -class VariadicOperatorMatcherInterface : public MatcherInterface { -public: - VariadicOperatorMatcherInterface(VariadicOperatorFunction Func, - std::vector InnerMatchers) - : Func(Func), InnerMatchers(std::move(InnerMatchers)) {} - - bool matches(const T &Node, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const override { - return Func(ast_type_traits::DynTypedNode::create(Node), Finder, Builder, - InnerMatchers); - } - -private: - const VariadicOperatorFunction Func; - const std::vector InnerMatchers; -}; - /// \brief "No argument" placeholder to use as template paratemers. struct VariadicOperatorNoArg {}; -/// \brief Polymorphic matcher object that uses a \c VariadicOperatorFunction -/// operator. +/// \brief Polymorphic matcher object that uses a \c +/// DynTypedMatcher::VariadicOperatorFunction operator. /// /// Input matchers can have any type (including other polymorphic matcher /// types), and the actual Matcher is generated on demand with an implicit @@ -1165,7 +1140,8 @@ typename P9 = VariadicOperatorNoArg> class VariadicOperatorMatcher { public: - VariadicOperatorMatcher(VariadicOperatorFunction Func, const P1 &Param1, + VariadicOperatorMatcher(DynTypedMatcher::VariadicOperatorFunction Func, + const P1 &Param1, const P2 &Param2 = VariadicOperatorNoArg(), const P3 &Param3 = VariadicOperatorNoArg(), const P4 &Param4 = VariadicOperatorNoArg(), @@ -1189,9 +1165,8 @@ addMatcher(Param7, Matchers); addMatcher(Param8, Matchers); addMatcher(Param9, Matchers); - // FIXME: Use DynTypedMatcher::constructVariadic() instead. - return Matcher( - new VariadicOperatorMatcherInterface(Func, std::move(Matchers))); + return DynTypedMatcher::constructVariadic(Func, std::move(Matchers)) + .template unconditionalConvertTo(); } private: @@ -1206,7 +1181,7 @@ static void addMatcher(VariadicOperatorNoArg, std::vector &Matchers) {} - const VariadicOperatorFunction Func; + const DynTypedMatcher::VariadicOperatorFunction Func; const P1 Param1; const P2 Param2; const P3 Param3; @@ -1224,7 +1199,7 @@ /// It supports 1-9 argument overloaded operator(). More can be added if needed. template struct VariadicOperatorMatcherFunc { - VariadicOperatorFunction Func; + DynTypedMatcher::VariadicOperatorFunction Func; template struct EnableIfValidArity @@ -1350,9 +1325,9 @@ for (const auto *InnerMatcher : InnerMatchers) { DynMatchers.push_back(*InnerMatcher); } - // FIXME: Use DynTypedMatcher::constructVariadic() instead. - return BindableMatcher(new VariadicOperatorMatcherInterface( - AllOfVariadicOperator, std::move(DynMatchers))); + return BindableMatcher(DynTypedMatcher::constructVariadic( + AllOfVariadicOperator, std::move(DynMatchers)) + .template unconditionalConvertTo()); } /// \brief Creates a Matcher that matches if Index: include/clang/ASTMatchers/Dynamic/VariantValue.h =================================================================== --- include/clang/ASTMatchers/Dynamic/VariantValue.h +++ include/clang/ASTMatchers/Dynamic/VariantValue.h @@ -106,9 +106,9 @@ /// \brief Constructs a variadic typed matcher from \p InnerMatchers. /// Will try to convert each inner matcher to the destination type and /// return llvm::None if it fails to do so. - llvm::Optional constructVariadicOperator( - ast_matchers::internal::VariadicOperatorFunction Func, - ArrayRef InnerMatchers) const; + llvm::Optional + constructVariadicOperator(DynTypedMatcher::VariadicOperatorFunction Func, + ArrayRef InnerMatchers) const; protected: ~MatcherOps() {} @@ -147,9 +147,9 @@ /// \brief Creates a 'variadic' operator matcher. /// /// It will bind to the appropriate type on getTypedMatcher(). - static VariantMatcher VariadicOperatorMatcher( - ast_matchers::internal::VariadicOperatorFunction Func, - std::vector Args); + static VariantMatcher + VariadicOperatorMatcher(DynTypedMatcher::VariadicOperatorFunction Func, + std::vector Args); /// \brief Makes the matcher the "null" matcher. void reset(); Index: lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- lib/ASTMatchers/ASTMatchersInternal.cpp +++ lib/ASTMatchers/ASTMatchersInternal.cpp @@ -32,7 +32,7 @@ class VariadicMatcher : public DynMatcherInterface { public: - VariadicMatcher(VariadicOperatorFunction Func, + VariadicMatcher(DynTypedMatcher::VariadicOperatorFunction Func, std::vector InnerMatchers) : Func(Func), InnerMatchers(std::move(InnerMatchers)) {} @@ -43,7 +43,7 @@ } private: - VariadicOperatorFunction Func; + DynTypedMatcher::VariadicOperatorFunction Func; std::vector InnerMatchers; }; @@ -86,7 +86,8 @@ } // namespace DynTypedMatcher DynTypedMatcher::constructVariadic( - VariadicOperatorFunction Func, std::vector InnerMatchers) { + DynTypedMatcher::VariadicOperatorFunction Func, + std::vector InnerMatchers) { assert(InnerMatchers.size() > 0 && "Array must not be empty."); assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(), [&InnerMatchers](const DynTypedMatcher &M) { Index: lib/ASTMatchers/Dynamic/Marshallers.h =================================================================== --- lib/ASTMatchers/Dynamic/Marshallers.h +++ lib/ASTMatchers/Dynamic/Marshallers.h @@ -556,7 +556,7 @@ /// \brief Variadic operator marshaller function. class VariadicOperatorMatcherDescriptor : public MatcherDescriptor { public: - typedef ast_matchers::internal::VariadicOperatorFunction VarFunc; + typedef DynTypedMatcher::VariadicOperatorFunction VarFunc; VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount, VarFunc Func, StringRef MatcherName) : MinCount(MinCount), MaxCount(MaxCount), Func(Func), Index: lib/ASTMatchers/Dynamic/VariantValue.cpp =================================================================== --- lib/ASTMatchers/Dynamic/VariantValue.cpp +++ lib/ASTMatchers/Dynamic/VariantValue.cpp @@ -58,7 +58,7 @@ llvm::Optional VariantMatcher::MatcherOps::constructVariadicOperator( - ast_matchers::internal::VariadicOperatorFunction Func, + DynTypedMatcher::VariadicOperatorFunction Func, ArrayRef InnerMatchers) const { std::vector DynMatchers; for (const auto &InnerMatcher : InnerMatchers) { @@ -176,7 +176,7 @@ class VariantMatcher::VariadicOpPayload : public VariantMatcher::Payload { public: - VariadicOpPayload(ast_matchers::internal::VariadicOperatorFunction Func, + VariadicOpPayload(DynTypedMatcher::VariadicOperatorFunction Func, std::vector Args) : Func(Func), Args(std::move(Args)) {} @@ -209,7 +209,7 @@ } private: - const ast_matchers::internal::VariadicOperatorFunction Func; + const DynTypedMatcher::VariadicOperatorFunction Func; const std::vector Args; }; @@ -225,7 +225,7 @@ } VariantMatcher VariantMatcher::VariadicOperatorMatcher( - ast_matchers::internal::VariadicOperatorFunction Func, + DynTypedMatcher::VariadicOperatorFunction Func, std::vector Args) { return VariantMatcher(new VariadicOpPayload(Func, std::move(Args))); }