diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-03-27 15:41:47 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:28:42 +0100 |
commit | 7adb5516b5825816ff1883c23d1ee33982043fcc (patch) | |
tree | d2ec5f08b705d35f367386cff36312cbac594bd4 | |
parent | ecbbfce5c566526b0e1eab5c9b9b1676c7dc450f (diff) | |
download | gcc-7adb5516b5825816ff1883c23d1ee33982043fcc.zip gcc-7adb5516b5825816ff1883c23d1ee33982043fcc.tar.gz gcc-7adb5516b5825816ff1883c23d1ee33982043fcc.tar.bz2 |
gccrs: token: Add type hints to string dump
The conversion to string of any known type literal was not giving back
any type hint, not even quotes for string. This commit fix this.
gcc/rust/ChangeLog:
* lex/rust-token.cc (Token::as_string): Add type hint output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/lex/rust-token.cc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc index a99593a..e539706 100644 --- a/gcc/rust/lex/rust-token.cc +++ b/gcc/rust/lex/rust-token.cc @@ -137,7 +137,31 @@ Token::as_string () const { if (should_have_str ()) { - return get_str (); + switch (get_id ()) + { + case STRING_LITERAL: + return "\"" + get_str () + "\""; + case BYTE_STRING_LITERAL: + return "b\"" + get_str () + "\""; + case CHAR_LITERAL: + return "'" + get_str () + "'"; + case BYTE_CHAR_LITERAL: + return "b'" + get_str () + "'"; + case LIFETIME: + return "''" + get_str (); + case INT_LITERAL: + if (get_type_hint () == CORETYPE_UNKNOWN) + return get_str (); + else + return get_str () + get_type_hint_str (); + case FLOAT_LITERAL: + if (get_type_hint () == CORETYPE_UNKNOWN) + return get_str (); + else + return get_str () + get_type_hint_str (); + default: + return get_str (); + } } else { |