]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction
authorMatthew Jasper <mjjasper1@gmail.com>
Tue, 9 May 2023 11:53:33 +0000 (12:53 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:18 +0000 (18:37 +0100)
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>
28 files changed:
gcc/rust/ast/rust-ast-collector.cc
gcc/rust/ast/rust-ast-collector.h
gcc/rust/ast/rust-ast-dump.cc
gcc/rust/ast/rust-ast-dump.h
gcc/rust/ast/rust-ast-full-decls.h
gcc/rust/ast/rust-ast-visitor.h
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-macro.h
gcc/rust/ast/rust-stmt.h
gcc/rust/checks/errors/rust-feature-gate.h
gcc/rust/expand/rust-cfg-strip.cc
gcc/rust/expand/rust-cfg-strip.h
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h
gcc/rust/hir/rust-ast-lower-base.cc
gcc/rust/hir/rust-ast-lower-base.h
gcc/rust/hir/rust-ast-lower-stmt.cc
gcc/rust/hir/rust-ast-lower-stmt.h
gcc/rust/parse/rust-parse-impl.h
gcc/rust/parse/rust-parse.h
gcc/rust/resolve/rust-ast-resolve-base.cc
gcc/rust/resolve/rust-ast-resolve-base.h
gcc/rust/resolve/rust-ast-resolve-stmt.h
gcc/rust/resolve/rust-early-name-resolver.cc
gcc/rust/resolve/rust-early-name-resolver.h
gcc/rust/util/rust-attributes.cc
gcc/rust/util/rust-attributes.h

index 586fc031af01f83a9a8e768cda5f07c4061d003f..afc169516a104529d2aa15e4c78402d92d2161aa 100644 (file)
@@ -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 ());
 }
index 868de037c3e05b38b1a59d58bdbb3c03f54caeb6..d4712c276988c8c43d51aaef6fe975e29bef4712 100644 (file)
@@ -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);
index c52de8b6a029bfe461fbdf58a2a7c457c8632936..78c6a083787fcc36a6bf04088488ea0c2438186e 100644 (file)
@@ -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 ());
 }
index b8b5e960035ca72eec740ccac06c0984559909d8..408ee3d6361c3dc1b6556a97f85ca1ba03be0065 100644 (file)
@@ -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);
index de0f12b04bc571bbc868439180ce40ae911d36a6..b23af48ccdb1938d029691544909bdaa273303e2 100644 (file)
@@ -159,8 +159,6 @@ class InlineAsm;
 class EmptyStmt;
 class LetStmt;
 class ExprStmt;
-class ExprStmtWithoutBlock;
-class ExprStmtWithBlock;
 
 // rust-item.h
 class TypeParam;
index f11c9c31ae2db8fd580de5d6ed897bb675b53c69..a69db3dd3cbbda3b953236492ee8e51b8b60a578 100644 (file)
@@ -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;
index 7a9dc8a008b5ecba18cc44c37021176dc87b26d7..550af84dc4a85c1b4e5705cda2c30d48f69ee28c 100644 (file)
@@ -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);
 }
index 0c86ff659ae8952120dce1ac2306998d6746297d..1591469f6d8807b1060c1831a7f5147e07b685be 100644 (file)
@@ -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
index b6349a71ed3e1a74f3b1f1540dd4e2855a6eb7db..c7472decc27733f8387e9374d0c121c9590155b1 100644 (file)
@@ -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 ();
index 59db2a8bca2f021904025a4c74c2229c8b513564..7496a376d8a51097c316bec742d653e179dc070d 100644 (file)
@@ -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
index 5d747047e189a3e81bc12a0c5979da2d9fb5cfa7..a22569433cdf5ef0486128f405653b8a07038aec 100644 (file)
@@ -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 {}
index 0aebb6f19d43a2ddf700f1a0cfee34608418fc4e..3f47100888d1bb4acea316923ed039c3b219b980 100644 (file)
@@ -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
 
index d631b5a95100dce48ed7e1705435fada320f4db7..a118f919442c7ae570ff32234d02c3b5965bfc82 100644 (file)
@@ -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;
index c4191ce68d1a2fdbeb49d6e543359ffebe01e2bc..a0cfd00e9a0fdc4989d984bbf2b65ac0770d97d0 100644 (file)
@@ -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 ());
 }
index f3123767213fb1558151ab4b837edc1921f979c9..7b245181995d1ed193f05aa85919c648eaf95c37 100644 (file)
@@ -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;
index 70f57c3441748cb4070fb9824948590e5310417d..096bc4f0862fb709dc7e60af3d7bb80f84a6dd52 100644 (file)
@@ -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
index f839eae21807113828d8d65d252117ca5be92b66..7e8cbf7e8dcd93ce8654c21079bef34b7e6d43c1 100644 (file)
@@ -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);
index dc14cb0608f65c2343eb3dda389b19f95964d8b7..d99a3f36a5af9f50db363fc11805d35006cdb094 100644 (file)
@@ -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
index 60ba1f4ede78575896d51b10ddbff6b26777f017..afd4dcabd64e3521953f789bd6b996e941873172 100644 (file)
@@ -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;
index 7fefb16c8d16f3602062b88da63597263167dcf4..f4df6fa8a1f5c61603f4eacf2358993bbcb5084a 100644 (file)
@@ -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));
          }
 
index 71f0ff1c0d22613c688811ccb57d466896ee2b47..a092290d880069c63c6e6799961c715d5534617d 100644 (file)
@@ -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 ());
index 997a1538e4dc2b8fbff4b2a0a38e874dce8d003d..b70d7196584785cb23980781dd2c10ec25c3a344 100644 (file)
@@ -587,11 +587,7 @@ ResolverBase::visit (AST::LetStmt &)
 {}
 
 void
-ResolverBase::visit (AST::ExprStmtWithoutBlock &)
-{}
-
-void
-ResolverBase::visit (AST::ExprStmtWithBlock &)
+ResolverBase::visit (AST::ExprStmt &)
 {}
 
 void
index 136d637385898e1e55c5b0bd045fd3d1c8bce635..f9aff16732231475070452e94d1a3a04cc9f4053 100644 (file)
@@ -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 &);
index bec5805c36fdfeaf6275ec792b3927bdd4bb2139..382192034502d4f12dc8e48ca9e4ed8c040ea2bb 100644 (file)
@@ -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);
   }
index f3e4b198f09fa281d500910732e48d1b895e3c0b..2165eed267fb5f93192e215348edab369a3c42b2 100644 (file)
@@ -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);
 }
index dfdab817d00c77cdc1e479b1ed18700070706b06..4d2ef989ba609529d2ed654b0a6d1f1675c50d34 100644 (file)
@@ -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);
index 03afad72bdd1b7fae655efb86eb784bd008f969d..92f0d644d98950ff668d27ba47ba02fed110948b 100644 (file)
@@ -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
index e8a1d273aea0a66256c9adc252d6052d06f36a43..1be2034c9147a5c5d946d7010bf77558345f1929 100644 (file)
@@ -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);