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: 194112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1187290dyb; Tue, 30 Jan 2024 04:35:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnJ1uDCiCGGvvY0/yVC7cE00i2eb08TqmVmuu9sFexMGPLJ7FdzagbQh4dZYwumo+8lnKv X-Received: by 2002:a05:6122:a1d:b0:4bd:6041:99f9 with SMTP id 29-20020a0561220a1d00b004bd604199f9mr3599447vkn.31.1706618133894; Tue, 30 Jan 2024 04:35:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706618133; cv=pass; d=google.com; s=arc-20160816; b=XA7PNlPsYuWCVLda/0dL3BLz4q+sj/XLsa/rx+HMXObb5TxLK6Jg9fVbb7dDIcGwNY ahI9Wf4Sr1xKt5rp4vNEq51IpbL6ZlKX6JitVjYoUL2Q4viunjPyVqUJELGoNe/FQIXh MtlgxQMArDaF83fYaXm3LbOft/8TFqNDwyxd3VH8qdkqo26tHD3VkUN1v+I3W+AwNnFZ Vmh44LWaqs05+i/IrbpVbM1LHGEFtxMQDWU5qn2UNP3RC9V0Ol2nJoqrTKMNWONG8W2m ZFvRgqwcxW0w51eXH5tZgS8+WqKJX7SKSPtqAp1Hl8bGlLk/xt/xXV1DZa5RJYv6s9xK 570Q== 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=+HHNBziI5JY3AI0XuA626L38zneN3r0M1gj9ZNQjrGg=; fh=s1GzlUPo1djGkCl3rkRJI30hDOSCVwGp0RAbVwQ8dxQ=; b=q0q/5Qmcixm1yVaW0pkjScJI7M40GaSvS2Lf648Q//INDjMc/ZMAdsov5xUT2ppeNZ iKCmGTxpf1Nda9qfXV5zdywnu394Oj3egBZbsZgr64bHe+XpuIshV9zPHqsfN2MM2kCE L+ImbpyxHRNxsXjGMALOv0lRya+VHAwEP7/aRFCM69F8zfRYNlCPDx0l7w2x1lpb9+ce AkRCU3hy1ga3rt8vvXIk25d0ncVbiDCPk/Sy9+OuGhI7ELJsdofJYnjRRyBrx1/+aGlE YOT7iY9SHFEP6MJDmHpM1GeQ7rltPr0aSP5dwLVGLjAOF2yjy8/i+J4hTCGkP0+6WgaY jyrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=NglV2Ex2; 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 gi3-20020a056214248300b0068c46c796d9si5788267qvb.318.2024.01.30.04.35.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:35:33 -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=NglV2Ex2; 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 EB6643857C7E for ; Tue, 30 Jan 2024 12:35:07 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789518816047472459 X-GMAIL-MSGID: 1789518816047472459 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