public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] token: Add type hints to string dump
@ 2023-04-06 21:35 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:816ed80ab7c02cf05cdb1e811f230fe25ea9d413

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

    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 a6be8473fe6..35da79e5864 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
     {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-06 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:35 [gcc/devel/rust/master] token: Add type hints to string dump Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).