aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-08 15:22:33 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-11-14 18:27:16 +0000
commitf46fd401949ece4cc691c80a05e0038f715a49c1 (patch)
treecdce316f52e09b4a8398e135053919e552193a0a /gcc
parent8ec6996a74cc33a2034cfb94d0b8acd580eca87c (diff)
downloadgcc-f46fd401949ece4cc691c80a05e0038f715a49c1.zip
gcc-f46fd401949ece4cc691c80a05e0038f715a49c1.tar.gz
gcc-f46fd401949ece4cc691c80a05e0038f715a49c1.tar.bz2
Use keyword const values instead of raw values
Change the keyword values from a raw string value to their matching const value in utils. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value. * parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/lex/rust-lex.cc9
-rw-r--r--gcc/rust/parse/rust-parse-impl.h8
2 files changed, 12 insertions, 5 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 19e2370..ee44e8d 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -1938,8 +1938,13 @@ Lexer::parse_raw_identifier (location_t loc)
rust_error_at (get_current_location (),
"%<_%> is not a valid raw identifier");
- if (str == "crate" || str == "extern" || str == "self" || str == "super"
- || str == "Self")
+ using namespace Rust::Values;
+ std::set<std::string> invalid{
+ Keywords::CRATE, Keywords::EXTERN_TOK, Keywords::SELF,
+ Keywords::SUPER, Keywords::SELF_ALIAS,
+ };
+
+ if (invalid.find (str) != invalid.end ())
{
rust_error_at (get_current_location (),
"%qs is a forbidden raw identifier", str.c_str ());
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index e1d7388..44b4d74 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -28,6 +28,7 @@
#include "rust-make-unique.h"
#include "rust-dir-owner.h"
#include "rust-attribute-values.h"
+#include "rust-keyword-values.h"
#include "optional.h"
@@ -682,6 +683,7 @@ template <typename ManagedTokenSource>
AST::SimplePathSegment
Parser<ManagedTokenSource>::parse_simple_path_segment ()
{
+ using namespace Values;
const_TokenPtr t = lexer.peek_token ();
switch (t->get_id ())
{
@@ -692,15 +694,15 @@ Parser<ManagedTokenSource>::parse_simple_path_segment ()
case SUPER:
lexer.skip_token ();
- return AST::SimplePathSegment ("super", t->get_locus ());
+ return AST::SimplePathSegment (Keywords::SUPER, t->get_locus ());
case SELF:
lexer.skip_token ();
- return AST::SimplePathSegment ("self", t->get_locus ());
+ return AST::SimplePathSegment (Keywords::SELF, t->get_locus ());
case CRATE:
lexer.skip_token ();
- return AST::SimplePathSegment ("crate", t->get_locus ());
+ return AST::SimplePathSegment (Keywords::CRATE, t->get_locus ());
case DOLLAR_SIGN:
if (lexer.peek_token (1)->get_id () == CRATE)
{