public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] ast: dump structs, enums and unions
Date: Mon, 10 Oct 2022 07:33:48 +0000 (GMT)	[thread overview]
Message-ID: <20221010073348.74646385829E@sourceware.org> (raw)

https://gcc.gnu.org/g:93937bd6582f3de40a7aefb0c639461a907b3fe1

commit 93937bd6582f3de40a7aefb0c639461a907b3fe1
Author: David Faust <david.faust@oracle.com>
Date:   Thu Oct 6 11:32:17 2022 -0700

    ast: dump structs, enums and unions

Diff:
---
 gcc/rust/ast/rust-ast-dump.cc | 135 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 127 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 6f2f81630b0..7cbdfa21fcb 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -750,35 +750,154 @@ Dump::visit (TypeAlias &type_alias)
 
 void
 Dump::visit (StructStruct &struct_item)
-{}
+{
+  stream << "struct " << struct_item.get_identifier ();
+  if (struct_item.has_generics ())
+    emit_generic_params (struct_item.get_generic_params ());
+
+  // FIXME: where-clause
+
+  stream << " {";
+
+  auto &fields = struct_item.get_fields ();
+
+  indentation.increment ();
+  for (auto &field : fields)
+    {
+      stream << '\n' << indentation;
+      format_struct_field (field);
+      stream << ',';
+    }
+  indentation.decrement ();
+
+  if (fields.size () > 0)
+    stream << '\n' << indentation;
+  stream << "}\n";
+}
 
 void
 Dump::visit (TupleStruct &tuple_struct)
-{}
+{
+  stream << "struct " << tuple_struct.get_identifier ();
+  if (tuple_struct.has_generics ())
+    emit_generic_params (tuple_struct.get_generic_params ());
+
+  // FIXME: where-clause
+
+  stream << '(';
+
+  auto &fields = tuple_struct.get_fields ();
+  if (fields.size () >= 1)
+    {
+      format_tuple_field (fields[0]);
+      for (size_t i = 1; i < fields.size (); i++)
+	{
+	  stream << ", ";
+	  format_tuple_field (fields[i]);
+	}
+    }
+  stream << ");\n";
+}
 
 void
 Dump::visit (EnumItem &item)
-{}
+{
+  stream << item.get_identifier ();
+}
 
 void
 Dump::visit (EnumItemTuple &item)
-{}
+{
+  stream << item.get_identifier () << '(';
+  auto &fields = item.get_tuple_fields ();
+  if (fields.size () >= 1)
+    {
+      format_tuple_field (fields[0]);
+      for (size_t i = 1; i < fields.size (); i++)
+	{
+	  stream << ", ";
+	  format_tuple_field (fields[i]);
+	}
+    }
+  stream << ')';
+}
 
 void
 Dump::visit (EnumItemStruct &item)
-{}
+{
+  stream << item.get_identifier () << " {";
+
+  auto &fields = item.get_struct_fields ();
+
+  indentation.increment ();
+  for (auto &field : fields)
+    {
+      stream << '\n' << indentation;
+      format_struct_field (field);
+      stream << ',';
+    }
+  indentation.decrement ();
+
+  if (fields.size () > 0)
+    stream << '\n' << indentation;
+  stream << '}';
+}
 
 void
 Dump::visit (EnumItemDiscriminant &item)
-{}
+{
+  stream << item.get_identifier () << " = ";
+  item.get_expr ()->accept_vis (*this);
+}
 
 void
 Dump::visit (Enum &enum_item)
-{}
+{
+  stream << "enum " << enum_item.get_identifier ();
+  if (enum_item.has_generics ())
+    emit_generic_params (enum_item.get_generic_params ());
+
+  // FIXME: where-clause
+
+  stream << " {";
+  auto &variants = enum_item.get_variants ();
+  if (variants.size () >= 1)
+    {
+      stream << '\n';
+      indentation.increment ();
+      for (auto &var : variants)
+	{
+	  stream << indentation;
+	  var->accept_vis (*this);
+	  stream << ",\n";
+	}
+      indentation.decrement ();
+    }
+
+  stream << "}\n";
+}
 
 void
 Dump::visit (Union &union_item)
-{}
+{
+  stream << "union " << union_item.get_identifier ();
+  if (union_item.has_generics ())
+    emit_generic_params (union_item.get_generic_params ());
+
+  // FIXME: where-clause
+
+  stream << " {";
+  indentation.increment ();
+  for (auto &field : union_item.get_variants ())
+    {
+      stream << '\n' << indentation;
+      format_struct_field (field);
+      stream << ',';
+    }
+  indentation.decrement ();
+
+  stream << '\n' << indentation << "}\n";
+}
 
 void
 Dump::visit (ConstantItem &const_item)

                 reply	other threads:[~2022-10-10  7:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010073348.74646385829E@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).