[PATCH] D94876: Remove TypedMatcherOps from VariantValue

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 17 10:07:40 PST 2021


steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94876

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


Index: clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ 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<DynTypedMatcher>
 VariantMatcher::MatcherOps::constructVariadicOperator(
     DynTypedMatcher::VariadicOperator Op,
Index: clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
===================================================================
--- clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ 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<VariantMatcher> InnerMatchers) const;
 
-  protected:
-    ~MatcherOps() = default;
-
   private:
     ASTNodeKind NodeKind;
   };
@@ -174,8 +170,12 @@
   /// 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 @@
   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 @@
   explicit VariantMatcher(std::shared_ptr<Payload> Value)
       : Value(std::move(Value)) {}
 
-  template <typename T> struct TypedMatcherOps;
 
   class SinglePayload;
   class PolymorphicPayload;
@@ -220,17 +224,6 @@
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94876.317225.patch
Type: text/x-patch
Size: 3468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210117/cfd563cc/attachment.bin>


More information about the cfe-commits mailing list