[gcc r14-7642] gccrs: ast: dump literals correctly
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:49:54 GMT 2024
https://gcc.gnu.org/g:d4ac20b6b426f92d536806ecbb05722570a2e605
commit r14-7642-gd4ac20b6b426f92d536806ecbb05722570a2e605
Author: Charalampos Mitrodimas <charmitro@gmail.com>
Date: Sat Jun 3 18:09:26 2023 +0000
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 -> '<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>
Diff:
---
gcc/rust/ast/rust-ast-dump.cc | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index f44bb07c915..d486b1deb8b 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
More information about the Gcc-cvs
mailing list