aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-04-08 02:24:03 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:28:47 +0100
commite7312c67a713ff2686b11d689b11eb94d5a88581 (patch)
tree91d753f74a803dc6f6ba5ecb588e8953b820975e /gcc
parentd93a1f032db86fe602566a6868b9bc5279554e71 (diff)
downloadgcc-e7312c67a713ff2686b11d689b11eb94d5a88581.zip
gcc-e7312c67a713ff2686b11d689b11eb94d5a88581.tar.gz
gcc-e7312c67a713ff2686b11d689b11eb94d5a88581.tar.bz2
gccrs: Fully unify deriving classes into HIR::ExprStmt
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/rust-ast-lower-stmt.cc11
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-stmt.h61
3 files changed, 18 insertions, 56 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index 6f34181..be9add9 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -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
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index 4ae3471..d628c52 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -129,8 +129,6 @@ class AsyncBlockExpr;
class EmptyStmt;
class LetStmt;
class ExprStmt;
-class ExprStmtWithoutBlock;
-class ExprStmtWithBlock;
// rust-item.h
class TypeParam;
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index 07d29a5..e151484 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -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