diff options
Diffstat (limited to 'gcc')
28 files changed, 87 insertions, 322 deletions
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 586fc03..afc1695 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -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 ()); } diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h index 868de03..d4712c2 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -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); diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 4c1f3d8..0c1ed75 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -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 ()); } diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 1bfa808..f014ad1 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -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); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 543f754..28bee14 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -159,8 +159,6 @@ class InlineAsm; class EmptyStmt; class LetStmt; class ExprStmt; -class ExprStmtWithoutBlock; -class ExprStmtWithBlock; // rust-item.h class TypeParam; diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 6cdb027..ccc8196 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -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; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 6880621..ea267f4 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -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); } @@ -2043,22 +2045,6 @@ TupleExpr::as_string () const } 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 { // TODO: rewrite dump to allow non-literal types @@ -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); } diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 23a84e8..6dbbd3d 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -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 diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 1df328f..0889aae 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -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 (); diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h index 296d891..38ca215 100644 --- a/gcc/rust/ast/rust-stmt.h +++ b/gcc/rust/ast/rust-stmt.h @@ -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 diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index e17e6ea..4bae8c0 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -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 {} diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index ece5299..ae06785 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -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 diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index 14d933b4..03b47b2 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -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; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index c4191ce..a0cfd00 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -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 ()); } diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index f312376..7b24518 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -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; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 1be58ad..38f0c3e 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -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 diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 38384d8..6bfbcfa 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -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); diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc index dc14cb0..d99a3f3 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.cc +++ b/gcc/rust/hir/rust-ast-lower-stmt.cc @@ -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 diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index 814425c..7a1ebe6 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -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; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 1824545..f19434d 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -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)); } diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 71f0ff1..a092290 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -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 ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 55883e9..6caa9e3 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -587,11 +587,7 @@ ResolverBase::visit (AST::LetStmt &) {} void -ResolverBase::visit (AST::ExprStmtWithoutBlock &) -{} - -void -ResolverBase::visit (AST::ExprStmtWithBlock &) +ResolverBase::visit (AST::ExprStmt &) {} void diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index 20e3be1..327ee70 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -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 &); diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 39864c3..52404f6 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -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); } diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index bd17920..3c628d0 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -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); } diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index a396b7d..9f1fc0d 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -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); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index bba4d12..64f82c1 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -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 diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index 58f0311..bd635f2 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -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); |