diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-stmt.cc | 11 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-decls.h | 2 | ||||
-rw-r--r-- | 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 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 |