[gcc r14-7472] gccrs: Fully unify deriving classes into HIR::ExprStmt
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:37:41 GMT 2024
https://gcc.gnu.org/g:e7312c67a713ff2686b11d689b11eb94d5a88581
commit r14-7472-ge7312c67a713ff2686b11d689b11eb94d5a88581
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date: Sat Apr 8 02:24:03 2023 -0400
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>
Diff:
---
gcc/rust/hir/rust-ast-lower-stmt.cc | 11 +++---
gcc/rust/hir/tree/rust-hir-full-decls.h | 2 --
gcc/rust/hir/tree/rust-hir-stmt.h | 61 ++++++++-------------------------
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 6f34181c629..be9add9b8b5 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 4ae3471cccd..d628c52bbc2 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 07d29a5482d..e1514842f80 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
More information about the Gcc-cvs
mailing list