diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-07-23 13:55:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 13:55:51 +0000 |
commit | afd9db6f6b28d273434b0c61ec0b1aa0dcc4c89f (patch) | |
tree | 1a12af0f69b1b8f12166afa7a0f83d2136fe8a23 /gcc/rust/parse/rust-parse-impl.h | |
parent | 44472c580cedd836081c82e621482e479a69729c (diff) | |
parent | 17fcb1a3bad0c281e9d8c789455025dd9232081b (diff) | |
download | gcc-afd9db6f6b28d273434b0c61ec0b1aa0dcc4c89f.zip gcc-afd9db6f6b28d273434b0c61ec0b1aa0dcc4c89f.tar.gz gcc-afd9db6f6b28d273434b0c61ec0b1aa0dcc4c89f.tar.bz2 |
Merge #590
590: Better union support in the parser r=philberty a=philberty
union is a weak keyword which means it isn't reserved and can be used
as a generic identifier. When we see an identifier where a union could
be declared we check whether the identifier is "union", but only when
the next token is also an identifier. In parse_union we shouldn't skip
the first identifier token, because it is already skipped when we call
expect_token.
Co-authored-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index bdf1e09..3996ef2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1083,7 +1083,8 @@ Parser<ManagedTokenSource>::parse_item (bool called_from_statement) // crappy hack to do union "keyword" case IDENTIFIER: // TODO: ensure std::string and literal comparison works - if (t->get_str () == "union") + if (t->get_str () == "union" + && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); // or should this go straight to parsing union? @@ -1274,8 +1275,8 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec outer_attrs) // TODO: implement union keyword but not really because of // context-dependence case UNION: crappy hack to do union "keyword" case IDENTIFIER: - // TODO: ensure std::string and literal comparison works - if (t->get_str () == "union") + if (t->get_str () == "union" + && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_union (std::move (vis), std::move (outer_attrs)); // or should item switch go straight to parsing union? @@ -4524,7 +4525,6 @@ Parser<ManagedTokenSource>::parse_union (AST::Visibility vis, const_TokenPtr union_keyword = expect_token (IDENTIFIER); rust_assert (union_keyword->get_str () == "union"); Location locus = union_keyword->get_locus (); - lexer.skip_token (); // parse actual union name const_TokenPtr union_name_tok = expect_token (IDENTIFIER); @@ -6054,8 +6054,8 @@ Parser<ManagedTokenSource>::parse_stmt () break; // crappy hack to do union "keyword" case IDENTIFIER: - // TODO: ensure std::string and literal comparison works - if (t->get_str () == "union") + if (t->get_str () == "union" + && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); // or should this go straight to parsing union? @@ -11674,8 +11674,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block () } // crappy hack to do union "keyword" case IDENTIFIER: - // TODO: ensure std::string and literal comparison works - if (t->get_str () == "union") + if (t->get_str () == "union" + && lexer.peek_token (1)->get_id () == IDENTIFIER) { std::unique_ptr<AST::VisItem> item ( parse_vis_item (std::move (outer_attrs))); |