public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7712] gccrs: dump: Add formatting to dump
@ 2024-01-16 17:55 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:55 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:671517fc2e28d7b3f8caa2d2d1b26365285d3d99
commit r14-7712-g671517fc2e28d7b3f8caa2d2d1b26365285d3d99
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Fri Jun 23 14:33:53 2023 +0200
gccrs: dump: Add formatting to dump
Add formatting character output to ast dump.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add comment
after tail expressions.
* ast/rust-ast-dump.cc (Dump::require_spacing): Check for
missing previous token.
* ast/rust-ast-dump.h: Output formatting characters.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/ast/rust-ast-collector.cc | 1 +
gcc/rust/ast/rust-ast-dump.cc | 5 +++++
gcc/rust/ast/rust-ast-dump.h | 35 ++++++++++++++++++++++++++++-------
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 89c693e0891..38eb31780f9 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -1276,6 +1276,7 @@ TokenCollector::visit (BlockExpr &expr)
if (expr.has_tail_expr ())
{
visit (expr.get_tail_expr ());
+ comment ("tail expr");
newline ();
}
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 7c90592ffa3..e8a3c08834c 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -27,6 +27,11 @@ Dump::Dump (std::ostream &stream) : stream (stream), indentation (Indent ()) {}
bool
Dump::require_spacing (TokenPtr previous, TokenPtr current)
{
+ if (previous == nullptr)
+ {
+ return false;
+ }
+
switch (current->get_id ())
{
case EXCLAM:
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index ec72ba14c4a..38df5f3951b 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -44,14 +44,35 @@ public:
TokenCollector collector;
collector.visit (v);
- auto tokens = collector.collect_tokens ();
- if (!tokens.empty ())
- stream << tokens.front ()->as_string ();
- for (auto it = tokens.cbegin () + 1; it < tokens.cend (); it++)
+ TokenPtr previous = nullptr;
+ for (auto item : collector.collect ())
{
- if (require_spacing (*(it - 1), *it))
- stream << " ";
- stream << (*it)->as_string ();
+ switch (item.get_kind ())
+ {
+ case AST::CollectItem::Kind::Token: {
+ TokenPtr current = item.get_token ();
+ if (require_spacing (previous, current))
+ stream << " ";
+ stream << current->as_string ();
+ previous = current;
+ }
+ break;
+ case AST::CollectItem::Kind::Comment:
+ stream << " /* " << item.get_comment () << " */ ";
+ break;
+ case AST::CollectItem::Kind::Indentation:
+ for (size_t i = 0; i < item.get_indent_level (); i++)
+ {
+ stream << " ";
+ }
+ break;
+ case AST::CollectItem::Kind::Newline:
+ stream << "\n";
+ previous = nullptr;
+ break;
+ default:
+ gcc_unreachable ();
+ }
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:55 [gcc r14-7712] gccrs: dump: Add formatting to dump Arthur Cohen
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).