aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-27 13:17:31 +0000
committerGitHub <noreply@github.com>2022-07-27 13:17:31 +0000
commit50ca4b2ba0028945fd1a0aefec739ea99f77e908 (patch)
tree9fcd846c7a445a139cade5728e3e77b1513857fb /gcc
parentd94d5b1ea23220d423fd40bd00cadb0e6ede751f (diff)
parent5556d29f7bc0836f2ed6413c04eca3ae055c18d7 (diff)
downloadgcc-50ca4b2ba0028945fd1a0aefec739ea99f77e908.zip
gcc-50ca4b2ba0028945fd1a0aefec739ea99f77e908.tar.gz
gcc-50ca4b2ba0028945fd1a0aefec739ea99f77e908.tar.bz2
Merge #1378
1378: hir/dump: simple dumping of crate attrs and adding a few todos r=CohenArthur a=ndrwnaguib This is draft PR to track the current implementation of the pretty dumping of HIR. `@CohenArthur` and I have agreed to keep it as simple as possible for now, and enhancements will be added along the way. Co-authored-by: andrewnaguib <24280372+ndrwnaguib@users.noreply.github.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc96
-rw-r--r--gcc/rust/hir/rust-hir-dump.h2
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 006a254..f6786f8 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 &)
{}
@@ -268,8 +329,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 af104da..a108c5c 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;