aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast-dump.cc
diff options
context:
space:
mode:
authorCharalampos Mitrodimas <charmitro@gmail.com>2023-06-03 18:09:26 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-06-06 12:46:02 +0000
commite11efa45bf12142b0599f017a8f07a1817375703 (patch)
tree466e95562f42083a90eec26cc8005ad26e67ee08 /gcc/rust/ast/rust-ast-dump.cc
parentcc09d0bf04fd87afb9f2b717d485a380a05e0a73 (diff)
downloadgcc-e11efa45bf12142b0599f017a8f07a1817375703.zip
gcc-e11efa45bf12142b0599f017a8f07a1817375703.tar.gz
gcc-e11efa45bf12142b0599f017a8f07a1817375703.tar.bz2
ast: dump literals correctly
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>
Diffstat (limited to 'gcc/rust/ast/rust-ast-dump.cc')
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc29
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index c00ed65..5d59611 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -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