]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Use keyword const values instead of raw values
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 8 Nov 2023 14:22:33 +0000 (15:22 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:13:13 +0000 (19:13 +0100)
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>
gcc/rust/lex/rust-lex.cc
gcc/rust/parse/rust-parse-impl.h

index cab2abbba5af009cd8acf1e977d11e6d0f3aca21..b78565ec3a57da271502f436188c665b7fdc36b6 100644 (file)
@@ -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 ());
index 260c197c93cef90da171428e97440ba83e512876..21795bb4ca0e81fab21ec98ab3e9c811d13a03a2 100644 (file)
@@ -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)
        {