From: Philip Herron <philip.herron@embecosm.com>
To: gcc-rust@gcc.gnu.org
Subject: Re: [PATCH 1/2] Better union support in the parser
Date: Fri, 23 Jul 2021 12:19:51 +0100 [thread overview]
Message-ID: <b7cff9ce-4030-3ac5-0ca6-3acc9d53a7d3@embecosm.com> (raw)
In-Reply-To: <20210722231902.7401-2-mark@klomp.org>
[-- Attachment #1.1: Type: text/plain, Size: 3245 bytes --]
On 23/07/2021 00:19, Mark Wielaard wrote:
> 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.
> ---
> gcc/rust/parse/rust-parse-impl.h | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
> index bdf1e09a029..3996ef21672 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)));
Looks great, I will merge this now.
--Phil
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 665 bytes --]
next prev parent reply other threads:[~2021-07-23 11:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-22 23:19 union support Mark Wielaard
2021-07-22 23:19 ` [PATCH 1/2] Better union support in the parser Mark Wielaard
2021-07-23 11:19 ` Philip Herron [this message]
2021-07-22 23:19 ` [PATCH 2/2] WIP union hir-lowering and type support Mark Wielaard
2021-07-23 11:19 ` Philip Herron
2021-08-01 11:29 ` Mark Wielaard
2021-08-01 22:37 ` Mark Wielaard
2021-08-02 12:33 ` Thomas Schwinge
2021-08-04 21:04 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b7cff9ce-4030-3ac5-0ca6-3acc9d53a7d3@embecosm.com \
--to=philip.herron@embecosm.com \
--cc=gcc-rust@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).