]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: dump literals correctly
authorCharalampos Mitrodimas <charmitro@gmail.com>
Sat, 3 Jun 2023 18:09:26 +0000 (18:09 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:24 +0000 (18:46 +0100)
This commit fixes printing of literals based on their
type.

Previous implementation printed literals the same, regardless
their type. Now we are printing:
  * int, float, bool don't require special printing
  * char        -> '<char>'
  * string      -> "<string>"
  * byte        -> b'<byte>'
  * byte_string -> b"<byte_string>"

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit):
print literals based on their type.

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
gcc/rust/ast/rust-ast-dump.cc

index f44bb07c915f5eb0c7491fbe99be8e07a3b8627e..d486b1deb8bab3ca6099f8f76c810fbbcf81db13 100644 (file)
@@ -507,7 +507,34 @@ Dump::visit (QualifiedPathInType &path)
 void
 Dump::visit (LiteralExpr &expr)
 {
-  stream << expr.as_string ();
+  switch (expr.get_lit_type ())
+    {
+    case Literal::CHAR:
+      stream << "'" << expr.as_string () << "'";
+      return;
+
+    case Literal::STRING:
+      stream << "\"" << expr.as_string () << "\"";
+      return;
+
+    case Literal::BYTE:
+      stream << "b'" << expr.as_string () << "'";
+      return;
+
+    case Literal::BYTE_STRING:
+      stream << "b\"" << expr.as_string () << "\"";
+      return;
+
+    case Literal::INT:
+    case Literal::FLOAT:
+    case Literal::BOOL:
+      stream << expr.as_string ();
+      return;
+
+    case Literal::ERROR:
+      stream << "/*ERROR*/";
+      return;
+    }
 }
 
 void