]> gcc.gnu.org Git - gcc.git/commitdiff
gccrs: Add get_pattern_kind to Pattern
author0xn4utilus <gyanendrabanjare8@gmail.com>
Sun, 25 Feb 2024 00:50:51 +0000 (06:20 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 11:12:15 +0000 (13:12 +0200)
gcc/rust/ChangeLog:

* ast/rust-ast.h: Add Kind Enum to
Pattern.
* ast/rust-macro.h: Add get_pattern_kind().
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.

Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-macro.h
gcc/rust/ast/rust-path.h
gcc/rust/ast/rust-pattern.h

index 92faaf297f9d0af64d3da0f7249973a8a338712d..edf726b1ffec364cde8b5b16d5d32e187142d2f2 100644 (file)
@@ -1360,12 +1360,32 @@ protected:
 class Pattern : public Visitable
 {
 public:
+  enum class Kind
+  {
+    Literal,
+    Identifier,
+    Wildcard,
+    Rest,
+    Range,
+    Reference,
+    Struct,
+    TupleStruct,
+    Tuple,
+    Grouped,
+    Slice,
+    Alt,
+    Path,
+    MacroInvocation,
+  };
+
   // Unique pointer custom clone function
   std::unique_ptr<Pattern> clone_pattern () const
   {
     return std::unique_ptr<Pattern> (clone_pattern_impl ());
   }
 
+  virtual Kind get_pattern_kind () = 0;
+
   // possible virtual methods: is_refutable()
 
   virtual ~Pattern () {}
index bfdebfc42032cd9fbc08bdb0220e00538ac1f87e..5b9ff3f22c88d2bde5edb6f9cb131d7704e85e1a 100644 (file)
@@ -610,6 +610,11 @@ public:
 
   std::string as_string () const override;
 
+  Pattern::Kind get_pattern_kind () override
+  {
+    return Pattern::Kind::MacroInvocation;
+  }
+
   /**
    * The default constructor you should use. Whenever we parse a macro call, we
    * cannot possibly know whether or not this call refers to a builtin macro or
index ccac6303bb4b3f9196f0947b98b3882064f314aa..bd3012b1bed3b562dd68c03702546b1a9ffc4d6e 100644 (file)
@@ -578,6 +578,8 @@ public:
   // TODO: this seems kinda dodgy
   std::vector<PathExprSegment> &get_segments () { return segments; }
   const std::vector<PathExprSegment> &get_segments () const { return segments; }
+
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
 };
 
 /* AST node representing a path-in-expression pattern (path that allows
index 96f09355fae0a91d6cc1b958c95532d32e656ad8..365f3b7f69d22b14a359cead3319a76f010fe163 100644 (file)
@@ -55,6 +55,8 @@ public:
 
   const Literal &get_literal () const { return lit; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Literal; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -149,6 +151,11 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override
+  {
+    return Pattern::Kind::Identifier;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -177,6 +184,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Wildcard; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -204,6 +213,8 @@ public:
 
   NodeId get_node_id () const override final { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Rest; }
+
 protected:
   RestPattern *clone_pattern_impl () const override
   {
@@ -431,6 +442,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Range; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -499,6 +512,11 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override
+  {
+    return Pattern::Kind::Reference;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -934,6 +952,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Struct; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1174,6 +1194,11 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override
+  {
+    return Pattern::Kind::TupleStruct;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1411,6 +1436,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Tuple; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1471,6 +1498,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Grouped; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1535,6 +1564,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Slice; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1600,6 +1631,8 @@ public:
 
   NodeId get_node_id () const override { return node_id; }
 
+  Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Alt; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
This page took 0.064407 seconds and 5 git commands to generate.