diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-03-27 12:54:53 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:28:42 +0100 |
commit | 1a20b5b1165f43ac9db6cfa62afe91031c2a717b (patch) | |
tree | 170c6e0d2d7c5814a64825a8fbcf2aeb1d7b1922 | |
parent | 1bc67e50e3f77081e5593e7c5e77ed3a2a816755 (diff) | |
download | gcc-1a20b5b1165f43ac9db6cfa62afe91031c2a717b.zip gcc-1a20b5b1165f43ac9db6cfa62afe91031c2a717b.tar.gz gcc-1a20b5b1165f43ac9db6cfa62afe91031c2a717b.tar.bz2 |
gccrs: lex: Add source code token string representation
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>
-rw-r--r-- | gcc/rust/lex/rust-token.cc | 13 | ||||
-rw-r--r-- | gcc/rust/lex/rust-token.h | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc index b0589b1..a99593a 100644 --- a/gcc/rust/lex/rust-token.cc +++ b/gcc/rust/lex/rust-token.cc @@ -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 diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 356f30c..65a37fd 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -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 |