public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Dump InherentImpl
@ 2022-06-08 12:52 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2ad8ec6da7a871debda2e4ce94a63696b7d43422

commit 2ad8ec6da7a871debda2e4ce94a63696b7d43422
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu Jun 2 16:37:23 2022 +0200

    ast: Dump InherentImpl

Diff:
---
 gcc/rust/ast/rust-ast-dump.cc | 83 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 72 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 64966c9d2ec..c23720b59d1 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -102,7 +102,9 @@ Dump::visit (TypePathSegmentFunction &segment)
 
 void
 Dump::visit (TypePath &path)
-{}
+{
+  stream << path.as_string ();
+}
 
 void
 Dump::visit (QualifiedPathInExpression &path)
@@ -253,8 +255,8 @@ Dump::visit (BlockExpr &expr)
   if (expr.has_tail_expr ())
     expr.get_tail_expr ()->accept_vis (*this);
 
-  stream << "\n}\n";
-  indentation.increment ();
+  indentation.decrement ();
+  stream << "\n" << indentation << "}\n";
 }
 
 void
@@ -364,7 +366,10 @@ Dump::visit (AsyncBlockExpr &expr)
 // rust-item.h
 void
 Dump::visit (TypeParam &param)
-{}
+{
+  // Is it possible to have a null type here?
+  param.get_type ()->accept_vis (*this);
+}
 
 void
 Dump::visit (LifetimeWhereClauseItem &item)
@@ -376,7 +381,36 @@ Dump::visit (TypeBoundWhereClauseItem &item)
 
 void
 Dump::visit (Method &method)
-{}
+{
+  stream << indentation << "fn " << method.get_method_name () << '(';
+
+  auto &self = method.get_self_param ();
+  stream << self.as_string ();
+
+  auto &params = method.get_function_params ();
+  for (auto &param : params)
+    {
+      stream << ", ";
+      format_function_param (param);
+    }
+
+  stream << ") ";
+
+  if (method.has_return_type ())
+    {
+      stream << "-> ";
+      method.get_return_type ()->accept_vis (*this);
+      stream << " ";
+    }
+
+  auto &block = method.get_definition ();
+  if (!block)
+    stream << ';';
+  else
+    block->accept_vis (*this);
+
+  stream << '\n';
+}
 
 void
 Dump::visit (Module &module)
@@ -405,7 +439,7 @@ Dump::visit (UseDeclaration &use_decl)
 void
 Dump::visit (Function &function)
 {
-  stream << "fn " << function.get_function_name () << '(';
+  stream << indentation << "fn " << function.get_function_name () << '(';
 
   auto &params = function.get_function_params ();
   if (params.size () >= 1)
@@ -424,6 +458,7 @@ Dump::visit (Function &function)
     {
       stream << "-> ";
       function.get_return_type ()->accept_vis (*this);
+      stream << " ";
     }
 
   auto &block = function.get_definition ();
@@ -501,7 +536,25 @@ Dump::visit (Trait &trait)
 
 void
 Dump::visit (InherentImpl &impl)
-{}
+{
+  stream << "impl ";
+
+  // FIXME: Handle generics
+
+  impl.get_type ()->accept_vis (*this);
+
+  // FIXME: Handle where-clause
+  // FIXME: Handle inner attributes
+
+  stream << " {\n";
+  indentation.increment ();
+
+  for (auto &item : impl.get_impl_items ())
+    item->accept_vis (*this);
+
+  indentation.decrement ();
+  stream << "\n}\n";
+}
 
 void
 Dump::visit (TraitImpl &impl)
@@ -728,19 +781,27 @@ Dump::visit (RawPointerType &type)
 
 void
 Dump::visit (ReferenceType &type)
-{}
+{
+  type.get_type_referenced ()->accept_vis (*this);
+}
 
 void
 Dump::visit (ArrayType &type)
-{}
+{
+  type.get_elem_type ()->accept_vis (*this);
+}
 
 void
 Dump::visit (SliceType &type)
-{}
+{
+  type.get_elem_type ()->accept_vis (*this);
+}
 
 void
 Dump::visit (InferredType &type)
-{}
+{
+  stream << "_";
+}
 
 void
 Dump::visit (BareFunctionType &type)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:52 [gcc/devel/rust/master] ast: Dump InherentImpl Thomas Schwinge

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).