From patchwork Tue Jan 30 12:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=NglV2Ex2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TPPkY69c0z23fD for ; Tue, 30 Jan 2024 23:34:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF8E7386F474 for ; Tue, 30 Jan 2024 12:34:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 6835F38582A5 for ; Tue, 30 Jan 2024 12:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6835F38582A5 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 6835F38582A5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; cv=none; b=rfS56xz82g+Qm/c+7vYxfn0RdaFLfN2W3r2xQvjUY8vFWIx4LNKQwIMU2p6Fc6KbuXu3lWoWLwZtttRlM6BfWzGe+MYXk3ocTphxtuH2T8i7MBFOFRgMamPToo5oJUytrS+c7qV97LCRwkBIKh9D2SR4fj6owtlKPJjEzs8CCtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; c=relaxed/simple; bh=MtXUyebEhxYk2gyiVidZgZdy4bpAKRXtvnGMbYDaDrs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KBOfED3ebANFgdwmja9qu9r0G97a40wrlQruC18bDuxOc39WcOd+FISi+lFuoBJFshkrK+OrPFxrWocznyBoFr1tx8d2K12ciyila0B2+QejEGoeRx12BYvKyFMsmWiOjbY8cT1EcNVOK0bmV7WVxQOh/bsd4sEmU2zRCrpCev8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33ae7ae1c32so1688920f8f.3 for ; Tue, 30 Jan 2024 04:11:15 -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=+HHNBziI5JY3AI0XuA626L38zneN3r0M1gj9ZNQjrGg=; b=NglV2Ex2Q8spjW7ieBWNlFX/yab113kQGWtSiHT4DAwrbD/LFPsex7g/i/LdWDJT7e TJefwIzC5ZEADa3uCXk0gKcwP7sX8OClUe8kR4Qsupo9wKjr8F4JIcE/G5IDLXaB7tE6 7RQ382nZMlMQdy+TfMiCe6vRYGf9FfsM//kTkHWGQJAt+MU4cG13SiZNAkwq2DBHxaz0 Pfr638q35NIX/4Sv0np5eml0/zycHnfLN5ik/mxUDeDeQDyQgznWH2e7ne83c6pVzO6t qjcqJ8o4BMNb6/RiIFWMsD3Pyufb3K4Cgf8E9Wv5cWAOytCJYJEJRYABBUV/b+lZ6IJI gVaA== 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=+HHNBziI5JY3AI0XuA626L38zneN3r0M1gj9ZNQjrGg=; b=a97XQs5/JUd7XjgvqO022PL02l2CFPFMAj9vQeZOJnmcnLnpcHqoro4R/i0I5y1Zf9 jR/Dm+B2PH29dFiT+i6zgJVT5cTOU+k0vQQ40mVO0UHXkm9eup6SOfXCOXuX5B/84esT 2m3pzRxU/SOK1nNw716FOJq/KCDEDEIXyeXyXwfpBwQtNnFH9UARJ9Zh/UH9A/c6s8gL Zv0oe8XAeyp3jWihFXbc1v9tYX3gEJwU4DLD+9zNATp8A2GFvhf5uG5bON8il8raeMI/ ea8u7pTXEW8ZXBXVt/6YY8FnHqQnRT6AN6hmThDW74gxnhnpEmJ8KriW3BO4JmssDy1G LN6g== X-Gm-Message-State: AOJu0YziqcegRRQQcFzl02040RMG1mjMlM+DCbHVcJ6tyUgEx0jCGLWZ h6Rg6StIIJUcIi2+CQMt0aeHQrbGoWE/vJgCXUhePrBFUBy/3XKumtlcsEIaN09YjY6DOp+PZDu JXQ== X-Google-Smtp-Source: AGHT+IFToWlkUixWIY56O3E4qyQ8z73rVVWrs6BM1UiKII+NGKNsEY6rQdQGdosiL+FMRFBlUhHBHw== X-Received: by 2002:a05:6000:1565:b0:33a:f00c:cb5 with SMTP id 5-20020a056000156500b0033af00c0cb5mr4452907wrz.6.1706616673872; 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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 031/101] gccrs: Introduce a proper keyword list Date: Tue, 30 Jan 2024 13:06:47 +0100 Message-ID: <20240130121026.807464-34-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+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Pierre-Emmanuel Patry The old "keyword" list was used for the lexer, and could therefore not be used with keyword spanning over multiple tokens as those tokens should remain lexed as is. Hence the introduction of a new list macro for keyword exclusive tasks. This also means we can no longer match a token id for each keyword. The token id map has been renamed to keep it's properties. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name. * lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated comments. * util/rust-keyword-values.cc (get_keywords): Update the keyword map name. (RS_TOKEN): Define as empty (RS_TOKEN_KEYWORD_2015): Add the emission value. (RS_TOKEN_KEYWORD_2018): Likewise. * util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword list. (RS_TOKEN_KEYWORD_2018): Define multiple new keywords. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-lex.cc | 2 +- gcc/rust/lex/rust-token.h | 2 -- gcc/rust/util/rust-keyword-values.cc | 13 ++++++++++++- gcc/rust/util/rust-keyword-values.h | 13 +++++++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 2d41c114f73..5bff2d9125c 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -260,7 +260,7 @@ Lexer::replace_current_token (TokenPtr replacement) TokenId Lexer::classify_keyword (const std::string &str) { - auto &keywords = Rust::Values::Keywords::keywords; + auto &keywords = Rust::Values::Keywords::keywords_tokens; auto keyword = keywords.find (str); if (keyword == keywords.end ()) diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index e38c3cf9943..438b29b4957 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -145,7 +145,6 @@ enum PrimitiveCoreType /* Doc Comments */ \ RS_TOKEN (INNER_DOC_COMMENT, "#![doc]") \ RS_TOKEN (OUTER_DOC_COMMENT, "#[doc]") \ - /* have "weak" union and 'static keywords? */ \ RS_TOKEN_KEYWORD_2015 (ABSTRACT, "abstract") /* unused */ \ RS_TOKEN_KEYWORD_2015 (AS, "as") \ RS_TOKEN_KEYWORD_2018 (ASYNC, "async") /* unused */ \ @@ -157,7 +156,6 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD_2015 (CONST, "const") \ RS_TOKEN_KEYWORD_2015 (CONTINUE, "continue") \ RS_TOKEN_KEYWORD_2015 (CRATE, "crate") \ - /* FIXME: Do we need to add $crate (DOLLAR_CRATE) as a reserved kw? */ \ RS_TOKEN_KEYWORD_2015 (DO, "do") /* unused */ \ RS_TOKEN_KEYWORD_2018 (DYN, "dyn") \ RS_TOKEN_KEYWORD_2015 (ELSE, "else") \ diff --git a/gcc/rust/util/rust-keyword-values.cc b/gcc/rust/util/rust-keyword-values.cc index 8aa5ef1371a..9e1d2bcdef6 100644 --- a/gcc/rust/util/rust-keyword-values.cc +++ b/gcc/rust/util/rust-keyword-values.cc @@ -38,7 +38,18 @@ get_keywords () return m; } -const std::map Keywords::keywords = get_keywords (); +const std::map Keywords::keywords_tokens + = get_keywords (); + +const std::set Keywords::keywords = { +#define RS_TOKEN(x, y) +#define RS_TOKEN_KEYWORD_2015(tok, key) {key}, +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 + RS_KEYWORD_LIST +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 +#undef RS_TOKEN +}; } // namespace Values } // namespace Rust diff --git a/gcc/rust/util/rust-keyword-values.h b/gcc/rust/util/rust-keyword-values.h index 4a6f1df525d..01c98a2cde4 100644 --- a/gcc/rust/util/rust-keyword-values.h +++ b/gcc/rust/util/rust-keyword-values.h @@ -21,6 +21,14 @@ #include "rust-token.h" +// Append keywords made from multiple tokens to the existing token-keyword list +#define RS_KEYWORD_LIST \ + RS_TOKEN_LIST \ + RS_TOKEN_KEYWORD_2015 (DOLLAR_CRATE, "$crate") \ + RS_TOKEN_KEYWORD_2015 (PATH_ROOT, "{{root}}") \ + RS_TOKEN_KEYWORD_2015 (STATIC_LIFETIME, "'static") \ + RS_TOKEN_KEYWORD_2015 (UNDERSCORE_LIFETIME, "'_") + namespace Rust { namespace Values { @@ -28,14 +36,15 @@ namespace Values { class Keywords { public: - const static std::map keywords; + const static std::map keywords_tokens; + const static std::set keywords; // Rust keyword values public: #define RS_TOKEN(x, y) #define RS_TOKEN_KEYWORD_2015(tok, key) static constexpr auto &tok = key; #define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 - RS_TOKEN_LIST + RS_KEYWORD_LIST #undef RS_TOKEN_KEYWORD_2015 #undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN