]> gcc.gnu.org Git - gcc.git/commitdiff
gccrs: Move functionality into HIR::ExprStmt from deriving classes
authorOwen Avery <powerboat9.gamer@gmail.com>
Sun, 5 Feb 2023 01:15:52 +0000 (20:15 -0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:46 +0000 (18:28 +0100)
And move method as_string into HIR::ExprStmt from deriving classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h
(ExprStmt::expr): Add field.
(ExprStmt::get_expr): Add method.
(ExprStmt::ExprStmt): Add copy/move constructors, modify existing constructor.
(ExprStmt::operator=): Add assignment operator.
(ExprStmtWithoutBlock::expr): Remove field.
(ExprStmtWithoutBlock::get_expr): Remove method.
(ExprStmtWithoutBlock::ExprStmt):
Remove copy/move constructors, modify existing constructor.
(ExprStmtWithoutBlock::operator=): Remove assignment operator.
(ExprStmtWithBlock::expr): Remove field.
(ExprStmtWithBlock::get_expr): Remove method.
(ExprStmtWithBlock::ExprStmt): Remove copy/move constructors, modify existing constructor.
(ExprStmtWithBlock::operator=): Remove assignment operator.
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.
* hir/tree/rust-hir.cc
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/hir/tree/rust-hir-stmt.h
gcc/rust/hir/tree/rust-hir.cc

index 2600a1c1223a7fa26929d639fc742a4f943f1101..db45d1958e2d21b0c2f3f8f9647c7dc240975aed 100644 (file)
@@ -158,16 +158,40 @@ class ExprStmt : public Stmt
 {
   // TODO: add any useful virtual functions
 
+  std::unique_ptr<Expr> expr;
   Location locus;
 
 public:
+  std::string as_string () const override;
+
   Location get_locus () const override final { return locus; }
 
   bool is_item () const override final { return false; }
 
+  Expr *get_expr () { return expr.get (); }
+
+  // Copy constructor with clone
+  ExprStmt (ExprStmt const &other)
+    : Stmt (other), expr (other.expr->clone_expr ()), locus (other.locus)
+  {}
+
+  // Overloaded assignment operator to clone
+  ExprStmt &operator= (ExprStmt const &other)
+  {
+    Stmt::operator= (other);
+    expr = other.expr->clone_expr ();
+    locus = other.locus;
+
+    return *this;
+  }
+
+  // move constructors
+  ExprStmt (ExprStmt &&other) = default;
+  ExprStmt &operator= (ExprStmt &&other) = default;
+
 protected:
-  ExprStmt (Analysis::NodeMapping mappings, Location locus)
-    : Stmt (std::move (mappings)), locus (locus)
+  ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr, Location locus)
+    : Stmt (std::move (mappings)), expr (std::move (expr)), locus (locus)
   {}
 };
 
@@ -175,39 +199,16 @@ protected:
  * difficulties, can only be guaranteed to hold an expression). */
 class ExprStmtWithoutBlock : public ExprStmt
 {
-  std::unique_ptr<Expr> expr;
 
 public:
-  std::string as_string () const override;
-
   ExprStmtWithoutBlock (Analysis::NodeMapping mappings,
                        std::unique_ptr<Expr> expr, Location locus)
-    : ExprStmt (std::move (mappings), locus), expr (std::move (expr))
-  {}
-
-  // Copy constructor with clone
-  ExprStmtWithoutBlock (ExprStmtWithoutBlock const &other)
-    : ExprStmt (other), expr (other.expr->clone_expr ())
+    : ExprStmt (std::move (mappings), std::move (expr), locus)
   {}
 
-  // Overloaded assignment operator to clone
-  ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock const &other)
-  {
-    ExprStmt::operator= (other);
-    expr = other.expr->clone_expr ();
-
-    return *this;
-  }
-
-  // move constructors
-  ExprStmtWithoutBlock (ExprStmtWithoutBlock &&other) = default;
-  ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock &&other) = default;
-
   void accept_vis (HIRFullVisitor &vis) override;
   void accept_vis (HIRStmtVisitor &vis) override;
 
-  Expr *get_expr () { return expr.get (); }
-
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
@@ -220,42 +221,19 @@ protected:
 // Statement containing an expression with a block
 class ExprStmtWithBlock : public ExprStmt
 {
-  std::unique_ptr<ExprWithBlock> expr;
   bool must_be_unit;
 
 public:
-  std::string as_string () const override;
-
   ExprStmtWithBlock (Analysis::NodeMapping mappings,
                     std::unique_ptr<ExprWithBlock> expr, Location locus,
                     bool must_be_unit)
-    : ExprStmt (std::move (mappings), locus), expr (std::move (expr)),
+    : ExprStmt (std::move (mappings), std::move (expr), locus),
       must_be_unit (must_be_unit)
   {}
 
-  // Copy constructor with clone
-  ExprStmtWithBlock (ExprStmtWithBlock const &other)
-    : ExprStmt (other), expr (other.expr->clone_expr_with_block ())
-  {}
-
-  // Overloaded assignment operator to clone
-  ExprStmtWithBlock &operator= (ExprStmtWithBlock const &other)
-  {
-    ExprStmt::operator= (other);
-    expr = other.expr->clone_expr_with_block ();
-
-    return *this;
-  }
-
-  // move constructors
-  ExprStmtWithBlock (ExprStmtWithBlock &&other) = default;
-  ExprStmtWithBlock &operator= (ExprStmtWithBlock &&other) = default;
-
   void accept_vis (HIRFullVisitor &vis) override;
   void accept_vis (HIRStmtVisitor &vis) override;
 
-  ExprWithBlock *get_expr () { return expr.get (); }
-
   bool is_unit_check_needed () const override { return must_be_unit; }
 
 protected:
index 0d42546ab92c8a548cdce768561bf48b728f73ed..e78ada1d0d9004b4d2e1e72b76b7134ae3cae58d 100644 (file)
@@ -1075,9 +1075,9 @@ PathInExpression::as_string () const
 }
 
 std::string
-ExprStmtWithBlock::as_string () const
+ExprStmt::as_string () const
 {
-  std::string str = indent_spaces (enter) + "ExprStmtWithBlock: \n";
+  std::string str = indent_spaces (enter) + "ExprStmt:\n";
 
   if (expr == nullptr)
     {
@@ -1941,26 +1941,6 @@ TupleExpr::as_string () const
   return str;
 }
 
-std::string
-ExprStmtWithoutBlock::as_string () const
-{
-  std::string str ("ExprStmtWithoutBlock:\n");
-  indent_spaces (enter);
-  str += indent_spaces (stay);
-
-  if (expr == nullptr)
-    {
-      str += "none (this shouldn't happen and is probably an error)";
-    }
-  else
-    {
-      str += expr->as_string ();
-    }
-  indent_spaces (out);
-
-  return str;
-}
-
 std::string
 FunctionParam::as_string () const
 {
This page took 0.071709 seconds and 5 git commands to generate.