From: Arthur Cohen <arthur.co...@embecosm.com>

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  | 10 ++++++++++
 gcc/rust/ast/rust-expr.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 5e724d184de..42be097f056 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -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;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 852c3f3a3a4..cff09fe17d7 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -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; }
 
-- 
2.45.2

Reply via email to