diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index ac8469bded53..e064b28b84f9 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -489,19 +489,6 @@ private: IntrusiveRefCntPtr Implementation; }; -/// Wrapper base class for a wrapping matcher. -/// -/// This is just a container for a DynTypedMatcher that can be used as a base -/// class for another matcher. -template -class WrapperMatcherInterface : public MatcherInterface { -protected: - explicit WrapperMatcherInterface(DynTypedMatcher &&InnerMatcher) - : InnerMatcher(std::move(InnerMatcher)) {} - - const DynTypedMatcher InnerMatcher; -}; - /// Wrapper of a MatcherInterface *that allows copying. /// /// A Matcher can be used anywhere a Matcher is @@ -572,10 +559,12 @@ public: /// does only matches in the absence of qualifiers, or not, i.e. simply /// ignores any qualifiers. template - class TypeToQualType : public WrapperMatcherInterface { + class TypeToQualType : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: TypeToQualType(const Matcher &InnerMatcher) - : TypeToQualType::WrapperMatcherInterface(InnerMatcher) {} + : InnerMatcher(InnerMatcher) {} bool matches(const QualType &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -764,13 +753,15 @@ Matcher hasAnySelectorFunc( /// Type argument DeclMatcherT is required by PolymorphicMatcherWithParam1 but /// not actually used. template -class HasDeclarationMatcher : public WrapperMatcherInterface { +class HasDeclarationMatcher : public MatcherInterface { static_assert(std::is_same>::value, "instantiated with wrong types"); + const DynTypedMatcher InnerMatcher; + public: explicit HasDeclarationMatcher(const Matcher &InnerMatcher) - : HasDeclarationMatcher::WrapperMatcherInterface(InnerMatcher) {} + : InnerMatcher(InnerMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1181,14 +1172,14 @@ struct ArgumentAdaptingMatcherFunc { } }; -template -class TraversalMatcher : public WrapperMatcherInterface { +template class TraversalMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; clang::TraversalKind Traversal; public: - explicit TraversalMatcher(clang::TraversalKind TK, const Matcher &ChildMatcher) - : TraversalMatcher::WrapperMatcherInterface(ChildMatcher), Traversal(TK) { - } + explicit TraversalMatcher(clang::TraversalKind TK, + const Matcher &InnerMatcher) + : InnerMatcher(InnerMatcher), Traversal(TK) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1337,10 +1328,12 @@ public: /// /// ChildT must be an AST base type. template -class HasMatcher : public WrapperMatcherInterface { +class HasMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: - explicit HasMatcher(const Matcher &ChildMatcher) - : HasMatcher::WrapperMatcherInterface(ChildMatcher) {} + explicit HasMatcher(const Matcher &InnerMatcher) + : InnerMatcher(InnerMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1356,16 +1349,18 @@ public: /// As opposed to the HasMatcher, the ForEachMatcher will produce a match /// for each child that matches. template -class ForEachMatcher : public WrapperMatcherInterface { +class ForEachMatcher : public MatcherInterface { static_assert(IsBaseType::value, "for each only accepts base type matcher"); - public: - explicit ForEachMatcher(const Matcher &ChildMatcher) - : ForEachMatcher::WrapperMatcherInterface(ChildMatcher) {} + const DynTypedMatcher InnerMatcher; - bool matches(const T& Node, ASTMatchFinder* Finder, - BoundNodesTreeBuilder* Builder) const override { +public: + explicit ForEachMatcher(const Matcher &InnerMatcher) + : InnerMatcher(InnerMatcher) {} + + bool matches(const T &Node, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const override { return Finder->matchesChildOf( Node, this->InnerMatcher, Builder, TraversalKind::TK_IgnoreImplicitCastsAndParentheses, @@ -1469,17 +1464,19 @@ BindableMatcher makeDynCastAllOfComposite( /// /// DescendantT must be an AST base type. template -class HasDescendantMatcher : public WrapperMatcherInterface { +class HasDescendantMatcher : public MatcherInterface { static_assert(IsBaseType::value, "has descendant only accepts base type matcher"); + const DynTypedMatcher DescendantMatcher; + public: explicit HasDescendantMatcher(const Matcher &DescendantMatcher) - : HasDescendantMatcher::WrapperMatcherInterface(DescendantMatcher) {} + : DescendantMatcher(DescendantMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { - return Finder->matchesDescendantOf(Node, this->InnerMatcher, Builder, + return Finder->matchesDescendantOf(Node, this->DescendantMatcher, Builder, ASTMatchFinder::BK_First); } }; @@ -1489,17 +1486,19 @@ public: /// /// \c ParentT must be an AST base type. template -class HasParentMatcher : public WrapperMatcherInterface { +class HasParentMatcher : public MatcherInterface { static_assert(IsBaseType::value, "has parent only accepts base type matcher"); + const DynTypedMatcher ParentMatcher; + public: explicit HasParentMatcher(const Matcher &ParentMatcher) - : HasParentMatcher::WrapperMatcherInterface(ParentMatcher) {} + : ParentMatcher(ParentMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { - return Finder->matchesAncestorOf(Node, this->InnerMatcher, Builder, + return Finder->matchesAncestorOf(Node, this->ParentMatcher, Builder, ASTMatchFinder::AMM_ParentOnly); } }; @@ -1509,17 +1508,19 @@ public: /// /// \c AncestorT must be an AST base type. template -class HasAncestorMatcher : public WrapperMatcherInterface { +class HasAncestorMatcher : public MatcherInterface { static_assert(IsBaseType::value, "has ancestor only accepts base type matcher"); + const DynTypedMatcher AncestorMatcher; + public: explicit HasAncestorMatcher(const Matcher &AncestorMatcher) - : HasAncestorMatcher::WrapperMatcherInterface(AncestorMatcher) {} + : AncestorMatcher(AncestorMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { - return Finder->matchesAncestorOf(Node, this->InnerMatcher, Builder, + return Finder->matchesAncestorOf(Node, this->AncestorMatcher, Builder, ASTMatchFinder::AMM_All); } }; @@ -1531,18 +1532,20 @@ public: /// As opposed to HasDescendantMatcher, ForEachDescendantMatcher will match /// for each descendant node that matches instead of only for the first. template -class ForEachDescendantMatcher : public WrapperMatcherInterface { +class ForEachDescendantMatcher : public MatcherInterface { static_assert(IsBaseType::value, "for each descendant only accepts base type matcher"); + const DynTypedMatcher DescendantMatcher; + public: explicit ForEachDescendantMatcher( const Matcher &DescendantMatcher) - : ForEachDescendantMatcher::WrapperMatcherInterface(DescendantMatcher) {} + : DescendantMatcher(DescendantMatcher) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { - return Finder->matchesDescendantOf(Node, this->InnerMatcher, Builder, + return Finder->matchesDescendantOf(Node, this->DescendantMatcher, Builder, ASTMatchFinder::BK_All); } }; @@ -1635,10 +1638,12 @@ public: /// Matches nodes of type \c TLoc for which the inner /// \c Matcher matches. template -class LocMatcher : public WrapperMatcherInterface { +class LocMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: explicit LocMatcher(const Matcher &InnerMatcher) - : LocMatcher::WrapperMatcherInterface(InnerMatcher) {} + : InnerMatcher(InnerMatcher) {} bool matches(const TLoc &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1657,10 +1662,12 @@ private: /// \c QualType. /// /// Used to implement the \c loc() matcher. -class TypeLocTypeMatcher : public WrapperMatcherInterface { +class TypeLocTypeMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: explicit TypeLocTypeMatcher(const Matcher &InnerMatcher) - : TypeLocTypeMatcher::WrapperMatcherInterface(InnerMatcher) {} + : InnerMatcher(InnerMatcher) {} bool matches(const TypeLoc &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1674,13 +1681,13 @@ public: /// Matches nodes of type \c T for which the inner matcher matches on a /// another node of type \c T that can be reached using a given traverse /// function. -template -class TypeTraverseMatcher : public WrapperMatcherInterface { +template class TypeTraverseMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: explicit TypeTraverseMatcher(const Matcher &InnerMatcher, QualType (T::*TraverseFunction)() const) - : TypeTraverseMatcher::WrapperMatcherInterface(InnerMatcher), - TraverseFunction(TraverseFunction) {} + : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override { @@ -1699,12 +1706,13 @@ private: /// matcher matches on a another node of type \c T that can be reached using a /// given traverse function. template -class TypeLocTraverseMatcher : public WrapperMatcherInterface { +class TypeLocTraverseMatcher : public MatcherInterface { + const DynTypedMatcher InnerMatcher; + public: explicit TypeLocTraverseMatcher(const Matcher &InnerMatcher, TypeLoc (T::*TraverseFunction)() const) - : TypeLocTraverseMatcher::WrapperMatcherInterface(InnerMatcher), - TraverseFunction(TraverseFunction) {} + : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {} bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const override {