https://gcc.gnu.org/g:e50983a756329b2e27359a523d0ff1609c22aaa1

commit r15-8223-ge50983a756329b2e27359a523d0ff1609c22aaa1
Author: Marc Poulhiès <d...@kataplop.net>
Date:   Sun Jun 30 23:11:17 2024 +0200

    rust: fix HIR dump for MatchExpr
    
    The visitor was still using the as_string() method.
    
    gcc/rust/ChangeLog:
    
            * hir/rust-hir-dump.cc (Dump::do_matcharm): New.
            (Dump::do_matchcase): New.
            (Dump::visit(MatchExpr)): Adjust, don't use as_string.
            * hir/rust-hir-dump.h (Dump::do_matcharm, Dump::do_matchcase): New.
    
    Signed-off-by: Marc Poulhiès <d...@kataplop.net>

Diff:
---
 gcc/rust/hir/rust-hir-dump.cc | 43 ++++++++++++++++++++++++++++++++++++-------
 gcc/rust/hir/rust-hir-dump.h  |  2 ++
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index f0fd9141f5e8..4ae9cba858d1 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -352,6 +352,31 @@ Dump::do_expr (Expr &e)
   do_outer_attrs (oa);
 }
 
+void
+Dump::do_matcharm (MatchArm &e)
+{
+  begin ("MatchArm");
+  // FIXME Can't remember how to handle that. Let's see later.
+  // do_outer_attrs(e);
+  visit_collection ("match_arm_patterns", e.get_patterns ());
+  visit_field ("guard_expr", e.get_guard_expr ());
+  end ("MatchArm");
+}
+
+void
+Dump::do_matchcase (HIR::MatchCase &e)
+{
+  begin ("MatchCase");
+
+  begin_field ("arm");
+  do_matcharm (e.get_arm ());
+  end_field ("arm");
+
+  visit_field ("expr", e.get_expr ());
+
+  end ("MatchCase");
+}
+
 void
 Dump::do_pathexpr (PathExpr &e)
 {
@@ -1437,16 +1462,20 @@ Dump::visit (MatchExpr &e)
   begin ("MatchExpr");
   do_inner_attrs (e);
   do_expr (e);
+
   visit_field ("branch_value", e.get_scrutinee_expr ());
 
-  std::string str;
-  if (e.get_match_cases ().empty ())
-    str = "none";
+  if (!e.has_match_arms ())
+    {
+      put_field ("match_arms", "empty");
+    }
   else
-    for (const auto &arm : e.get_match_cases ())
-      str += "\n " + arm.as_string ();
-  put_field ("match_arms", str);
-
+    {
+      begin_field ("match_arms");
+      for (auto &arm : e.get_match_cases ())
+       do_matchcase (arm);
+      end_field ("match_arms");
+    }
   end ("MatchExpr");
 }
 
diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h
index bb5c3606b51a..b3a2020742fd 100644
--- a/gcc/rust/hir/rust-hir-dump.h
+++ b/gcc/rust/hir/rust-hir-dump.h
@@ -100,6 +100,8 @@ private:
   void do_structfield (StructField &);
   void do_maybenamedparam (MaybeNamedParam &);
   void do_struct (Struct &);
+  void do_matcharm (MatchArm &);
+  void do_matchcase (MatchCase &);
 
   void visit (AST::Attribute &attribute);
   virtual void visit (Lifetime &) override;

Reply via email to