diff options
author | Matthew Jasper <mjjasper1@gmail.com> | 2023-05-09 12:53:33 +0100 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-05-15 14:48:41 +0000 |
commit | 4cd88c4cd60bce7a2fd14191334a56ab08ea5181 (patch) | |
tree | 059e2a37d4ab5b4c5728a952c5da12149a2c7a2a /gcc/rust/parse/rust-parse-impl.h | |
parent | 142b84e3c56252004348f57c0822dca39d437395 (diff) | |
download | gcc-4cd88c4cd60bce7a2fd14191334a56ab08ea5181.zip gcc-4cd88c4cd60bce7a2fd14191334a56ab08ea5181.tar.gz gcc-4cd88c4cd60bce7a2fd14191334a56ab08ea5181.tar.bz2 |
ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction
This distinction isn't very helpful and makes correct parsing harder.
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* ast/rust-stmt.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
(class ExprStmt):
Make non-abstract, add common functionality from removed base classes.
* ast/rust-ast.h: Move to_stmt to base class.
* ast/rust-ast.cc (ExprStmtWithBlock::as_string): Remove.
* ast/rust-macro.h: Use new signature for to_stmt.
(ExprStmt::as_string): New method.
(ExprStmtWithoutBlock::as_string): Remove.
(BlockExpr::strip_tail_expr): Update for removed classes.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
(ExprStmt::accept_vis): New method.
* ast/rust-ast-dump.cc (Dump::visit): Update for removed classes.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-collector.cc (TokenStream::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h: Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
* hir/rust-ast-lower-stmt.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_match_expr): Likewise.
(Parser::parse_stmt_or_expr_without_block): Likewise.
* parse/rust-parse.h: Likewise.
Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 87 |
1 files changed, 32 insertions, 55 deletions
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)); } |