Skip to content

Commit

Permalink
Make DefaultResolver visit more of the AST
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit): Visit inner AST nodes of ClosureExprInner,
	ClosureExprInnerTyped, IfExpr, IfExprConseqElse, MatchExpr,
	PathInExpression, EnumItemTuple, EnumItemStruct, and
	EnumItemDiscriminant.
	* ast/rust-item.h
	(EnumItemDiscriminant::has_expr): New function.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and CohenArthur committed Mar 1, 2024
1 parent 9ee5b51 commit 7064be3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 16 deletions.
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,8 @@ class EnumItemDiscriminant : public EnumItem

void accept_vis (ASTVisitor &vis) override;

bool has_expr () { return expression != nullptr; }

// TODO: is this better? Or is a "vis_block" better?
std::unique_ptr<Expr> &get_expr ()
{
Expand Down
105 changes: 89 additions & 16 deletions gcc/rust/resolve/rust-default-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,43 @@ DefaultResolver::visit (AST::StructExprFieldIndexValue &)
{}

void
DefaultResolver::visit (AST::ClosureExprInner &)
{}
DefaultResolver::visit (AST::ClosureExprInner &expr)
{
if (expr.is_marked_for_strip ())
return;

for (auto &param : expr.get_params ())
{
if (param.is_error ())
continue;

param.get_pattern ()->accept_vis (*this);
if (param.has_type_given ())
param.get_type ()->accept_vis (*this);
}

expr.get_definition_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ClosureExprInnerTyped &)
{}
DefaultResolver::visit (AST::ClosureExprInnerTyped &expr)
{
if (expr.is_marked_for_strip ())
return;

for (auto &param : expr.get_params ())
{
if (param.is_error ())
continue;

param.get_pattern ()->accept_vis (*this);
if (param.has_type_given ())
param.get_type ()->accept_vis (*this);
}

expr.get_definition_block ()->accept_vis (*this);
expr.get_return_type ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ContinueExpr &expr)
Expand Down Expand Up @@ -230,11 +261,18 @@ DefaultResolver::visit (AST::WhileLetLoopExpr &expr)

void
DefaultResolver::visit (AST::IfExpr &expr)
{}
{
expr.get_condition_expr ()->accept_vis (*this);
expr.get_if_block ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::IfExprConseqElse &)
{}
DefaultResolver::visit (AST::IfExprConseqElse &expr)
{
expr.get_condition_expr ()->accept_vis (*this);
expr.get_if_block ()->accept_vis (*this);
expr.get_else_block ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::IfLetExpr &expr)
Expand All @@ -246,7 +284,20 @@ DefaultResolver::visit (AST::IfLetExprConseqElse &)

void
DefaultResolver::visit (AST::MatchExpr &expr)
{}
{
if (expr.is_marked_for_strip ())
return;

expr.get_scrutinee_expr ()->accept_vis (*this);
for (auto &arm : expr.get_match_cases ())
{
arm.get_expr ()->accept_vis (*this);
for (auto &pat : arm.get_arm ().get_patterns ())
pat->accept_vis (*this);
if (arm.get_arm ().has_match_arm_guard ())
arm.get_arm ().get_guard_expr ()->accept_vis (*this);
}
}

void
DefaultResolver::visit (AST::AwaitExpr &expr)
Expand Down Expand Up @@ -277,8 +328,21 @@ DefaultResolver::visit (AST::ConstGenericParam &)
{}

void
DefaultResolver::visit (AST::PathInExpression &)
{}
DefaultResolver::visit (AST::PathInExpression &expr)
{
for (auto &seg : expr.get_segments ())
if (seg.has_generic_args ())
{
auto &args = seg.get_generic_args ();
for (auto &arg : args.get_generic_args ())
arg.accept_vis (*this);
for (auto &arg : args.get_binding_args ())
if (!arg.is_error ())
arg.get_type ()->accept_vis (*this);
for (auto &arg : args.get_lifetime_args ())
arg.accept_vis (*this);
}
}

void
DefaultResolver::visit (AST::TypePathSegmentGeneric &)
Expand Down Expand Up @@ -373,16 +437,25 @@ DefaultResolver::visit (AST::EnumItem &)
{}

void
DefaultResolver::visit (AST::EnumItemTuple &)
{}
DefaultResolver::visit (AST::EnumItemTuple &item)
{
for (auto &field : item.get_tuple_fields ())
field.get_field_type ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::EnumItemStruct &)
{}
DefaultResolver::visit (AST::EnumItemStruct &item)
{
for (auto &field : item.get_struct_fields ())
field.get_field_type ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::EnumItemDiscriminant &)
{}
DefaultResolver::visit (AST::EnumItemDiscriminant &item)
{
if (item.has_expr ())
item.get_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ConstantItem &item)
Expand Down

0 comments on commit 7064be3

Please sign in to comment.