diff options
author | Matthew Jasper <mjjasper1@gmail.com> | 2023-05-10 02:08:37 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:37:19 +0100 |
commit | 48408712cc8cc39cba50c10938a284661ddece87 (patch) | |
tree | 888c170ba2cc16c8868c3359f76b4b27ff7658bf /gcc/rust/hir/tree | |
parent | 9e9ee593cf0507e5b54a556737909a46c6e91319 (diff) | |
download | gcc-48408712cc8cc39cba50c10938a284661ddece87.zip gcc-48408712cc8cc39cba50c10938a284661ddece87.tar.gz gcc-48408712cc8cc39cba50c10938a284661ddece87.tar.bz2 |
gccrs: Fix parsing of block expressions followed by `.`
`{ ... }.f;` is parsed as a single statement in rust. This means that we can't
determine whether an expression statement will need a semicolon terminator
until we finish parsing it. To handle this we change expression parsing to
check for this case by inspecting the expression returned from null_denotation
and looking ahead for a `.` or `?` token.
gcc/rust/ChangeLog:
* ast/rust-ast.h (Expr::as_expr_without_block): Remove.
(Expr::set_outer_attrs): Make public in base class.
* expand/rust-macro-expand.cc:
Add fixme comment for pre-existing bug.
* hir/tree/rust-hir.h: Remove Expr::as_expr_without_block.
* parse/rust-parse-impl.h (Parser::parse_lifetime): Use lifetime_from_token.
(Parser::lifetime_from_token): New method.
(Parser::null_denotation): Handle labelled loop expressions and for loop expressions.
(Parser::parse_loop_label): Make initial token a parameter.
(Parser::parse_labelled_loop_expr): Likewise.
(Parser::parse_for_loop_expr): Allow FOR token to already be skipped.
(Parser::parse_expr): Handle expr_can_be_stmt.
(Parser::parse_expr_with_block): Remove.
(Parser::parse_expr_stmt_with_block): Remove.
(Parser::parse_expr_stmt_without_block): Remove.
(Parser::parse_expr_without_block): Remove.
(Parser::parse_stmt_or_expr_with_block): Remove.
(Parser::parse_expr_stmt): Use parse_expr directly.
(Parser::parse_match_expr): Likewise.
(Parser::parse_stmt): Use parse_expr_stmt in more cases.
(Parser::parse_stmt_or_expr):
Rename from parse_stmt_or_expr_without_block, use parse_expr directly.
(Parser::parse_block_expr): Update error message.
* parse/rust-parse.h: Update declarations.
gcc/testsuite/ChangeLog:
* rust/compile/for_expr.rs: New test.
* rust/compile/issue-407-2.rs: Update compiler output.
* rust/compile/issue-407.rs: Update compiler output.
* rust/compile/issue-867.rs: Update compiler output.
* rust/compile/issue-2189.rs: New test.
* rust/compile/macro_call_statement.rs: New test.
* rust/compile/stmt_with_block_dot.rs: New test.
* rust/compile/torture/loop8.rs: New test.
Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
Diffstat (limited to 'gcc/rust/hir/tree')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 11 |
1 files changed, 0 insertions, 11 deletions
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 31f1494..0258f5f 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -288,10 +288,6 @@ public: return std::unique_ptr<Expr> (clone_expr_impl ()); } - /* HACK: downcasting without dynamic_cast (if possible) via polymorphism - - * overrided in subclasses of ExprWithoutBlock */ - virtual ExprWithoutBlock *as_expr_without_block () const { return nullptr; } - // TODO: make pure virtual if move out outer attributes to derived classes virtual std::string as_string () const; @@ -354,13 +350,6 @@ public: return std::unique_ptr<ExprWithoutBlock> (clone_expr_without_block_impl ()); } - /* downcasting hack from expr to use pratt parsing with - * parse_expr_without_block */ - ExprWithoutBlock *as_expr_without_block () const override - { - return clone_expr_without_block_impl (); - } - BlockType get_block_expr_type () const final override { return BlockType::WITHOUT_BLOCK; |