[gcc r14-7431] gccrs: token: Add type hints to string dump

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:34:10 GMT 2024


https://gcc.gnu.org/g:7adb5516b5825816ff1883c23d1ee33982043fcc

commit r14-7431-g7adb5516b5825816ff1883c23d1ee33982043fcc
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Mar 27 15:41:47 2023 +0200

    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>

Diff:
---
 gcc/rust/lex/rust-token.cc | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc
index a99593ae686..e5397067b8a 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
     {


More information about the Gcc-cvs mailing list