[clang] e12d827 - Make it possible to store NodeKinds in ArgKind

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 7 06:03:41 PST 2021


Author: Stephen Kelly
Date: 2021-02-07T14:00:45Z
New Revision: e12d8279915c323f3727085ccfd0f2c54ad82bdd

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

LOG: Make it possible to store NodeKinds in ArgKind

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 abfb29707924..5b3f8a7ca5eb 100644
--- a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -35,6 +35,7 @@ class ArgKind {
  public:
   enum Kind {
     AK_Matcher,
+    AK_Node,
     AK_Boolean,
     AK_Double,
     AK_Unsigned,
@@ -48,11 +49,19 @@ class ArgKind {
     return ArgKind{AK_Matcher, MatcherKind};
   }
 
+  static ArgKind MakeNodeArg(ASTNodeKind MatcherKind) {
+    return ArgKind{AK_Node, MatcherKind};
+  }
+
   Kind getArgKind() const { return K; }
   ASTNodeKind getMatcherKind() const {
     assert(K == AK_Matcher);
     return NodeKind;
   }
+  ASTNodeKind getNodeKind() const {
+    assert(K == AK_Node);
+    return NodeKind;
+  }
 
   /// Determines if this type can be converted to \p To.
   ///
@@ -63,7 +72,8 @@ class ArgKind {
   bool isConvertibleTo(ArgKind To, unsigned *Specificity) const;
 
   bool operator<(const ArgKind &Other) const {
-    if (K == AK_Matcher && Other.K == AK_Matcher)
+    if ((K == AK_Matcher && Other.K == AK_Matcher) ||
+        (K == AK_Node && Other.K == AK_Node))
       return NodeKind < Other.NodeKind;
     return K < Other.K;
   }

diff  --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
index d367ad0e3233..813eb1597756 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -23,6 +23,8 @@ std::string ArgKind::asString() const {
   switch (getArgKind()) {
   case AK_Matcher:
     return (Twine("Matcher<") + NodeKind.asStringRef() + ">").str();
+  case AK_Node:
+    return NodeKind.asStringRef().str();
   case AK_Boolean:
     return "boolean";
   case AK_Double:
@@ -38,7 +40,7 @@ std::string ArgKind::asString() const {
 bool ArgKind::isConvertibleTo(ArgKind To, unsigned *Specificity) const {
   if (K != To.K)
     return false;
-  if (K != AK_Matcher) {
+  if (K != AK_Matcher && K != AK_Node) {
     if (Specificity)
       *Specificity = 1;
     return true;
@@ -443,6 +445,11 @@ bool VariantValue::isConvertibleTo(ArgKind Kind, unsigned *Specificity) const {
     *Specificity = 1;
     return true;
 
+  case ArgKind::AK_Node:
+    if (!isNodeKind())
+      return false;
+    return getMatcher().isConvertibleTo(Kind.getNodeKind(), Specificity);
+
   case ArgKind::AK_Matcher:
     if (!isMatcher())
       return false;


        


More information about the cfe-commits mailing list