]> 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)
committerCohenArthur <arthur.cohen@embecosm.com>
Mon, 15 Jul 2024 12:05:54 +0000 (12:05 +0000)
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 bcacc8de968285e1ad4ef22ad17279659b92e711..57500e4169fc302fc6e44acaf4ed2bf05c682ab5 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 afaf92c25c484eecb6f826da8873e73b76efd238..2fe0261a363f5bee2d05dff8ca96822f5dda7985 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;