]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fully unify deriving classes into HIR::ExprStmt
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 8 Apr 2023 06:24:03 +0000 (02:24 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:47 +0000 (18:28 +0100)
gcc/rust/ChangeLog:

* hir/tree/rust-hir-full-decls.h
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/tree/rust-hir-stmt.h
(class ExprStmt):
Add remaining ExprStmtWith{,out}Block functionality.
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit):
Lower to HIR::ExprStmt instead of deriving class.

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

index 6f34181c6299b49eb009007dde62f6ecbee38be6..be9add9b8b5891ca8963c13db6062052ea8ba03d 100644 (file)
@@ -66,10 +66,8 @@ ASTLoweringStmt::visit (AST::ExprStmtWithBlock &stmt)
                                 mappings->get_next_hir_id (crate_num),
                                 UNKNOWN_LOCAL_DEFID);
   translated
-    = new HIR::ExprStmtWithBlock (mapping,
-                                 std::unique_ptr<HIR::ExprWithBlock> (expr),
-                                 stmt.get_locus (),
-                                 !stmt.is_semicolon_followed ());
+    = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::ExprWithBlock> (expr),
+                        stmt.get_locus (), !stmt.is_semicolon_followed ());
 }
 
 void
@@ -82,9 +80,8 @@ 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::ExprStmtWithoutBlock (mapping, std::unique_ptr<HIR::Expr> (expr),
-                                    stmt.get_locus ());
+  translated = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
+                                 stmt.get_locus ());
 }
 
 void
index 4ae3471cccda4b352fc7823e8b2c9c7933c9809e..d628c52bbc251b07df7a6cc44c6efc14724b6fca 100644 (file)
@@ -129,8 +129,6 @@ class AsyncBlockExpr;
 class EmptyStmt;
 class LetStmt;
 class ExprStmt;
-class ExprStmtWithoutBlock;
-class ExprStmtWithBlock;
 
 // rust-item.h
 class TypeParam;
index 07d29a5482d9256801eef31e3ecbfebeb243d48a..e1514842f80071a294c545a7a07aa95054dda701 100644 (file)
@@ -152,16 +152,25 @@ protected:
   LetStmt *clone_stmt_impl () const override { return new LetStmt (*this); }
 };
 
-/* Abstract base class for expression statements (statements containing an
- * expression) */
+/* class for expression statements (statements containing an expression) */
 class ExprStmt : public Stmt
 {
-  // TODO: add any useful virtual functions
-
   std::unique_ptr<Expr> expr;
   Location locus;
+  bool must_be_unit;
 
 public:
+  ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
+           Location locus, bool must_be_unit)
+    : Stmt (std::move (mappings)), expr (std::move (expr)), locus (locus),
+      must_be_unit (must_be_unit)
+  {}
+
+  ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
+           Location locus)
+    : ExprStmt (std::move (mappings), std::move (expr), locus, false)
+  {}
+
   std::string as_string () const override;
 
   Location get_locus () const override final { return locus; }
@@ -192,54 +201,12 @@ public:
   ExprStmt (ExprStmt &&other) = default;
   ExprStmt &operator= (ExprStmt &&other) = default;
 
-protected:
-  ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr, Location locus)
-    : Stmt (std::move (mappings)), expr (std::move (expr)), 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
-{
-
-public:
-  ExprStmtWithoutBlock (Analysis::NodeMapping mappings,
-                       std::unique_ptr<Expr> expr, Location locus)
-    : ExprStmt (std::move (mappings), std::move (expr), locus)
-  {}
-
-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
-{
-  bool must_be_unit;
-
-public:
-  ExprStmtWithBlock (Analysis::NodeMapping mappings,
-                    std::unique_ptr<ExprWithBlock> expr, Location locus,
-                    bool must_be_unit)
-    : ExprStmt (std::move (mappings), std::move (expr), locus),
-      must_be_unit (must_be_unit)
-  {}
-
   bool is_unit_check_needed () const override { return must_be_unit; }
 
 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 HIR