Skip to content

Commit

Permalink
rust: fix HIR dump for MatchExpr
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dkm committed Jul 2, 2024
1 parent 7fd14aa commit 12be7fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
43 changes: 36 additions & 7 deletions gcc/rust/hir/rust-hir-dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
}

Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/hir/rust-hir-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Dump : public HIRFullVisitor
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;
Expand Down

0 comments on commit 12be7fa

Please sign in to comment.