diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-item.h | 2 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-default-resolver.cc | 105 |
2 files changed, 91 insertions, 16 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 0911719..44963ba 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2081,6 +2081,8 @@ public: 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 () { diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 9f7fda4..28f04a1 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -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 ¶m : 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 ¶m : 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) @@ -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) @@ -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) @@ -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 &) @@ -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) |