diff --git a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h --- a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h +++ b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h @@ -100,8 +100,7 @@ /// Convert \p Matcher the destination type and return it as a new /// DynTypedMatcher. - virtual DynTypedMatcher - convertMatcher(const DynTypedMatcher &Matcher) const = 0; + DynTypedMatcher convertMatcher(const DynTypedMatcher &Matcher) const; /// Constructs a variadic typed matcher from \p InnerMatchers. /// Will try to convert each inner matcher to the destination type and @@ -110,9 +109,6 @@ constructVariadicOperator(DynTypedMatcher::VariadicOperator Op, ArrayRef InnerMatchers) const; - protected: - ~MatcherOps() = default; - private: ASTNodeKind NodeKind; }; @@ -174,8 +170,12 @@ /// that can, the result would be ambiguous and false is returned. template bool hasTypedMatcher() const { + return hasTypedMatcher(ASTNodeKind::getFromNodeKind()); + } + + bool hasTypedMatcher(ASTNodeKind NK) const { if (!Value) return false; - return Value->getTypedMatcher(TypedMatcherOps()).hasValue(); + return Value->getTypedMatcher(MatcherOps(NK)).hasValue(); } /// Determines if the contained matcher can be converted to \p Kind. @@ -197,10 +197,15 @@ template ast_matchers::internal::Matcher getTypedMatcher() const { assert(hasTypedMatcher() && "hasTypedMatcher() == false"); - return Value->getTypedMatcher(TypedMatcherOps()) + return Value->getTypedMatcher(MatcherOps(ASTNodeKind::getFromNodeKind())) ->template convertTo(); } + DynTypedMatcher getTypedMatcher(ASTNodeKind NK) const { + assert(hasTypedMatcher(NK) && "hasTypedMatcher(NK) == false"); + return *Value->getTypedMatcher(MatcherOps(NK)); + } + /// String representation of the type of the value. /// /// If the underlying matcher is a polymorphic one, the string will show all @@ -211,7 +216,6 @@ explicit VariantMatcher(std::shared_ptr Value) : Value(std::move(Value)) {} - template struct TypedMatcherOps; class SinglePayload; class PolymorphicPayload; @@ -220,17 +224,6 @@ std::shared_ptr Value; }; -template -struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps { - TypedMatcherOps() : MatcherOps(ASTNodeKind::getFromNodeKind()) {} - typedef ast_matchers::internal::Matcher MatcherT; - - DynTypedMatcher - convertMatcher(const DynTypedMatcher &Matcher) const override { - return DynTypedMatcher(Matcher.convertTo()); - } -}; - /// Variant value class. /// /// Basically, a tagged union with value type semantics. diff --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp --- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp +++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp @@ -59,6 +59,11 @@ return Matcher.canConvertTo(NodeKind); } +DynTypedMatcher VariantMatcher::MatcherOps::convertMatcher( + const DynTypedMatcher &Matcher) const { + return Matcher.dynCastTo(NodeKind); +} + llvm::Optional VariantMatcher::MatcherOps::constructVariadicOperator( DynTypedMatcher::VariadicOperator Op,