]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Dump inner attrs for Dump::visit(BlockExpr &)
authorJiakun Fan <120090316@link.cuhk.edu.cn>
Sat, 11 Mar 2023 17:47:32 +0000 (17:47 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:21:12 +0000 (18:21 +0100)
Refer to `BlockExpr::as_string ()`, dump inner attrs for `Dump::visit`.
Add visit (AST::Attribute &).

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::go): fix format
(Dump::visit): impl `visit (AST::Attribute &)`, dump inner attrs and
`visit (Lifetime &)`
* hir/rust-hir-dump.h:add `visit (AST::Attribute &)`

Signed-off-by: Jiakun Fan <120090316@link.cuhk.edu.cn>
gcc/rust/hir/rust-hir-dump.cc
gcc/rust/hir/rust-hir-dump.h

index f0d04710466508d905fe7fb2046d834ed5c433dd..65b79f362b1f9c9a26969d02d60bd5cb3af1a46e 100644 (file)
@@ -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,29 +268,48 @@ Dump::visit (ClosureExpr &)
 void
 Dump::visit (BlockExpr &block_expr)
 {
-  stream << "BlockExpr: [";
+  stream << "BlockExpr: [\n";
+
   indentation.increment ();
-  stream << std::endl;
   // TODO: inner attributes
+  if (!block_expr.inner_attrs.empty ())
+    {
+      stream << indentation << "inner_attrs: [";
+      indentation.increment ();
+      for (auto &attr : block_expr.inner_attrs)
+       {
+         stream << "\n";
+         stream << indentation;
+         visit (attr);
+       }
+      indentation.decrement ();
+      stream << "\n" << indentation << "]\n";
+    }
 
   // 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
index 39b8cc010acc01c8a78d39b42c08df47df328ef1..be731700f91956e46e7ebcef08f5043d34bf3caa 100644 (file)
@@ -37,6 +37,7 @@ private:
   Indent indentation;
   std::ostream &stream;
 
+  void visit (AST::Attribute &attribute);
   virtual void visit (Lifetime &) override;
   virtual void visit (LifetimeParam &) override;
   virtual void visit (PathInExpression &) override;