]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Add new Expr::Kinds
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 23 Jan 2025 11:43:31 +0000 (11:43 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:06:58 +0000 (13:06 +0100)
Collapses all of the OperatorExprs into Expr instead of first having to check for OperatorExpr and
then check for each OperatorExpr::Kind.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add new Expr::Kinds.
* ast/rust-expr.h: Implement missing get_expr_kind(), Add get_function_expr_ptr()

gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-expr.h

index 5e724d184de597133eb4d82b2bdad9a5bea1cada..42be097f0567a34cb7156e60189edbd8b06748a9 100644 (file)
@@ -1263,6 +1263,16 @@ public:
     Identifier,
     FormatArgs,
     MacroInvocation,
+    Borrow,
+    Dereference,
+    ErrorPropagation,
+    Negation,
+    ArithmeticOrLogical,
+    Comparison,
+    LazyBoolean,
+    TypeCast,
+    Assignment,
+    CompoundAssignment,
   };
 
   virtual Kind get_expr_kind () const = 0;
index 852c3f3a3a4541093114908d71b01771304d5f3e..cff09fe17d7b73fe387100c1b27e5504d271c1a4 100644 (file)
@@ -407,6 +407,8 @@ public:
   bool get_is_double_borrow () const { return double_borrow; }
   bool is_raw_borrow () const { return raw_borrow; }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::Borrow; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -437,6 +439,8 @@ public:
     return *main_or_left_expr;
   }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::Dereference; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -468,6 +472,11 @@ public:
     return *main_or_left_expr;
   }
 
+  Expr::Kind get_expr_kind () const override
+  {
+    return Expr::Kind::ErrorPropagation;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -511,6 +520,8 @@ public:
     return *main_or_left_expr;
   }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::Negation; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -599,6 +610,11 @@ public:
   void visit_lhs (ASTVisitor &vis) { main_or_left_expr->accept_vis (vis); }
   void visit_rhs (ASTVisitor &vis) { right_expr->accept_vis (vis); }
 
+  Expr::Kind get_expr_kind () const override
+  {
+    return Expr::Kind::ArithmeticOrLogical;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -686,6 +702,8 @@ public:
 
   ExprType get_kind () { return expr_type; }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::Comparison; }
+
   /* TODO: implement via a function call to std::cmp::PartialEq::eq(&op1, &op2)
    * maybe? */
 protected:
@@ -774,6 +792,8 @@ public:
 
   ExprType get_kind () { return expr_type; }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::LazyBoolean; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -836,6 +856,8 @@ public:
     return *type_to_convert_to;
   }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::TypeCast; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -914,6 +936,8 @@ public:
     return *right_expr;
   }
 
+  Expr::Kind get_expr_kind () const override { return Expr::Kind::Assignment; }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -1000,6 +1024,11 @@ public:
     return right_expr;
   }
 
+  Expr::Kind get_expr_kind () const override
+  {
+    return Expr::Kind::CompoundAssignment;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -2139,6 +2168,8 @@ public:
     return *function;
   }
 
+  std::unique_ptr<Expr> &get_function_expr_ptr () { return function; }
+
   const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
   std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }