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] hir/dump: simple dumping of crate attrs and adding a few todos
Date: Wed, 27 Jul 2022 15:53:38 +0000 (GMT)	[thread overview]
Message-ID: <20220727155338.B69CA3857B86@sourceware.org> (raw)

https://gcc.gnu.org/g:5556d29f7bc0836f2ed6413c04eca3ae055c18d7

commit 5556d29f7bc0836f2ed6413c04eca3ae055c18d7
Author: andrewnaguib <24280372+ndrwnaguib@users.noreply.github.com>
Date:   Tue Jul 12 12:04:50 2022 -0700

    hir/dump: simple dumping of crate attrs and adding a few todos

Diff:
---
 gcc/rust/hir/rust-hir-dump.cc | 96 ++++++++++++++++++++++++++++++++++++++-----
 gcc/rust/hir/rust-hir-dump.h  |  2 +
 2 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 506334441fd..6b36920015b 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -21,15 +21,60 @@
 namespace Rust {
 namespace HIR {
 
-Dump::Dump (std::ostream &stream) : stream (stream) {}
+Dump::Dump (std::ostream &stream) : stream (stream), indent (0) {}
 
 void
 Dump::go (HIR::Crate &crate)
 {
-  // TODO: print crate inner_attrs
-  // TODO: print crate items
-  // TODO: print crate mappings
-  stream << crate.as_string ();
+  stream << "Crate"
+	 << " "
+	 << "{" << std::endl;
+  //
+
+  indent++;
+  stream << std::string (indent, indent_char);
+  stream << "inner_attrs"
+	 << ":"
+	 << " "
+	 << "[";
+  for (auto &attr : crate.inner_attrs)
+    stream << attr.as_string ();
+  stream << "]"
+	 << "," << std::endl;
+  indent--;
+
+  indent++;
+  stream << std::string (indent, indent_char);
+  //
+
+  stream << "items"
+	 << ":"
+	 << " "
+	 << "[";
+
+  stream << std::string (indent, indent_char);
+  for (const auto &item : crate.items)
+    {
+      stream << std::endl;
+      item->accept_vis (*this);
+    }
+  stream << std::string (indent, indent_char);
+  stream << "]"
+	 << "," << std::endl;
+  indent--;
+  //
+
+  indent++;
+  stream << std::string (indent, indent_char);
+  stream << "node_mappings"
+	 << ":"
+	 << " "
+	 << "[";
+  // TODO: print crate mapping attrs
+  stream << "]" << std::endl;
+  indent--;
+
+  stream << "}" << std::endl;
 }
 
 void
@@ -64,8 +109,14 @@ Dump::visit (QualifiedPathInType &)
 {}
 
 void
-Dump::visit (LiteralExpr &)
-{}
+Dump::visit (LiteralExpr &literal_expr)
+{
+  indent++;
+  stream << std::string (indent, indent_char);
+  stream << "( " + literal_expr.get_literal ().as_string () + " ("
+	      + literal_expr.get_mappings ().as_string () + "))";
+  stream << "\n";
+}
 void
 Dump::visit (BorrowExpr &)
 {}
@@ -152,8 +203,18 @@ void
 Dump::visit (ClosureExprInner &)
 {}
 void
-Dump::visit (BlockExpr &)
-{}
+Dump::visit (BlockExpr &block_expr)
+{
+  stream << "BlockExpr"
+	 << ":"
+	 << " "
+	 << "[";
+  indent++;
+  // TODO: print statements
+  // TODO: print tail expression if exists
+  stream << "]";
+  indent--;
+}
 void
 Dump::visit (ClosureExprInnerTyped &)
 {}
@@ -264,8 +325,21 @@ void
 Dump::visit (UseDeclaration &)
 {}
 void
-Dump::visit (Function &)
-{}
+Dump::visit (Function &function)
+{
+  indent++;
+  stream << std::string (indent, indent_char);
+  stream << "Function"
+	 << " ";
+  stream << "{" << std::endl;
+  // TODO: print function params
+  stream << std::string (indent, indent_char);
+  stream << "}" << std::endl;
+  // TODO: get function definition and visit block
+
+  stream << std::endl;
+  indent--;
+}
 void
 Dump::visit (TypeAlias &)
 {}
diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h
index 4569c90233b..8905d0ce641 100644
--- a/gcc/rust/hir/rust-hir-dump.h
+++ b/gcc/rust/hir/rust-hir-dump.h
@@ -34,6 +34,8 @@ public:
 
 private:
   std::ostream &stream;
+  std::size_t indent; // current indentation level
+  char indent_char = '\t';
 
   virtual void visit (IdentifierExpr &) override;
   virtual void visit (Lifetime &) override;


                 reply	other threads:[~2022-07-27 15:53 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=20220727155338.B69CA3857B86@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).