]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: lex: Add source code token string representation
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 27 Mar 2023 10:54:53 +0000 (12:54 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:42 +0000 (18:28 +0100)
Add a new representation for tokens which should reflect the string
token as it could be found in the original source.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Add as_string
implementation.
* lex/rust-token.h: Add as_string prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/lex/rust-token.cc
gcc/rust/lex/rust-token.h

index b0589b1ea70224c34cfdd07d6a516e9a2eb77a9d..a99593ae686fe8aa84a7adb663bd8b9d586ae8f8 100644 (file)
@@ -131,4 +131,17 @@ Token::get_str () const
     }
   return *str;
 }
+
+std::string
+Token::as_string () const
+{
+  if (should_have_str ())
+    {
+      return get_str ();
+    }
+  else
+    {
+      return get_token_description ();
+    }
+}
 } // namespace Rust
index 356f30cc1894989187f0498c8c22633314d818fd..65a37fdb0d0fc9b9e2f9a673c827a8222aca258f 100644 (file)
@@ -443,6 +443,10 @@ return *str;
 
   // Returns whether the token is a pure decimal int literal
   bool is_pure_decimal () const { return type_hint == CORETYPE_PURE_DECIMAL; }
+
+  // Return the token representation as someone would find it in the original
+  // source code file.
+  std::string as_string () const;
 };
 } // namespace Rust