From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id D4C4D3888C57 for ; Fri, 23 Jul 2021 11:19:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4C4D3888C57 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x433.google.com with SMTP id b9so1123656wrx.12 for ; Fri, 23 Jul 2021 04:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=Nb7sWGWS4o79KpwSeGLynKt8LrvyPdfE3MDMQcEjkvs=; b=Aucg9SXnVOJNo2WjcqJg3DQjFd5loS9ZEauaKN1nO9NR1bXfkDXqdLRES0dtk6d1/f 6xqLjnz9MSwPEXfeo1ugVFO3T/bdfyVWD545Dv19ZQFh+KlQY3OblZjVOyX2+0ZZJvgR Itv96pFrsLJ27iSArlWkGVGVZ/gIpv3UI5X5R70/AnSD/9vLErlGzb4ZfvXpMIUGKZVb a3WOQetR6TJVK4OVO7KQqYa/Apl33W18KIhvxL2p5wm8vE+ganbOvUIDrEAGXqeECnuc wPJUzy5MbS3pc2t05jl2cP4KMq0ainuIrrp2lTtELGvAZsmVzphctacR/u/f7sgG/UMo mDDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=Nb7sWGWS4o79KpwSeGLynKt8LrvyPdfE3MDMQcEjkvs=; b=hulqOi4VGhlTJGgQi9SHeRqYWu/MRkeHFjCz9NKDyc4a2QJQF/u5U1Z2iGLHhQVyTu S+15n7kdbM7htlYoEXcIQnIho/dbbmegr9PsLWE1foGWPq3AuDCuX3GHBfPaGNoih9BJ ZkiEDhRF/15uCLkXpNuZkgmrRq4UW1UR07FO+iJ374HG7ywY5gWMx2UfDE0BTCYAIRHb BytjIKedFeFYtopIUSnPs9bXDR/UcOcghnZZMrPwOPZzaBB6jeJCzxeVZYAYTIWbBz3X mO6K5FzrE4C8l0kP6gTUwZmzkuc3A/1sMqzopsbyxwDeYiDV5P3t3rQmr14D0ubL/o4z Bhjw== X-Gm-Message-State: AOAM531fVBgDDdjO8EnswShoy8H3TvhwPjZfpwmIRSebfvSNY0wFd/S1 D1lWQ8NVSnPFTFHQ1HiubWND8KzCB1rI2A== X-Google-Smtp-Source: ABdhPJwvtiy3fS4gHbA/loX+zsGvmk+xilwURSyk+jUZTgKOHZry1HDlw9s2muLnkCvNxIBdPuotPQ== X-Received: by 2002:a05:6000:52:: with SMTP id k18mr4646533wrx.270.1627039192816; Fri, 23 Jul 2021 04:19:52 -0700 (PDT) Received: from [192.168.0.40] ([86.14.124.218]) by smtp.gmail.com with ESMTPSA id l3sm4883245wmq.2.2021.07.23.04.19.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Jul 2021 04:19:52 -0700 (PDT) Subject: Re: [PATCH 1/2] Better union support in the parser To: gcc-rust@gcc.gnu.org References: <20210722231902.7401-1-mark@klomp.org> <20210722231902.7401-2-mark@klomp.org> From: Philip Herron Message-ID: Date: Fri, 23 Jul 2021 12:19:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210722231902.7401-2-mark@klomp.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wiJCSWARbqL5cvV7k8yQocYmLpFcEy6CI" X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2021 11:19:55 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --wiJCSWARbqL5cvV7k8yQocYmLpFcEy6CI Content-Type: multipart/mixed; boundary="NtzaCFkUG41GNGV6KdVQlLLJ7LSUJzpHs"; protected-headers="v1" From: Philip Herron To: gcc-rust@gcc.gnu.org Message-ID: Subject: Re: [PATCH 1/2] Better union support in the parser References: <20210722231902.7401-1-mark@klomp.org> <20210722231902.7401-2-mark@klomp.org> In-Reply-To: <20210722231902.7401-2-mark@klomp.org> --NtzaCFkUG41GNGV6KdVQlLLJ7LSUJzpHs Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US 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-par= se-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::parse_item (bool call= ed_from_statement) > // crappy hack to do union "keyword" > case IDENTIFIER: > // TODO: ensure std::string and literal comparison works > - if (t->get_str () =3D=3D "union") > + if (t->get_str () =3D=3D "union" > + && lexer.peek_token (1)->get_id () =3D=3D IDENTIFIER) > { > return parse_vis_item (std::move (outer_attrs)); > // or should this go straight to parsing union? > @@ -1274,8 +1275,8 @@ Parser::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 () =3D=3D "union") > + if (t->get_str () =3D=3D "union" > + && lexer.peek_token (1)->get_id () =3D=3D 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::parse_union (AST::Vis= ibility vis, > const_TokenPtr union_keyword =3D expect_token (IDENTIFIER); > rust_assert (union_keyword->get_str () =3D=3D "union"); > Location locus =3D union_keyword->get_locus (); > - lexer.skip_token (); > =20 > // parse actual union name > const_TokenPtr union_name_tok =3D expect_token (IDENTIFIER); > @@ -6054,8 +6054,8 @@ Parser::parse_stmt () > break; > // crappy hack to do union "keyword" > case IDENTIFIER: > - // TODO: ensure std::string and literal comparison works > - if (t->get_str () =3D=3D "union") > + if (t->get_str () =3D=3D "union" > + && lexer.peek_token (1)->get_id () =3D=3D IDENTIFIER) > { > return parse_vis_item (std::move (outer_attrs)); > // or should this go straight to parsing union? > @@ -11674,8 +11674,8 @@ Parser::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 () =3D=3D "union") > + if (t->get_str () =3D=3D "union" > + && lexer.peek_token (1)->get_id () =3D=3D IDENTIFIER) > { > std::unique_ptr item ( > parse_vis_item (std::move (outer_attrs))); Looks great, I will merge this now. --Phil --NtzaCFkUG41GNGV6KdVQlLLJ7LSUJzpHs-- --wiJCSWARbqL5cvV7k8yQocYmLpFcEy6CI Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsD5BAABCAAjFiEET83ATZOayqRjyL0Cr7gxHEFOdpkFAmD6pdcFAwAAAAAACgkQr7gxHEFOdpl8 AgwAsAuhacCkBhE8cm2hputmd+PG3V4Kd9nSYI8kBTc6bTrrKHlz69VRLi1NEeZ3IVap+xQA5cMk WSgulL9L2UCSBozkiz0ixIp9MkquJDHw7SNS7ZFcLNhflazxVKtH3M9iC7a1XDBIyJodBtjrNWq1 uxnr17oHu2iSvQGaHzmryyv1Afm36nRh1QDycx9SAZzBOuTL1oaMzP+N1LqPQ13UI7u/mrmhydYh dspr/IMFwaWFQp+67vYSVXDJpOSIn9hLD1G90+BjRTWxn8v1+SCUNRQszKxX3yQKXpX5e0G5YMxg /KannpcyfpFR+bIC4T7NS5NBVhppvWwbbYblhE5EK/XYi83Cec1EyRxptNWQ0WPSRnw3SVaW9Tcu /+vAgS7Vmfh/hMmBQ7GSSa9I6+QmSS2O54PcrHEYuaDGL6qrKVVwNefjuriz2a8m8cTdTgcOCkYF glBGPFr90Tj2szHPPv64oWhMGhPO3yC108pB0rwcxAsCpxwTr3453Otr2Zry =ytmY -----END PGP SIGNATURE----- --wiJCSWARbqL5cvV7k8yQocYmLpFcEy6CI--