diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-11-08 14:54:51 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:13:13 +0100 |
commit | e50b0969b8eb69afd5432fc4aee1434974275067 (patch) | |
tree | c34d8a03aa19a82cef6948bc2e428a69bbd7e29b /gcc/rust/lex/rust-lex.cc | |
parent | 8f41baaa832a480338b7a4d686d4b26000164588 (diff) | |
download | gcc-e50b0969b8eb69afd5432fc4aee1434974275067.zip gcc-e50b0969b8eb69afd5432fc4aee1434974275067.tar.gz gcc-e50b0969b8eb69afd5432fc4aee1434974275067.tar.bz2 |
gccrs: Change keyword set to a map
Some part of the code requires the token id behind a given keyword, a map
keep the "set" aspect whilst providing this additional feature.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (RS_TOKEN): Remove local map.
(RS_TOKEN_KEYWORD): Likewise.
(Lexer::classify_keyword): Change call to utils.
* util/rust-keyword-values.cc (get_keywords): Add init function.
(RS_TOKEN_KEYWORD): Call to X macro.
* util/rust-keyword-values.h: Change from set to a map.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/lex/rust-lex.cc')
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 2cfc9ce..cab2abb 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -24,6 +24,7 @@ #include "rust-session-manager.h" #include "safe-ctype.h" #include "cpplib.h" +#include "rust-keyword-values.h" namespace Rust { // TODO: move to separate compilation unit? @@ -254,25 +255,12 @@ Lexer::replace_current_token (TokenPtr replacement) rust_debug ("called 'replace_current_token' - this is deprecated"); } -/* shitty anonymous namespace that can only be accessed inside the compilation - * unit - used for classify_keyword binary search in sorted array of keywords - * created with x-macros. */ -namespace { -// TODO: make constexpr when update to c++20 -const std::map<std::string, TokenId> keywords = { -#define RS_TOKEN(x, y) -#define RS_TOKEN_KEYWORD(tok, key) {key, tok}, - RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD -#undef RS_TOKEN -}; -} // namespace - /* Determines whether the string passed in is a keyword or not. If it is, it * returns the keyword name. */ TokenId Lexer::classify_keyword (const std::string &str) { + auto &keywords = Rust::Values::Keywords::keywords; auto keyword = keywords.find (str); if (keyword == keywords.end ()) |