[clang] 8d112a8 - Remove TypedMatcherOps from VariantValue

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 19 14:40:12 PST 2021


Author: Stephen Kelly
Date: 2021-01-19T22:39:58Z
New Revision: 8d112a8eda9d78bc4c97cf7bc9e133afae7b6eed

URL: https://github.com/llvm/llvm-project/commit/8d112a8eda9d78bc4c97cf7bc9e133afae7b6eed
DIFF: https://github.com/llvm/llvm-project/commit/8d112a8eda9d78bc4c97cf7bc9e133afae7b6eed.diff

LOG: Remove TypedMatcherOps from VariantValue

It provides no features or advantage over ASTNodeKind-based handling.

Differential Revision: https://reviews.llvm.org/D94876

Added: 
    

Modified: 
    clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
    clang/lib/ASTMatchers/Dynamic/VariantValue.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
index e47b42a4f38c..140b41dffc40 100644
--- a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -100,8 +100,7 @@ class VariantMatcher {
 
     /// 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 @@ class VariantMatcher {
     constructVariadicOperator(DynTypedMatcher::VariadicOperator Op,
                               ArrayRef<VariantMatcher> InnerMatchers) const;
 
-  protected:
-    ~MatcherOps() = default;
-
   private:
     ASTNodeKind NodeKind;
   };
@@ -174,8 +170,12 @@ class VariantMatcher {
   /// that can, the result would be ambiguous and false is returned.
   template <class T>
   bool hasTypedMatcher() const {
+    return hasTypedMatcher(ASTNodeKind::getFromNodeKind<T>());
+  }
+
+  bool hasTypedMatcher(ASTNodeKind NK) const {
     if (!Value) return false;
-    return Value->getTypedMatcher(TypedMatcherOps<T>()).hasValue();
+    return Value->getTypedMatcher(MatcherOps(NK)).hasValue();
   }
 
   /// Determines if the contained matcher can be converted to \p Kind.
@@ -197,10 +197,15 @@ class VariantMatcher {
   template <class T>
   ast_matchers::internal::Matcher<T> getTypedMatcher() const {
     assert(hasTypedMatcher<T>() && "hasTypedMatcher<T>() == false");
-    return Value->getTypedMatcher(TypedMatcherOps<T>())
+    return Value->getTypedMatcher(MatcherOps(ASTNodeKind::getFromNodeKind<T>()))
         ->template convertTo<T>();
   }
 
+  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 @@ class VariantMatcher {
   explicit VariantMatcher(std::shared_ptr<Payload> Value)
       : Value(std::move(Value)) {}
 
-  template <typename T> struct TypedMatcherOps;
 
   class SinglePayload;
   class PolymorphicPayload;
@@ -220,17 +224,6 @@ class VariantMatcher {
   std::shared_ptr<const Payload> Value;
 };
 
-template <typename T>
-struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
-  TypedMatcherOps() : MatcherOps(ASTNodeKind::getFromNodeKind<T>()) {}
-  typedef ast_matchers::internal::Matcher<T> MatcherT;
-
-  DynTypedMatcher
-  convertMatcher(const DynTypedMatcher &Matcher) const override {
-    return DynTypedMatcher(Matcher.convertTo<T>());
-  }
-};
-
 /// 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
index 866e2d0e3491..f31dda82a932 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -59,6 +59,11 @@ VariantMatcher::MatcherOps::canConstructFrom(const DynTypedMatcher &Matcher,
   return Matcher.canConvertTo(NodeKind);
 }
 
+DynTypedMatcher VariantMatcher::MatcherOps::convertMatcher(
+    const DynTypedMatcher &Matcher) const {
+  return Matcher.dynCastTo(NodeKind);
+}
+
 llvm::Optional<DynTypedMatcher>
 VariantMatcher::MatcherOps::constructVariadicOperator(
     DynTypedMatcher::VariadicOperator Op,


        


More information about the cfe-commits mailing list