From patchwork Tue Jan 30 12:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 194076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1182200dyb; Tue, 30 Jan 2024 04:26:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSoIXdyE4G89TSu+f0r9YHwfBX4IKr4z1rs+8rfk8ReMlZWrXo5OfbTFwVEesXf3sArThE X-Received: by 2002:ac8:7d88:0:b0:42a:75e6:6594 with SMTP id c8-20020ac87d88000000b0042a75e66594mr1162307qtd.18.1706617594156; Tue, 30 Jan 2024 04:26:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617594; cv=pass; d=google.com; s=arc-20160816; b=u+kshxLydMtTyQcAMmUmJwyZbsbXDvbtpxn522HD2orRBjlw9djFtLBKEVNwuHBhrS XbFspOK+nRo5mwA5EVwdHutATlriPi81hY4FaMfENyAFYAqSBH9yTuyfXvRkn2RQsDSG cgF6sUlkII1aVrKhpvKW8TiLMajuu3AiLVlXC1YGnPMs32FH1Vx5UPpoXpaObcT9Lwzj 3td3+jF76Rmwt+BrVAe63yOoCi+q2XviDj9FGgOn2fqElZz6EfJVmdhFkBbxf8Ta+hXg 3i4U7bnly3MUblckP0L+4MSmsRZP2A39ZffvdTt2LvIP2K56f72+8cFejoecUBXolD39 Ub3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=pM95hFU5oiyqIxzv4O4c5hGB3ZdxfRx9o5up0a86vxw=; fh=s1GzlUPo1djGkCl3rkRJI30hDOSCVwGp0RAbVwQ8dxQ=; b=iVksvyNHWBDzkZRMPwJ6IUH2CBmjdv5qH4bV4wRcQaBICDE23qoiisc/rQhyEy8I1O rNwvO4n1gXYNqKsFt562DfgoIxzk8InoduZg1UnuH0ejDVBKO91k2Esk/qNrcw8RRva6 gXB1kYfR+Gpx9HNcJktsRAtbQf43TNee5sfVnMrZ3F71DvZcelJIwlXK6/SnqS0VacVC xqZ5YMWCmxwLKm3NSwsY27T3suJ92Tr0a43ND88+AwVVf4K6ZwzYzyBvrrqNOMlzhcZF U4PbTkpn/3KYkHg+ostsjNiJUFCIh5ZAB3rfeC0ublv0o16DjE2NRXDAsOSIddK25Kmt YsSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ddh4xPKA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i7-20020ac85c07000000b0042a5f965469si9888386qti.143.2024.01.30.04.26.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:26:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ddh4xPKA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26BF8386103A for ; Tue, 30 Jan 2024 12:26:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 0910F3858015 for ; Tue, 30 Jan 2024 12:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0910F3858015 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0910F3858015 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616690; cv=none; b=dQOzoHK1EXvnF3TN7wTM/KqCMCGIH1qBIoralqa7JvVhMMJREAW1MOPDeGSPFr5Vor+XvSALkZCRjDlUgcoYG3fEOpLydvNgGrh0SXf7IM6ksGIr5+/6DXTOL0u+7LcKEkf9pElGcrgLVzvqlcgcfx1V5MpHbKuCCSvwNIpT7zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616690; c=relaxed/simple; bh=n0qlva23R/mdGvhF3Fg8aIAaJq/ktFxYKViE1JDxF2g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mVqtdnMYDoefBGJ6q77GZ61H2A+qSqvnUVX6KT+lDPUBCdp/MamS95ecSC8CeD6Fjjo4D2GOA251I0KDesN3gaN2PpM4++vA1lOlex6fV9Qi7YXinL1boa70Ed0c1t0gaE3O34cwQtwhlCayy81eTEkxUZwuCM2WMh6fQB/qV7M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2cf2fdd518bso34998721fa.1 for ; Tue, 30 Jan 2024 04:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=pM95hFU5oiyqIxzv4O4c5hGB3ZdxfRx9o5up0a86vxw=; b=ddh4xPKAr7R+8Ns8sOvmB81BWR6W0e7OPm8g9v9Gx1SNEKMyvhdrGEaYSFyWR/VYCY yFpbLDtchh9maV7yVwpTN8H+ZmHrnSX0QuoNan2CG17ItcnAcxQ89WZVrCYoeKnszLqO RFKaUPd8fi91uZcqQN/qXZZBeooKGPp2EUJ9EtfcuUlypHYShlXJ+AcpQwCAkEmMm+A2 iFjDDEq/3Aui/7uIkmjiYEGnB3y0rzHA+FS8LvJhx57wvK+PhkRWIJGmLkkMJVwZa2KU aLaQeZ8nEMvk9PQJ9M9wpPJVXMsfQRxnsTVjAqBXgDO9InjuW6exE0z9XiOYqv7A9xpC mSwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pM95hFU5oiyqIxzv4O4c5hGB3ZdxfRx9o5up0a86vxw=; b=pUR8dfoRvsAX+NEPIwice7PxWKZldr6uRcqBbKRk+G2LU35ANFdns1jeXkqal58pEV shMx07AtaFB7xtucLDz/kV3Tb3Zmo8kduM9oJdVmvJ5aOj6P1ymQM4JE+qDrDv6TG2oY C5DbW9mQ+R/Zjs7jOmcTssP22RDYbMgfUUsxnZmkbZ5o0gIwpQ97ZbJQLTc2zmor/eU1 YeApDxR/Qyg4ZONHMM6saYurc4Zl9K8XIT6A00cfP/EDEZ27eO69LIbyXrTLNVHAPJZv 3I4y1NXVlD2cfQS/J97c/7kZCXo31Gna1xfR8Qt/K+bJeLB42yvybiQ9nQwXjobiN+kk Xlgg== X-Gm-Message-State: AOJu0Yzue+KjgUTNDR34fOR6x5fTpiMlHrdpHzBjCI2C6sR7JGxJRZ2A Vm+Dmldl8glaR3kK8mUDfFs48ywNfaWcP4zr1GTzEWfwj7mDi0NQbUzl6Nnly1Pb5T74jCMIjzH ImA== X-Received: by 2002:a2e:9b8e:0:b0:2ce:c0f:4b6 with SMTP id z14-20020a2e9b8e000000b002ce0c0f04b6mr5597708lji.39.1706616673438; Tue, 30 Jan 2024 04:11:13 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:12 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 030/101] gccrs: Replace some weak keyword raw value with constexpr Date: Tue, 30 Jan 2024 13:06:46 +0100 Message-ID: <20240130121026.807464-33-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789518250590097530 X-GMAIL-MSGID: 1789518250590097530 From: Pierre-Emmanuel Patry Raw values may have typos or contain error, replacing those will improve the codebase. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value. * parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise. (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_macro_rules_def): Likewise. (Parser::parse_union): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_stmt): Likewise. (Parser::parse_stmt_or_expr): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 6 ++++-- gcc/rust/parse/rust-parse-impl.h | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 5b12875c349..3e3a959578e 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -1875,7 +1875,8 @@ TokenCollector::visit (Union &union_item) { visit_items_as_lines (union_item.get_outer_attrs ()); auto id = union_item.get_identifier ().as_string (); - push (Rust::Token::make_identifier (union_item.get_locus (), "union")); + push (Rust::Token::make_identifier (union_item.get_locus (), + Values::WeakKeywords::UNION)); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); if (union_item.has_generics ()) @@ -2256,7 +2257,8 @@ TokenCollector::visit (MacroRulesDefinition &rules_def) auto rule_name = rules_def.get_rule_name ().as_string (); - push (Rust::Token::make_identifier (rules_def.get_locus (), "macro_rules")); + push (Rust::Token::make_identifier (rules_def.get_locus (), + Values::WeakKeywords::MACRO_RULES)); push (Rust::Token::make (EXCLAM, UNDEF_LOCATION)); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (rule_name))); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 28659060568..37eddc1b753 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1085,7 +1085,7 @@ Parser::is_macro_rules_def (const_TokenPtr t) bool allowed_macro_name = (macro_name == IDENTIFIER || macro_name == TRY); - return t->get_str () == "macro_rules" + return t->get_str () == Values::WeakKeywords::MACRO_RULES && lexer.peek_token (1)->get_id () == EXCLAM && allowed_macro_name; } @@ -1146,13 +1146,13 @@ Parser::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 () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); // or should this go straight to parsing union? } - else if (t->get_str () == "default" + else if (t->get_str () == Values::WeakKeywords::DEFAULT && lexer.peek_token (1)->get_id () != EXCLAM) { add_error (Error (t->get_locus (), @@ -1357,7 +1357,7 @@ 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: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_union (std::move (vis), std::move (outer_attrs)); @@ -1436,7 +1436,8 @@ Parser::parse_macro_rules_def (AST::AttrVec outer_attrs) { // ensure that first token is identifier saying "macro_rules" const_TokenPtr t = lexer.peek_token (); - if (t->get_id () != IDENTIFIER || t->get_str () != "macro_rules") + if (t->get_id () != IDENTIFIER + || t->get_str () != Values::WeakKeywords::MACRO_RULES) { Error error ( t->get_locus (), @@ -4734,7 +4735,7 @@ Parser::parse_union (AST::Visibility vis, /* hack - "weak keyword" by finding identifier called "union" (lookahead in * item switch) */ const_TokenPtr union_keyword = expect_token (IDENTIFIER); - rust_assert (union_keyword->get_str () == "union"); + rust_assert (union_keyword->get_str () == Values::WeakKeywords::UNION); location_t locus = union_keyword->get_locus (); // parse actual union name @@ -5715,7 +5716,7 @@ Parser::parse_trait_impl_item () // semi return parse_macro_invocation_semi (std::move (outer_attrs)); case IDENTIFIER: - if (lexer.peek_token ()->get_str () == "default") + if (lexer.peek_token ()->get_str () == Values::WeakKeywords::DEFAULT) return parse_trait_impl_function_or_method (visibility, std::move (outer_attrs)); else @@ -5779,7 +5780,8 @@ Parser::parse_trait_impl_function_or_method ( auto is_default = false; auto t = lexer.peek_token (); - if (t->get_id () == IDENTIFIER && t->get_str () == "default") + if (t->get_id () == IDENTIFIER + && t->get_str () == Values::WeakKeywords::DEFAULT) { is_default = true; lexer.skip_token (); @@ -6300,7 +6302,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) break; // crappy hack to do union "keyword" case IDENTIFIER: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); @@ -11704,7 +11706,7 @@ Parser::parse_stmt_or_expr () // crappy hack to do union "keyword" case IDENTIFIER: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { std::unique_ptr item ( @@ -11712,7 +11714,7 @@ Parser::parse_stmt_or_expr () return ExprOrStmt (std::move (item)); // or should this go straight to parsing union? } - else if (t->get_str () == "macro_rules" + else if (t->get_str () == Values::WeakKeywords::MACRO_RULES && lexer.peek_token (1)->get_id () == EXCLAM) { // macro_rules! macro item