aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-keyword-values.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-08 14:54:51 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:13:13 +0100
commite50b0969b8eb69afd5432fc4aee1434974275067 (patch)
treec34d8a03aa19a82cef6948bc2e428a69bbd7e29b /gcc/rust/util/rust-keyword-values.cc
parent8f41baaa832a480338b7a4d686d4b26000164588 (diff)
downloadgcc-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/util/rust-keyword-values.cc')
-rw-r--r--gcc/rust/util/rust-keyword-values.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/gcc/rust/util/rust-keyword-values.cc b/gcc/rust/util/rust-keyword-values.cc
index 29bc65e..58a404d 100644
--- a/gcc/rust/util/rust-keyword-values.cc
+++ b/gcc/rust/util/rust-keyword-values.cc
@@ -17,17 +17,26 @@
// <http://www.gnu.org/licenses/>.
#include "rust-keyword-values.h"
+#include "rust-token.h"
namespace Rust {
namespace Values {
-const std::set<std::string> Keywords::keywords = {
+// TODO: Can't we do this inline ?
+static std::map<std::string, TokenId>
+get_keywords ()
+{
+ std::map<std::string, TokenId> m = {
#define RS_TOKEN(x, y)
-#define RS_TOKEN_KEYWORD(tok, key) key,
- RS_TOKEN_LIST
+#define RS_TOKEN_KEYWORD(tok, key) {key, tok},
+ RS_TOKEN_LIST
#undef RS_TOKEN_KEYWORD
#undef RS_TOKEN
-};
+ };
+ return m;
+}
+
+const std::map<std::string, TokenId> Keywords::keywords = get_keywords ();
} // namespace Values
} // namespace Rust