From 7156ffff6de12d8a14b0597f1ca5053115cf5773 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Tue, 3 Sep 2013 13:21:01 +0000 Subject: [PATCH] Remove DynCastMatcher, since it is pretty much the same as Matcher::WrappedMatcher. Summary: Remove DynCastMatcher, since it is pretty much the same as Matcher::WrappedMatcher. This reduces the number of template instantiations and number of symbols in the object file. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1560 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189800 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/ASTMatchers/ASTMatchersInternal.h | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 301aa32616..26ebc97c7d 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -285,6 +285,14 @@ public: /// compatible with T. static Matcher constructFrom(const DynTypedMatcher &Other) { assert(canConstructFrom(Other)); + return constructFromUnsafe(Other); + } + + /// \brief Same as constructFrom(), but does not check that the underlying + /// matcher can handle a value of T. + /// + /// If it is not compatible, then this matcher will never match anything. + static Matcher constructFromUnsafe(const DynTypedMatcher &Other) { return Matcher(new WrappedMatcher(Other)); } @@ -922,27 +930,6 @@ public: } }; -/// \brief Provides a MatcherInterface for a Matcher that matches if T is -/// dyn_cast'able into To and the given Matcher matches on the dyn_cast'ed -/// node. -template -class DynCastMatcher : public MatcherInterface { -public: - explicit DynCastMatcher(const Matcher &InnerMatcher) - : InnerMatcher(InnerMatcher) {} - - virtual bool matches(const T &Node, - ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) const { - const To *InnerMatchValue = dyn_cast(&Node); - return InnerMatchValue != NULL && - InnerMatcher.matches(*InnerMatchValue, Finder, Builder); - } - -private: - const Matcher InnerMatcher; -}; - /// \brief Matcher that wraps an inner Matcher and binds the matched node /// to an ID if the inner matcher matches on the node. template @@ -975,7 +962,8 @@ private: template class BindableMatcher : public Matcher { public: - BindableMatcher(MatcherInterface *Implementation) + explicit BindableMatcher(const Matcher &M) : Matcher(M) {} + explicit BindableMatcher(MatcherInterface *Implementation) : Matcher(Implementation) {} /// \brief Returns a matcher that will bind the matched node on a match. @@ -1244,8 +1232,8 @@ BindableMatcher makeAllOfComposite( template BindableMatcher makeDynCastAllOfComposite( ArrayRef *> InnerMatchers) { - return BindableMatcher(new DynCastMatcher( - makeAllOfComposite(InnerMatchers))); + return BindableMatcher( + Matcher::constructFromUnsafe(makeAllOfComposite(InnerMatchers))); } /// \brief Matches nodes of type T that have at least one descendant node of -- 2.40.0