From 1a20b5b1165f43ac9db6cfa62afe91031c2a717b Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 27 Mar 2023 12:54:53 +0200 Subject: 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 --- gcc/rust/lex/rust-token.cc | 13 +++++++++++++ gcc/rust/lex/rust-token.h | 4 ++++ 2 files changed, 17 insertions(+) (limited to 'gcc') 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 -- cgit v1.1