aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2023-10-16 14:42:49 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:09:20 +0100
commit3b1d27f78720bf4cf3857f31a4d26226e2581fb1 (patch)
tree73ddf9a35bf03586194d48e18d2edc6e2e61f63a /gcc/rust/parse
parent9e7e3ea6380d4c8fe01740ce5278e84d2124fe93 (diff)
downloadgcc-3b1d27f78720bf4cf3857f31a4d26226e2581fb1.zip
gcc-3b1d27f78720bf4cf3857f31a4d26226e2581fb1.tar.gz
gcc-3b1d27f78720bf4cf3857f31a4d26226e2581fb1.tar.bz2
gccrs: ast: Parse labelled block
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (AstBuilder::block): Add label arg to constructor call. * ast/rust-expr.h (class LoopLabel): Move before BlockExpr. (class BlockExpr): Add LoopLabel member. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Add label arg to constructor call. * parse/rust-parse-impl.h (Parser::parse_block_expr): Add label parameter. (Parser::parse_labelled_loop_expr): Add label arg to constructor call. * parse/rust-parse.h: Add label arg to constructor call. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h12
-rw-r--r--gcc/rust/parse/rust-parse.h7
2 files changed, 12 insertions, 7 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 1e59913..7844f72 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -7359,6 +7359,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
template <typename ManagedTokenSource>
std::unique_ptr<AST::BlockExpr>
Parser<ManagedTokenSource>::parse_block_expr (AST::AttrVec outer_attrs,
+ AST::LoopLabel label,
location_t pratt_parsed_loc)
{
location_t locus = pratt_parsed_loc;
@@ -7425,8 +7426,8 @@ Parser<ManagedTokenSource>::parse_block_expr (AST::AttrVec outer_attrs,
return std::unique_ptr<AST::BlockExpr> (
new AST::BlockExpr (std::move (stmts), std::move (expr),
- std::move (inner_attrs), std::move (outer_attrs), locus,
- end_locus));
+ std::move (inner_attrs), std::move (outer_attrs),
+ std::move (label), locus, end_locus));
}
/* Parses a "grouped" expression (expression in parentheses), used to control
@@ -8367,7 +8368,7 @@ Parser<ManagedTokenSource>::parse_for_loop_expr (AST::AttrVec outer_attrs,
// Parses a loop expression with label (any kind of loop - disambiguates).
template <typename ManagedTokenSource>
-std::unique_ptr<AST::BaseLoopExpr>
+std::unique_ptr<AST::Expr>
Parser<ManagedTokenSource>::parse_labelled_loop_expr (const_TokenPtr tok,
AST::AttrVec outer_attrs)
{
@@ -8419,6 +8420,8 @@ Parser<ManagedTokenSource>::parse_labelled_loop_expr (const_TokenPtr tok,
return parse_while_loop_expr (std::move (outer_attrs),
std::move (label));
}
+ case LEFT_CURLY:
+ return parse_block_expr (std::move (outer_attrs), std::move (label));
default:
// error
add_error (Error (t->get_locus (),
@@ -12537,7 +12540,8 @@ Parser<ManagedTokenSource>::null_denotation_not_path (
return parse_continue_expr (std::move (outer_attrs), tok->get_locus ());
case LEFT_CURLY:
// ok - this is an expression with block for once.
- return parse_block_expr (std::move (outer_attrs), tok->get_locus ());
+ return parse_block_expr (std::move (outer_attrs),
+ AST::LoopLabel::error (), tok->get_locus ());
case IF:
// if or if let, so more lookahead to find out
if (lexer.peek_token ()->get_id () == LET)
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index d5c1219..6a69533 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -139,6 +139,7 @@ public:
std::unique_ptr<AST::BlockExpr>
parse_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
+ AST::LoopLabel label = AST::LoopLabel::error (),
location_t pratt_parsed_loc = UNKNOWN_LOCATION);
bool is_macro_rules_def (const_TokenPtr t);
@@ -590,9 +591,9 @@ private:
AST::MatchArm parse_match_arm ();
std::vector<std::unique_ptr<AST::Pattern> >
parse_match_arm_patterns (TokenId end_token_id);
- std::unique_ptr<AST::BaseLoopExpr>
- parse_labelled_loop_expr (const_TokenPtr tok,
- AST::AttrVec outer_attrs = AST::AttrVec ());
+ std::unique_ptr<AST::Expr> parse_labelled_loop_expr (const_TokenPtr tok,
+ AST::AttrVec outer_attrs
+ = AST::AttrVec ());
AST::LoopLabel parse_loop_label (const_TokenPtr tok);
std::unique_ptr<AST::AsyncBlockExpr>
parse_async_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ());