From: Charalampos Mitrodimas Date: Sat, 3 Jun 2023 18:09:26 +0000 (+0000) Subject: gccrs: ast: dump literals correctly X-Git-Tag: basepoints/gcc-15~2497 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4ac20b6b426f92d536806ecbb05722570a2e605;p=thirdparty%2Fgcc.git gccrs: 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 -> '' * string -> "" * byte -> b'' * byte_string -> b"" gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): print literals based on their type. Signed-off-by: Charalampos Mitrodimas --- diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index f44bb07c915f..d486b1deb8ba 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