aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-hir-dump.cc
diff options
context:
space:
mode:
authorJiakun Fan <120090316@link.cuhk.edu.cn>2023-03-14 17:49:33 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-03-17 16:38:54 +0000
commitbe27571c110d99fe55324a9c2b6622787b08fb52 (patch)
tree78a7d323da24a29bfc1ffc7524e9249c112351ef /gcc/rust/hir/rust-hir-dump.cc
parent04b04f7a0394c566d2958d457a92b1ad44043c5b (diff)
downloadgcc-be27571c110d99fe55324a9c2b6622787b08fb52.zip
gcc-be27571c110d99fe55324a9c2b6622787b08fb52.tar.gz
gcc-be27571c110d99fe55324a9c2b6622787b08fb52.tar.bz2
Feat: add visit (AST::Attribute &)
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::go): fix format (Dump::visit):impl `visit (AST::Attribute &)` and `visit (Lifetime &)` * hir/rust-hir-dump.h:add `visit (AST::Attribute &)` Signed-off-by: Jiakun Fan <120090316@link.cuhk.edu.cn>
Diffstat (limited to 'gcc/rust/hir/rust-hir-dump.cc')
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc71
1 files changed, 54 insertions, 17 deletions
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index f2df4a0..1585df5 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -51,7 +51,9 @@ Dump::go (HIR::Crate &crate)
stream << std::endl;
item->accept_vis (*this);
}
+ stream << std::endl;
stream << indentation;
+
stream << "]," << std::endl;
indentation.decrement ();
//
@@ -66,8 +68,39 @@ Dump::go (HIR::Crate &crate)
}
void
-Dump::visit (Lifetime &)
-{}
+Dump::visit (AST::Attribute &attribute)
+{
+ std::string path_str = attribute.get_path ().as_string ();
+ stream << path_str;
+ if (attribute.has_attr_input ())
+ stream << attribute.get_attr_input ().as_string ();
+}
+
+void
+Dump::visit (Lifetime &lifetime)
+{
+ if (lifetime.is_error ())
+ {
+ stream << "error lifetime";
+ return;
+ }
+
+ switch (lifetime.get_lifetime_type ())
+ {
+ case AST::Lifetime::LifetimeType::NAMED:
+ stream << "'" << lifetime.get_name ();
+ break;
+ case AST::Lifetime::LifetimeType::STATIC:
+ stream << "'static";
+ break;
+ case AST::Lifetime::LifetimeType::WILDCARD:
+ stream << "'_";
+ break;
+ default:
+ stream << "ERROR-MARK-STRING: lifetime type failure";
+ break;
+ }
+}
void
Dump::visit (LifetimeParam &)
{}
@@ -235,44 +268,48 @@ Dump::visit (ClosureExpr &)
void
Dump::visit (BlockExpr &block_expr)
{
- stream << "BlockExpr: [";
- indentation.increment ();
- stream << std::endl;
+ stream << "BlockExpr: [\n";
+ indentation.increment ();
// TODO: inner attributes
- stream << std::string (indent, indent_char);
- stream << "inner attributes: ";
if (!block_expr.inner_attrs.empty ())
{
- for (const auto &attr : block_expr.inner_attrs)
+ stream << indentation << "inner_attrs: [";
+ indentation.increment ();
+ for (auto &attr : block_expr.inner_attrs)
{
- stream << std::endl;
- stream << std::string (indent, indent_char);
- stream << attr.as_string ();
- // stream << attr.accept_vis(*self);
+ stream << "\n";
+ stream << indentation;
+ visit (attr);
}
+ indentation.decrement ();
+ stream << "\n" << indentation << "]\n";
}
- stream << std::endl;
-
// statements
+ // impl null pointer check
+
if (block_expr.has_statements ())
{
auto &stmts = block_expr.get_statements ();
for (auto &stmt : stmts)
{
stream << indentation << "Stmt: {\n";
- // stream << indentation;
stmt->accept_vis (*this);
stream << "\n";
stream << indentation << "}\n";
}
}
- // // TODO: print tail expression if exists
+ // final expression
+ if (block_expr.has_expr ())
+ {
+ stream << indentation << "final expression:";
+ stream << "\n" << indentation << block_expr.expr->as_string ();
+ }
indentation.decrement ();
- stream << indentation << "]";
+ stream << "\n" << indentation << "]";
}
void