From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 1F6DC38582AE for ; Tue, 30 Jan 2024 12:11:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F6DC38582AE 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 1F6DC38582AE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616689; cv=none; b=ia91xFwZIiWrhAl3g2uLEqNfZctWHjmthwU5YvrGi6OsulheCqYP3eFGdjzYphIrWvTNOVmWJLn6yniqbRgNWOt7kfjbSKgE/LVgHJKntwA7I/rTyq+chGNKjFSoxKemh/4FDjyxnZZpQGSeR4PNk8TBNPX3XGRPtCRMvCy8ak8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616689; c=relaxed/simple; bh=n0qlva23R/mdGvhF3Fg8aIAaJq/ktFxYKViE1JDxF2g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GS1E+hXXt84HUMuZkqnud3HXspBIx4C2E0nD4eZgqBD91hJId/z1R0A9SVonwnijJDZlxpgrNqwizwCaTf20kofQ5vjeiZTOOcKGp6jOexEknHODVOq+ZlijLz+aWHLKSKWoonWonBWP8C9/at/09BAMLkrAXRTLnsQS5BMiUnM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2cf206e4d56so41762231fa.3 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=AfH+Nfy8Q/jXohd0GNCzOZfFbRD9dcWRSTg6IxRFc/g/FCmmvNTyvOgjHwpptuFKCz Y5RIpmm/UCuGSvuqYc6UYxJNR4I4FfBlnFGhvg9oG3Qh0QzpAuLtlwCQTY4lP/77YwPX NSoWfxRb44V++qtau6sa2PVEuwBSolOAYQErdx0BqX45qOpIpNxSGe8eGf8PzBWBYvIb ILJK53F2KBH7r7/qYx8zx7O5pCTeKrdBVIOBlszQJwxE4HH7ga+WcSx2UCg65NNt5r0o ciB1a2ztPPVHNayn5YNOVa6m6iUnBXDW3IwFhWSxxUbGBqboOJGyb5g8zypSP0HeGgCa L+KQ== X-Gm-Message-State: AOJu0YwvToRFOQjP0+hM0UEir9J/zZjE3uDT3Legbb55JArOz8jLMFTZ dDeUODqmAc44qnx/2CaMfIw6Iis81Xjo7mQ1elukaYeEYNNfya+BIUj7zyWshrCqnVxtOnYTUbs 1JA== X-Google-Smtp-Source: AGHT+IHTjAEq06qeRkee6iw/Lt9CIvJTYomO5flcZ1sEMxFghMKEeczKwR40R5Rz0GuTb1sYQAAK5A== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 -- 2.42.1