diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-21 17:24:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 17:24:27 +0000 |
commit | cb42c3674a5a9ab77cb0c1216a1b776c323037e2 (patch) | |
tree | 223139b9b80a2c0473cb42c87d7d85fcb33a9f84 /gcc/rust/parse/rust-parse-impl.h | |
parent | fc22f12c9c707b258f35a1bab0e8154441b972b8 (diff) | |
parent | dd9e4c1e0ca0b14388a3cd43f18a4e1a7aebe6e5 (diff) | |
download | gcc-cb42c3674a5a9ab77cb0c1216a1b776c323037e2.zip gcc-cb42c3674a5a9ab77cb0c1216a1b776c323037e2.tar.gz gcc-cb42c3674a5a9ab77cb0c1216a1b776c323037e2.tar.bz2 |
Merge #1144
1144: Add name and type resolution support TuplePatterns in MatchArms r=philberty a=philberty
This adds support for the name and type resolution of match expressions. The code generation
and checks for all cases possible cases needs more thought so this will be done as part of a
separate PR.
Addresses #1081
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c95afd6..25979ce 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8563,7 +8563,11 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs, return nullptr; } - std::unique_ptr<AST::Expr> expr = parse_expr (); + ParseRestrictions restrictions; + restrictions.expr_can_be_stmt = true; + restrictions.consume_semi = false; + + std::unique_ptr<AST::ExprStmt> expr = parse_expr_stmt ({}, restrictions); if (expr == nullptr) { Error error (lexer.peek_token ()->get_locus (), @@ -8573,10 +8577,30 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs, // skip somewhere? return nullptr; } - bool is_expr_without_block = expr->is_expr_without_block (); + bool is_expr_without_block + = expr->get_type () == AST::ExprStmt::ExprStmtType::WITHOUT_BLOCK; // construct match case expr and add to cases - match_arms.push_back (AST::MatchCase (std::move (arm), std::move (expr))); + 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; + + 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; + } // handle comma presence if (lexer.peek_token ()->get_id () != COMMA) @@ -10400,7 +10424,7 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern () // literal pattern return std::unique_ptr<AST::LiteralPattern> ( new AST::LiteralPattern (range_lower->get_str (), type, - range_lower->get_locus (), has_minus)); + range_lower->get_locus ())); } } |