[gcc r14-7429] gccrs: lex: Add source code token string representation
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:33:59 GMT 2024
https://gcc.gnu.org/g:1a20b5b1165f43ac9db6cfa62afe91031c2a717b
commit r14-7429-g1a20b5b1165f43ac9db6cfa62afe91031c2a717b
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Mon Mar 27 12:54:53 2023 +0200
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>
Diff:
---
gcc/rust/lex/rust-token.cc | 13 +++++++++++++
gcc/rust/lex/rust-token.h | 4 ++++
2 files changed, 17 insertions(+)
diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc
index b0589b1ea70..a99593ae686 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 356f30cc189..65a37fdb0d0 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
More information about the Gcc-cvs
mailing list