[gcc r14-7592] gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:43:25 GMT 2024


https://gcc.gnu.org/g:9e9ee593cf0507e5b54a556737909a46c6e91319

commit r14-7592-g9e9ee593cf0507e5b54a556737909a46c6e91319
Author: Matthew Jasper <mjjasper1@gmail.com>
Date:   Tue May 9 12:53:33 2023 +0100

    gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction
    
    This distinction isn't very helpful and makes correct parsing harder.
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-full-decls.h (class ExprStmtWithoutBlock): Remove.
            (class ExprStmtWithBlock): Remove.
            * ast/rust-stmt.h (class ExprStmtWithoutBlock): Remove.
            (class ExprStmtWithBlock): Remove.
            (class ExprStmt):
            Make non-abstract, add common functionality from removed base classes.
            * ast/rust-ast.h: Move to_stmt to base class.
            * ast/rust-ast.cc (ExprStmtWithBlock::as_string): Remove.
            * ast/rust-macro.h: Use new signature for to_stmt.
            (ExprStmt::as_string): New method.
            (ExprStmtWithoutBlock::as_string): Remove.
            (BlockExpr::strip_tail_expr): Update for removed classes.
            (ExprStmtWithoutBlock::accept_vis): Remove.
            (ExprStmtWithBlock::accept_vis): Remove.
            (ExprStmt::accept_vis): New method.
            * ast/rust-ast-dump.cc (Dump::visit): Update for removed classes.
            * ast/rust-ast-dump.h: Likewise.
            * ast/rust-ast-collector.h: Likewise.
            * ast/rust-ast-collector.cc (TokenStream::visit): Likewise.
            * ast/rust-ast-visitor.h: Likewise.
            * checks/errors/rust-feature-gate.h: Likewise.
            * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
            * expand/rust-expand-visitor.h: Likewise.
            * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
            * expand/rust-cfg-strip.h: Likewise.
            * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
            * hir/rust-ast-lower-base.h: Likewise.
            * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
            * hir/rust-ast-lower-stmt.h: Likewise.
            * util/rust-attributes.cc (AttributeChecker::visit): Likewise.
            * util/rust-attributes.h: Likewise.
            * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
            * resolve/rust-ast-resolve-base.h: Likewise.
            * resolve/rust-ast-resolve-stmt.h: Likewise.
            * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
            Likewise.
            * resolve/rust-early-name-resolver.h: Likewise.
            * parse/rust-parse-impl.h (Parser::parse_match_expr): Likewise.
            (Parser::parse_stmt_or_expr_without_block): Likewise.
            * parse/rust-parse.h: Likewise.
    
    Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc           |   8 +-
 gcc/rust/ast/rust-ast-collector.h            |   3 +-
 gcc/rust/ast/rust-ast-dump.cc                |   8 +-
 gcc/rust/ast/rust-ast-dump.h                 |   3 +-
 gcc/rust/ast/rust-ast-full-decls.h           |   2 -
 gcc/rust/ast/rust-ast-visitor.h              |   3 +-
 gcc/rust/ast/rust-ast.cc                     |  40 ++------
 gcc/rust/ast/rust-ast.h                      |   4 +-
 gcc/rust/ast/rust-macro.h                    |   2 +-
 gcc/rust/ast/rust-stmt.h                     | 138 ++++-----------------------
 gcc/rust/checks/errors/rust-feature-gate.h   |   3 +-
 gcc/rust/expand/rust-cfg-strip.cc            |  20 +---
 gcc/rust/expand/rust-cfg-strip.h             |   3 +-
 gcc/rust/expand/rust-expand-visitor.cc       |   8 +-
 gcc/rust/expand/rust-expand-visitor.h        |   3 +-
 gcc/rust/hir/rust-ast-lower-base.cc          |   5 +-
 gcc/rust/hir/rust-ast-lower-base.h           |   3 +-
 gcc/rust/hir/rust-ast-lower-stmt.cc          |  23 +----
 gcc/rust/hir/rust-ast-lower-stmt.h           |   3 +-
 gcc/rust/parse/rust-parse-impl.h             |  87 +++++++----------
 gcc/rust/parse/rust-parse.h                  |   4 +-
 gcc/rust/resolve/rust-ast-resolve-base.cc    |   6 +-
 gcc/rust/resolve/rust-ast-resolve-base.h     |   3 +-
 gcc/rust/resolve/rust-ast-resolve-stmt.h     |   7 +-
 gcc/rust/resolve/rust-early-name-resolver.cc |   8 +-
 gcc/rust/resolve/rust-early-name-resolver.h  |   3 +-
 gcc/rust/util/rust-attributes.cc             |   6 +-
 gcc/rust/util/rust-attributes.h              |   3 +-
 28 files changed, 87 insertions(+), 322 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 586fc031af0..afc169516a1 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -2666,13 +2666,7 @@ TokenCollector::visit (LetStmt &stmt)
 }
 
 void
-TokenCollector::visit (ExprStmtWithoutBlock &stmt)
-{
-  visit (stmt.get_expr ());
-}
-
-void
-TokenCollector::visit (ExprStmtWithBlock &stmt)
+TokenCollector::visit (ExprStmt &stmt)
 {
   visit (stmt.get_expr ());
 }
diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h
index 868de037c3e..d4712c27698 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -287,8 +287,7 @@ private:
   // rust-stmt.h
   void visit (EmptyStmt &stmt);
   void visit (LetStmt &stmt);
-  void visit (ExprStmtWithoutBlock &stmt);
-  void visit (ExprStmtWithBlock &stmt);
+  void visit (ExprStmt &stmt);
 
   // rust-type.h
   void visit (TraitBound &bound);
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index c52de8b6a02..78c6a083787 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -1689,13 +1689,7 @@ Dump::visit (LetStmt &stmt)
 }
 
 void
-Dump::visit (ExprStmtWithoutBlock &stmt)
-{
-  visit (stmt.get_expr ());
-}
-
-void
-Dump::visit (ExprStmtWithBlock &stmt)
+Dump::visit (ExprStmt &stmt)
 {
   visit (stmt.get_expr ());
 }
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index b8b5e960035..408ee3d6361 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -269,8 +269,7 @@ private:
   // rust-stmt.h
   void visit (EmptyStmt &stmt);
   void visit (LetStmt &stmt);
-  void visit (ExprStmtWithoutBlock &stmt);
-  void visit (ExprStmtWithBlock &stmt);
+  void visit (ExprStmt &stmt);
 
   // rust-type.h
   void visit (TraitBound &bound);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index de0f12b04bc..b23af48ccdb 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -159,8 +159,6 @@ class InlineAsm;
 class EmptyStmt;
 class LetStmt;
 class ExprStmt;
-class ExprStmtWithoutBlock;
-class ExprStmtWithBlock;
 
 // rust-item.h
 class TypeParam;
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index f11c9c31ae2..a69db3dd3cb 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -206,8 +206,7 @@ public:
   // rust-stmt.h
   virtual void visit (EmptyStmt &stmt) = 0;
   virtual void visit (LetStmt &stmt) = 0;
-  virtual void visit (ExprStmtWithoutBlock &stmt) = 0;
-  virtual void visit (ExprStmtWithBlock &stmt) = 0;
+  virtual void visit (ExprStmt &stmt) = 0;
 
   // rust-type.h
   virtual void visit (TraitBound &bound) = 0;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 7a9dc8a008b..550af84dc4a 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1261,9 +1261,9 @@ MacroInvocData::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)
     {
@@ -1273,6 +1273,8 @@ ExprStmtWithBlock::as_string () const
     {
       indent_spaces (enter);
       str += expr->as_string ();
+      if (semicolon_followed)
+	str += ";";
       indent_spaces (out);
     }
 
@@ -2042,22 +2044,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
 {
@@ -4225,14 +4211,10 @@ BlockExpr::strip_tail_expr ()
 	{
 	  auto &stmt = static_cast<ExprStmt &> (*statements.back ());
 
-	  if (stmt.get_type () == ExprStmt::ExprStmtType::WITH_BLOCK)
+	  if (!stmt.is_semicolon_followed ())
 	    {
-	      auto &stmt_block = static_cast<ExprStmtWithBlock &> (stmt);
-	      if (!stmt_block.is_semicolon_followed ())
-		{
-		  expr = std::move (stmt_block.get_expr ());
-		  statements.pop_back ();
-		}
+	      expr = std::move (stmt.get_expr ());
+	      statements.pop_back ();
 	    }
 	}
     }
@@ -4831,13 +4813,7 @@ LetStmt::accept_vis (ASTVisitor &vis)
 }
 
 void
-ExprStmtWithoutBlock::accept_vis (ASTVisitor &vis)
-{
-  vis.visit (*this);
-}
-
-void
-ExprStmtWithBlock::accept_vis (ASTVisitor &vis)
+ExprStmt::accept_vis (ASTVisitor &vis)
 {
   vis.visit (*this);
 }
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 0c86ff659ae..1591469f6d8 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -984,6 +984,8 @@ public:
 
   virtual std::vector<Attribute> &get_outer_attrs () = 0;
 
+  virtual Expr *to_stmt () const { return clone_expr_impl (); }
+
 protected:
   // Constructor
   Expr () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {}
@@ -1028,8 +1030,6 @@ public:
   {
     return clone_expr_without_block_impl ();
   }
-
-  virtual ExprWithoutBlock *to_stmt () const { return clone_expr_impl (); }
 };
 
 /* HACK: IdentifierExpr, delete when figure out identifier vs expr problem in
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index b6349a71ed3..c7472decc27 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -802,7 +802,7 @@ protected:
     return clone_macro_invocation_impl ();
   }
 
-  ExprWithoutBlock *to_stmt () const override
+  Expr *to_stmt () const override
 
   {
     auto new_impl = clone_macro_invocation_impl ();
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h
index 59db2a8bca2..7496a376d8a 100644
--- a/gcc/rust/ast/rust-stmt.h
+++ b/gcc/rust/ast/rust-stmt.h
@@ -179,19 +179,12 @@ protected:
   LetStmt *clone_stmt_impl () const override { return new LetStmt (*this); }
 };
 
-/* Abstract base class for expression statements (statements containing an
- * expression) */
+// Expression statements (statements containing an expression)
 class ExprStmt : public Stmt
 {
-public:
-  enum ExprStmtType
-  {
-    WITH_BLOCK,
-    WITHOUT_BLOCK
-  };
-
-protected:
+  std::unique_ptr<Expr> expr;
   Location locus;
+  bool semicolon_followed;
 
 public:
   Location get_locus () const override final { return locus; }
@@ -199,134 +192,44 @@ public:
   bool is_item () const override final { return false; }
 
   bool is_expr () const override final { return true; }
-
-  virtual ExprStmtType get_type () const = 0;
-
-protected:
-  ExprStmt (Location locus) : locus (locus) {}
-};
-
-/* Statement containing an expression without a block (or, due to technical
- * difficulties, can only be guaranteed to hold an expression). */
-class ExprStmtWithoutBlock : public ExprStmt
-{
-  // TODO: ensure that this works
-  std::unique_ptr<ExprWithoutBlock> expr;
-  /* HACK: cannot ensure type safety of ExprWithoutBlock due to Pratt parsing,
-   * so have to store more general type of Expr. FIXME: fix this issue somehow
-   * or redesign AST. */
-  // std::unique_ptr<Expr> expr;
-
-public:
-  std::string as_string () const override;
-
-  ExprStmtWithoutBlock (std::unique_ptr<ExprWithoutBlock> expr, Location locus)
-    : ExprStmt (locus), expr (std::move (expr->to_stmt ()))
-  {}
-
-  /*ExprStmtWithoutBlock (std::unique_ptr<Expr> expr, Location locus)
-    : ExprStmt (locus), expr (std::move (expr))
-  {}*/
-
-  // Copy constructor with clone
-  ExprStmtWithoutBlock (ExprStmtWithoutBlock const &other) : ExprStmt (other)
-  {
-    // guard to prevent null dereference (only required if error state)
-    if (other.expr != nullptr)
-      expr = other.expr->clone_expr_without_block ();
-  }
-  /*ExprStmtWithoutBlock (ExprStmtWithoutBlock const &other)
-    : ExprStmt (other), expr (other.expr->clone_expr ())
-  {}*/
-
-  // Overloaded assignment operator to clone
-  ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock const &other)
-  {
-    ExprStmt::operator= (other);
-    // expr = other.expr->clone_expr ();
-
-    // guard to prevent null dereference (only required if error state)
-    if (other.expr != nullptr)
-      expr = other.expr->clone_expr_without_block ();
-    else
-      expr = nullptr;
-
-    return *this;
-  }
-
-  // move constructors
-  ExprStmtWithoutBlock (ExprStmtWithoutBlock &&other) = default;
-  ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock &&other) = default;
-
-  void accept_vis (ASTVisitor &vis) override;
-
-  // Invalid if expr is null, so base stripping on that.
-  void mark_for_strip () override { expr = nullptr; }
-  bool is_marked_for_strip () const override { return expr == nullptr; }
-
-  // TODO: is this better? Or is a "vis_block" better?
-  std::unique_ptr<ExprWithoutBlock> &get_expr ()
-  {
-    rust_assert (expr != nullptr);
-    return expr;
-  }
-
-  ExprStmtType get_type () const override
-  {
-    return ExprStmtType::WITHOUT_BLOCK;
-  };
-
-protected:
-  /* Use covariance to implement clone function as returning this object rather
-   * than base */
-  ExprStmtWithoutBlock *clone_stmt_impl () const override
-  {
-    return new ExprStmtWithoutBlock (*this);
-  }
-};
-
-// Statement containing an expression with a block
-class ExprStmtWithBlock : public ExprStmt
-{
-  std::unique_ptr<ExprWithBlock> expr;
-  bool semicolon_followed;
-
-public:
   std::string as_string () const override;
 
   std::vector<LetStmt *> locals;
 
-  ExprStmtWithBlock (std::unique_ptr<ExprWithBlock> expr, Location locus,
-		     bool semicolon_followed)
-    : ExprStmt (locus), expr (std::move (expr)),
+  ExprStmt (std::unique_ptr<Expr> expr, Location locus, bool semicolon_followed)
+    : expr (expr->to_stmt ()), locus (locus),
       semicolon_followed (semicolon_followed)
   {}
 
   // Copy constructor with clone
-  ExprStmtWithBlock (ExprStmtWithBlock const &other) : ExprStmt (other)
+  ExprStmt (ExprStmt const &other)
+    : locus (other.locus), semicolon_followed (other.semicolon_followed)
   {
     // guard to prevent null dereference (only required if error state)
     if (other.expr != nullptr)
-      expr = other.expr->clone_expr_with_block ();
+      expr = other.expr->clone_expr ();
   }
 
   // Overloaded assignment operator to clone
-  ExprStmtWithBlock &operator= (ExprStmtWithBlock const &other)
+  ExprStmt &operator= (ExprStmt const &other)
   {
-    ExprStmt::operator= (other);
+    Stmt::operator= (other);
 
     // guard to prevent null dereference (only required if error state)
     if (other.expr != nullptr)
-      expr = other.expr->clone_expr_with_block ();
+      expr = other.expr->clone_expr ();
     else
       expr = nullptr;
 
+    locus = other.locus;
+    semicolon_followed = other.semicolon_followed;
+
     return *this;
   }
 
   // move constructors
-  ExprStmtWithBlock (ExprStmtWithBlock &&other) = default;
-  ExprStmtWithBlock &operator= (ExprStmtWithBlock &&other) = default;
+  ExprStmt (ExprStmt &&other) = default;
+  ExprStmt &operator= (ExprStmt &&other) = default;
 
   void accept_vis (ASTVisitor &vis) override;
 
@@ -335,7 +238,7 @@ public:
   bool is_marked_for_strip () const override { return expr == nullptr; }
 
   // TODO: is this better? Or is a "vis_block" better?
-  std::unique_ptr<ExprWithBlock> &get_expr ()
+  std::unique_ptr<Expr> &get_expr ()
   {
     rust_assert (expr != nullptr);
     return expr;
@@ -343,15 +246,10 @@ public:
 
   bool is_semicolon_followed () const { return semicolon_followed; }
 
-  ExprStmtType get_type () const override { return ExprStmtType::WITH_BLOCK; };
-
 protected:
   /* Use covariance to implement clone function as returning this object rather
    * than base */
-  ExprStmtWithBlock *clone_stmt_impl () const override
-  {
-    return new ExprStmtWithBlock (*this);
-  }
+  ExprStmt *clone_stmt_impl () const override { return new ExprStmt (*this); }
 };
 
 } // namespace AST
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index 5d747047e18..a22569433cd 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -168,8 +168,7 @@ public:
   void visit (AST::AltPattern &pattern) override {}
   void visit (AST::EmptyStmt &stmt) override {}
   void visit (AST::LetStmt &stmt) override {}
-  void visit (AST::ExprStmtWithoutBlock &stmt) override {}
-  void visit (AST::ExprStmtWithBlock &stmt) override {}
+  void visit (AST::ExprStmt &stmt) override {}
   void visit (AST::TraitBound &bound) override {}
   void visit (AST::ImplTraitType &type) override {}
   void visit (AST::TraitObjectType &type) override {}
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc
index 0aebb6f19d4..3f47100888d 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -3010,25 +3010,7 @@ CfgStrip::visit (AST::LetStmt &stmt)
     }
 }
 void
-CfgStrip::visit (AST::ExprStmtWithoutBlock &stmt)
-{
-  // outer attributes associated with expr, so rely on expr
-
-  // guard - should prevent null pointer expr
-  if (stmt.is_marked_for_strip ())
-    return;
-
-  // strip if expr is to be stripped
-  auto &expr = stmt.get_expr ();
-  expr->accept_vis (*this);
-  if (expr->is_marked_for_strip ())
-    {
-      stmt.mark_for_strip ();
-      return;
-    }
-}
-void
-CfgStrip::visit (AST::ExprStmtWithBlock &stmt)
+CfgStrip::visit (AST::ExprStmt &stmt)
 {
   // outer attributes associated with expr, so rely on expr
 
diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h
index d631b5a9510..a118f919442 100644
--- a/gcc/rust/expand/rust-cfg-strip.h
+++ b/gcc/rust/expand/rust-cfg-strip.h
@@ -206,8 +206,7 @@ public:
 
   void visit (AST::EmptyStmt &) override;
   void visit (AST::LetStmt &stmt) override;
-  void visit (AST::ExprStmtWithoutBlock &stmt) override;
-  void visit (AST::ExprStmtWithBlock &stmt) override;
+  void visit (AST::ExprStmt &stmt) override;
 
   void visit (AST::TraitBound &bound) override;
   void visit (AST::ImplTraitType &type) override;
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index c4191ce68d1..a0cfd00e9a0 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -1290,13 +1290,7 @@ ExpandVisitor::visit (AST::LetStmt &stmt)
 }
 
 void
-ExpandVisitor::visit (AST::ExprStmtWithoutBlock &stmt)
-{
-  visit (stmt.get_expr ());
-}
-
-void
-ExpandVisitor::visit (AST::ExprStmtWithBlock &stmt)
+ExpandVisitor::visit (AST::ExprStmt &stmt)
 {
   visit (stmt.get_expr ());
 }
diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h
index f3123767213..7b245181995 100644
--- a/gcc/rust/expand/rust-expand-visitor.h
+++ b/gcc/rust/expand/rust-expand-visitor.h
@@ -291,8 +291,7 @@ public:
 
   void visit (AST::EmptyStmt &) override;
   void visit (AST::LetStmt &stmt) override;
-  void visit (AST::ExprStmtWithoutBlock &stmt) override;
-  void visit (AST::ExprStmtWithBlock &stmt) override;
+  void visit (AST::ExprStmt &stmt) override;
 
   void visit (AST::TraitBound &bound) override;
   void visit (AST::ImplTraitType &type) override;
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index 70f57c34417..096bc4f0862 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -467,10 +467,7 @@ void
 ASTLoweringBase::visit (AST::LetStmt &)
 {}
 void
-ASTLoweringBase::visit (AST::ExprStmtWithoutBlock &)
-{}
-void
-ASTLoweringBase::visit (AST::ExprStmtWithBlock &)
+ASTLoweringBase::visit (AST::ExprStmt &)
 {}
 
 // rust-type.h
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index f839eae2180..7e8cbf7e8dc 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -234,8 +234,7 @@ public:
   // rust-stmt.h
   virtual void visit (AST::EmptyStmt &stmt);
   virtual void visit (AST::LetStmt &stmt);
-  virtual void visit (AST::ExprStmtWithoutBlock &stmt);
-  virtual void visit (AST::ExprStmtWithBlock &stmt);
+  virtual void visit (AST::ExprStmt &stmt);
 
   // rust-type.h
   virtual void visit (AST::TraitBound &bound);
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index dc14cb0608f..d99a3f36a5a 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -55,23 +55,7 @@ ASTLoweringStmt::translate (AST::Stmt *stmt, bool *terminated)
 }
 
 void
-ASTLoweringStmt::visit (AST::ExprStmtWithBlock &stmt)
-{
-  HIR::ExprWithBlock *expr
-    = ASTLoweringExprWithBlock::translate (stmt.get_expr ().get (),
-					   &terminated);
-
-  auto crate_num = mappings->get_current_crate ();
-  Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
-				 mappings->get_next_hir_id (crate_num),
-				 UNKNOWN_LOCAL_DEFID);
-  translated
-    = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::ExprWithBlock> (expr),
-			 stmt.get_locus (), !stmt.is_semicolon_followed ());
-}
-
-void
-ASTLoweringStmt::visit (AST::ExprStmtWithoutBlock &stmt)
+ASTLoweringStmt::visit (AST::ExprStmt &stmt)
 {
   HIR::Expr *expr
     = ASTLoweringExpr::translate (stmt.get_expr ().get (), &terminated);
@@ -80,8 +64,9 @@ ASTLoweringStmt::visit (AST::ExprStmtWithoutBlock &stmt)
   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
 				 mappings->get_next_hir_id (crate_num),
 				 UNKNOWN_LOCAL_DEFID);
-  translated = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
-				  stmt.get_locus ());
+  translated
+    = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
+			 stmt.get_locus (), !stmt.is_semicolon_followed ());
 }
 
 void
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h
index 60ba1f4ede7..afd4dcabd64 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -31,8 +31,7 @@ class ASTLoweringStmt : public ASTLoweringBase
 public:
   static HIR::Stmt *translate (AST::Stmt *stmt, bool *terminated);
 
-  void visit (AST::ExprStmtWithBlock &stmt) override;
-  void visit (AST::ExprStmtWithoutBlock &stmt) override;
+  void visit (AST::ExprStmt &stmt) override;
   void visit (AST::ConstantItem &constant) override;
   void visit (AST::LetStmt &stmt) override;
   void visit (AST::TupleStruct &struct_decl) override;
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 7fefb16c8d1..f4df6fa8a1f 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -7387,7 +7387,7 @@ Parser<ManagedTokenSource>::parse_expr_with_block (AST::AttrVec outer_attrs)
 /* Parses a expression statement containing an expression with block.
  * Disambiguates internally. */
 template <typename ManagedTokenSource>
-std::unique_ptr<AST::ExprStmtWithBlock>
+std::unique_ptr<AST::ExprStmt>
 Parser<ManagedTokenSource>::parse_expr_stmt_with_block (
   AST::AttrVec outer_attrs)
 {
@@ -7395,15 +7395,15 @@ Parser<ManagedTokenSource>::parse_expr_stmt_with_block (
   auto locus = expr_parsed->get_locus ();
 
   // return expr stmt created from expr
-  return std::unique_ptr<AST::ExprStmtWithBlock> (
-    new AST::ExprStmtWithBlock (std::move (expr_parsed), locus,
-				lexer.peek_token ()->get_id () == SEMICOLON));
+  return std::unique_ptr<AST::ExprStmt> (
+    new AST::ExprStmt (std::move (expr_parsed), locus,
+		       lexer.peek_token ()->get_id () == SEMICOLON));
 }
 
 /* Parses an expression statement containing an expression without block.
  * Disambiguates further. */
 template <typename ManagedTokenSource>
-std::unique_ptr<AST::ExprStmtWithoutBlock>
+std::unique_ptr<AST::ExprStmt>
 Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
   AST::AttrVec outer_attrs, ParseRestrictions restrictions)
 {
@@ -7432,8 +7432,8 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
     if (!skip_token (SEMICOLON))
       return nullptr;
 
-  return std::unique_ptr<AST::ExprStmtWithoutBlock> (
-    new AST::ExprStmtWithoutBlock (std::move (expr), locus));
+  return std::unique_ptr<AST::ExprStmt> (
+    new AST::ExprStmt (std::move (expr), locus, true));
 }
 
 /* Parses an expression without a block associated with it (further
@@ -8683,8 +8683,10 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
       restrictions.expr_can_be_stmt = true;
       restrictions.consume_semi = false;
 
-      std::unique_ptr<AST::ExprStmt> expr = parse_expr_stmt ({}, restrictions);
-      if (expr == nullptr)
+      std::unique_ptr<AST::ExprStmt> expr_stmt
+	= parse_expr_stmt ({}, restrictions);
+
+      if (expr_stmt == nullptr)
 	{
 	  Error error (lexer.peek_token ()->get_locus (),
 		       "failed to parse expr in match arm in match expr");
@@ -8693,30 +8695,12 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
 	  // skip somewhere?
 	  return nullptr;
 	}
-      bool is_expr_without_block
-	= expr->get_type () == AST::ExprStmt::ExprStmtType::WITHOUT_BLOCK;
 
-      // construct match case expr and add to cases
-      switch (expr->get_type ())
-	{
-	  case AST::ExprStmt::ExprStmtType::WITH_BLOCK: {
-	    AST::ExprStmtWithBlock *cast
-	      = static_cast<AST::ExprStmtWithBlock *> (expr.get ());
-	    std::unique_ptr<AST::Expr> e = cast->get_expr ()->clone_expr ();
-	    match_arms.push_back (
-	      AST::MatchCase (std::move (arm), std::move (e)));
-	  }
-	  break;
+      std::unique_ptr<AST::Expr> expr = expr_stmt->get_expr ()->clone_expr ();
+      bool is_expr_without_block
+	= expr_stmt->get_expr ()->is_expr_without_block ();
 
-	  case AST::ExprStmt::ExprStmtType::WITHOUT_BLOCK: {
-	    AST::ExprStmtWithoutBlock *cast
-	      = static_cast<AST::ExprStmtWithoutBlock *> (expr.get ());
-	    std::unique_ptr<AST::Expr> e = cast->get_expr ()->clone_expr ();
-	    match_arms.push_back (
-	      AST::MatchCase (std::move (arm), std::move (e)));
-	  }
-	  break;
-	}
+      match_arms.push_back (AST::MatchCase (std::move (arm), std::move (expr)));
 
       // handle comma presence
       if (lexer.peek_token ()->get_id () != COMMA)
@@ -11793,9 +11777,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_with_block (
   // internal block expr must either have semicolons followed, or evaluate to
   // ()
   auto locus = expr->get_locus ();
-  std::unique_ptr<AST::ExprStmtWithBlock> stmt (
-    new AST::ExprStmtWithBlock (std::move (expr), locus,
-				tok->get_id () == SEMICOLON));
+  std::unique_ptr<AST::ExprStmt> stmt (
+    new AST::ExprStmt (std::move (expr), locus, tok->get_id () == SEMICOLON));
   if (tok->get_id () == SEMICOLON)
     lexer.skip_token ();
 
@@ -11920,9 +11903,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 	    // must be expression statement
 	    lexer.skip_token ();
 
-	    std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-	      new AST::ExprStmtWithoutBlock (std::move (expr),
-					     t->get_locus ()));
+	    std::unique_ptr<AST::ExprStmt> stmt (
+	      new AST::ExprStmt (std::move (expr), t->get_locus (), true));
 	    return ExprOrStmt (std::move (stmt));
 	  }
 
@@ -11965,9 +11947,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 		// must be expression statement
 		lexer.skip_token ();
 
-		std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-		  new AST::ExprStmtWithoutBlock (std::move (expr),
-						 t->get_locus ()));
+		std::unique_ptr<AST::ExprStmt> stmt (
+		  new AST::ExprStmt (std::move (expr), t->get_locus (), true));
 		return ExprOrStmt (std::move (stmt));
 	      }
 
@@ -12010,9 +11991,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 	      // must be expression statement
 	      lexer.skip_token ();
 
-	      std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-		new AST::ExprStmtWithoutBlock (std::move (expr),
-					       t->get_locus ()));
+	      std::unique_ptr<AST::ExprStmt> stmt (
+		new AST::ExprStmt (std::move (expr), t->get_locus (), true));
 	      return ExprOrStmt (std::move (stmt));
 	    }
 
@@ -12035,9 +12015,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 
 	    if (expr)
 	      {
-		std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-		  new AST::ExprStmtWithoutBlock (std::move (expr),
-						 t->get_locus ()));
+		std::unique_ptr<AST::ExprStmt> stmt (
+		  new AST::ExprStmt (std::move (expr), t->get_locus (), true));
 		return ExprOrStmt (std::move (stmt));
 	      }
 	    else
@@ -12238,9 +12217,8 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
 	  {
 	    // statement
 	    lexer.skip_token ();
-	    std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-	      new AST::ExprStmtWithoutBlock (std::move (expr),
-					     stmt_or_expr_loc));
+	    std::unique_ptr<AST::ExprStmt> stmt (
+	      new AST::ExprStmt (std::move (expr), stmt_or_expr_loc, true));
 	    return ExprOrStmt (std::move (stmt));
 	  }
 
@@ -12266,9 +12244,9 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
 	  {
 	    // statement
 	    lexer.skip_token ();
-	    std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-	      new AST::ExprStmtWithoutBlock (std::move (struct_expr),
-					     stmt_or_expr_loc));
+	    std::unique_ptr<AST::ExprStmt> stmt (
+	      new AST::ExprStmt (std::move (struct_expr), stmt_or_expr_loc,
+				 true));
 	    return ExprOrStmt (std::move (stmt));
 	  }
 
@@ -12288,9 +12266,8 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
 	  {
 	    lexer.skip_token ();
 
-	    std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
-	      new AST::ExprStmtWithoutBlock (std::move (expr),
-					     stmt_or_expr_loc));
+	    std::unique_ptr<AST::ExprStmt> stmt (
+	      new AST::ExprStmt (std::move (expr), stmt_or_expr_loc, true));
 	    return ExprOrStmt (std::move (stmt));
 	  }
 
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 71f0ff1c0d2..a092290d880 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -637,9 +637,9 @@ private:
   std::unique_ptr<AST::ExprStmt> parse_expr_stmt (AST::AttrVec outer_attrs,
 						  ParseRestrictions restrictions
 						  = ParseRestrictions ());
-  std::unique_ptr<AST::ExprStmtWithBlock>
+  std::unique_ptr<AST::ExprStmt>
   parse_expr_stmt_with_block (AST::AttrVec outer_attrs);
-  std::unique_ptr<AST::ExprStmtWithoutBlock>
+  std::unique_ptr<AST::ExprStmt>
   parse_expr_stmt_without_block (AST::AttrVec outer_attrs,
 				 ParseRestrictions restrictions
 				 = ParseRestrictions ());
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc
index 997a1538e4d..b70d7196584 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-base.cc
@@ -587,11 +587,7 @@ ResolverBase::visit (AST::LetStmt &)
 {}
 
 void
-ResolverBase::visit (AST::ExprStmtWithoutBlock &)
-{}
-
-void
-ResolverBase::visit (AST::ExprStmtWithBlock &)
+ResolverBase::visit (AST::ExprStmt &)
 {}
 
 void
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 136d6373858..f9aff167322 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -180,8 +180,7 @@ public:
 
   void visit (AST::EmptyStmt &);
   void visit (AST::LetStmt &);
-  void visit (AST::ExprStmtWithoutBlock &);
-  void visit (AST::ExprStmtWithBlock &);
+  void visit (AST::ExprStmt &);
 
   void visit (AST::TraitBound &);
   void visit (AST::ImplTraitType &);
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index bec5805c36f..38219203450 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -43,12 +43,7 @@ public:
     stmt->accept_vis (resolver);
   }
 
-  void visit (AST::ExprStmtWithBlock &stmt) override
-  {
-    ResolveExpr::go (stmt.get_expr ().get (), prefix, canonical_prefix);
-  }
-
-  void visit (AST::ExprStmtWithoutBlock &stmt) override
+  void visit (AST::ExprStmt &stmt) override
   {
     ResolveExpr::go (stmt.get_expr ().get (), prefix, canonical_prefix);
   }
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index f3e4b198f09..2165eed267f 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -1157,13 +1157,7 @@ EarlyNameResolver::visit (AST::LetStmt &stmt)
 }
 
 void
-EarlyNameResolver::visit (AST::ExprStmtWithoutBlock &stmt)
-{
-  stmt.get_expr ()->accept_vis (*this);
-}
-
-void
-EarlyNameResolver::visit (AST::ExprStmtWithBlock &stmt)
+EarlyNameResolver::visit (AST::ExprStmt &stmt)
 {
   stmt.get_expr ()->accept_vis (*this);
 }
diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h
index dfdab817d00..4d2ef989ba6 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.h
+++ b/gcc/rust/resolve/rust-early-name-resolver.h
@@ -262,8 +262,7 @@ private:
   virtual void visit (AST::AltPattern &pattern);
   virtual void visit (AST::EmptyStmt &stmt);
   virtual void visit (AST::LetStmt &stmt);
-  virtual void visit (AST::ExprStmtWithoutBlock &stmt);
-  virtual void visit (AST::ExprStmtWithBlock &stmt);
+  virtual void visit (AST::ExprStmt &stmt);
   virtual void visit (AST::TraitBound &bound);
   virtual void visit (AST::ImplTraitType &type);
   virtual void visit (AST::TraitObjectType &type);
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 03afad72bdd..92f0d644d98 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -775,11 +775,7 @@ AttributeChecker::visit (AST::LetStmt &)
 {}
 
 void
-AttributeChecker::visit (AST::ExprStmtWithoutBlock &)
-{}
-
-void
-AttributeChecker::visit (AST::ExprStmtWithBlock &)
+AttributeChecker::visit (AST::ExprStmt &)
 {}
 
 // rust-type.h
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index e8a1d273aea..1be2034c914 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -245,8 +245,7 @@ private:
   // rust-stmt.h
   void visit (AST::EmptyStmt &stmt);
   void visit (AST::LetStmt &stmt);
-  void visit (AST::ExprStmtWithoutBlock &stmt);
-  void visit (AST::ExprStmtWithBlock &stmt);
+  void visit (AST::ExprStmt &stmt);
 
   // rust-type.h
   void visit (AST::TraitBound &bound);


More information about the Gcc-cvs mailing list