]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust: fix HIR dump for MatchExpr
authorMarc Poulhiès <dkm@kataplop.net>
Sun, 30 Jun 2024 21:11:17 +0000 (23:11 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:52 +0000 (16:35 +0100)
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 <dkm@kataplop.net>
gcc/rust/hir/rust-hir-dump.cc
gcc/rust/hir/rust-hir-dump.h

index f0fd9141f5e8d55ae0fccf299098f263ca48b469..4ae9cba858d18a0f2df772bf6a90018e54adf440 100644 (file)
@@ -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");
 }
 
index bb5c3606b51a92582a9611f02bf25742708cef29..b3a2020742fdb2a1f641e7786f91a418abc1e06a 100644 (file)
@@ -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;