aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-11 11:01:52 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-13 09:54:32 +0000
commit92898b2903528fc3747d561f26df7f6d70d0a3b3 (patch)
treeae7eaa341663e658907c0e6bd74a275f7e901d13 /gcc
parenta6405f1438b2868418f94cc1673001ca2b50a65c (diff)
downloadgcc-92898b2903528fc3747d561f26df7f6d70d0a3b3.zip
gcc-92898b2903528fc3747d561f26df7f6d70d0a3b3.tar.gz
gcc-92898b2903528fc3747d561f26df7f6d70d0a3b3.tar.bz2
Fix bug parsing while loop expressions
If a while loop is part of an expression it needs to know it does not need to skip token.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h39
-rw-r--r--gcc/rust/parse/rust-parse.h7
2 files changed, 32 insertions, 14 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 437a7b5..bd41ce3 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -2666,7 +2666,7 @@ Parser<ManagedTokenSource>::parse_generic_params ()
}
std::unique_ptr<AST::LifetimeParam> param (
- new AST::LifetimeParam (std::move (lifetime),
+ new AST::LifetimeParam (std::move (lifetime),
std::move (lifetime_bounds),
std::move (outer_attr), locus));
generic_params.push_back (std::move (param));
@@ -3167,9 +3167,9 @@ Parser<ManagedTokenSource>::parse_lifetime_param ()
// TODO: have end token passed in?
}
- return AST::LifetimeParam (std::move (lifetime),
- std::move (lifetime_bounds),
- std::move (outer_attr), lifetime_tok->get_locus ());
+ return AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds),
+ std::move (outer_attr),
+ lifetime_tok->get_locus ());
}
// Parses type generic parameters. Will also consume any trailing comma.
@@ -3698,7 +3698,7 @@ Parser<ManagedTokenSource>::parse_trait_bound ()
* handle this) */
std::vector<AST::LifetimeParam> for_lifetimes;
if (lexer.peek_token ()->get_id () == FOR)
- for_lifetimes = parse_for_lifetimes ();
+ for_lifetimes = parse_for_lifetimes ();
// handle TypePath
AST::TypePath type_path = parse_type_path ();
@@ -7879,14 +7879,30 @@ Parser<ManagedTokenSource>::parse_loop_expr (
template <typename ManagedTokenSource>
std::unique_ptr<AST::WhileLoopExpr>
Parser<ManagedTokenSource>::parse_while_loop_expr (
- std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label)
+ std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label,
+ bool pratt_parse)
{
Location locus = Linemap::unknown_location ();
- if (label.is_error ())
- locus = lexer.peek_token ()->get_locus ();
+ if (!pratt_parse)
+ {
+ if (label.is_error ())
+ locus = lexer.peek_token ()->get_locus ();
+ else
+ locus = label.get_locus ();
+
+ if (!skip_token (WHILE))
+ {
+ skip_after_end_block ();
+ return nullptr;
+ }
+ }
else
- locus = label.get_locus ();
- skip_token (WHILE);
+ {
+ if (label.is_error ())
+ locus = lexer.peek_token ()->get_locus () - 1;
+ else
+ locus = label.get_locus ();
+ }
// ensure it isn't a while let loop
if (lexer.peek_token ()->get_id () == LET)
@@ -12454,6 +12470,9 @@ Parser<ManagedTokenSource>::null_denotation (
case LOOP:
return parse_loop_expr (std::move (outer_attrs), AST::LoopLabel::error (),
true);
+ case WHILE:
+ return parse_while_loop_expr (std::move (outer_attrs),
+ AST::LoopLabel::error (), true);
case MATCH_TOK:
// also an expression with block
return parse_match_expr (std::move (outer_attrs), true);
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index e691c9e..0708068 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -504,10 +504,9 @@ private:
std::unique_ptr<AST::LoopExpr> parse_loop_expr (
std::vector<AST::Attribute> outer_attrs = std::vector<AST::Attribute> (),
AST::LoopLabel label = AST::LoopLabel::error (), bool pratt_parse = false);
- std::unique_ptr<AST::WhileLoopExpr>
- parse_while_loop_expr (std::vector<AST::Attribute> outer_attrs
- = std::vector<AST::Attribute> (),
- AST::LoopLabel label = AST::LoopLabel::error ());
+ std::unique_ptr<AST::WhileLoopExpr> parse_while_loop_expr (
+ std::vector<AST::Attribute> outer_attrs = std::vector<AST::Attribute> (),
+ AST::LoopLabel label = AST::LoopLabel::error (), bool pratt_parse = false);
std::unique_ptr<AST::WhileLetLoopExpr>
parse_while_let_loop_expr (std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> (),