diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-11-16 16:20:49 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-30 12:36:45 +0100 |
commit | 2c843a047dd3c596b4daabe247e52e1d6475e4d6 (patch) | |
tree | 80c1c2e8003d2caa7bcbad706e10bdd84c165e1c | |
parent | 28652f21e5560123c658d3e11d638957cb344641 (diff) | |
download | gcc-2c843a047dd3c596b4daabe247e52e1d6475e4d6.zip gcc-2c843a047dd3c596b4daabe247e52e1d6475e4d6.tar.gz gcc-2c843a047dd3c596b4daabe247e52e1d6475e4d6.tar.bz2 |
gccrs: Introduce a proper keyword list
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 <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 2 | ||||
-rw-r--r-- | gcc/rust/lex/rust-token.h | 2 | ||||
-rw-r--r-- | gcc/rust/util/rust-keyword-values.cc | 13 | ||||
-rw-r--r-- | 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 2d41c11..5bff2d9 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 e38c3cf..438b29b 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 8aa5ef1..9e1d2bc 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<std::string, TokenId> Keywords::keywords = get_keywords (); +const std::map<std::string, TokenId> Keywords::keywords_tokens + = get_keywords (); + +const std::set<std::string> 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 4a6f1df..01c98a2 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<std::string, TokenId> keywords; + const static std::map<std::string, TokenId> keywords_tokens; + const static std::set<std::string> 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 |