@@ -44,6 +44,15 @@ DefaultResolver::visit (AST::BlockExpr &expr)
4444void
4545DefaultResolver::visit (AST ::Module &module )
4646{
47+ // Parse the module's items if they haven't been expanded and the file
48+ // should be parsed (i.e isn't hidden behind an untrue or impossible cfg
49+ // directive
50+ // TODO: make sure this is right
51+ // This was copied from the old early resolver method
52+ // 'accumulate_escaped_macros'
53+ if (module .get_kind () == AST ::Module::UNLOADED )
54+ module .load_items ();
55+
4756 auto item_fn = [this , &module ] () {
4857 for (auto &item : module .get_items ())
4958 item->accept_vis (*this );
@@ -62,12 +71,14 @@ DefaultResolver::visit (AST::Function &function)
6271 if (p->is_variadic ())
6372 {
6473 auto param = static_cast <AST ::VariadicParam *> (p.get ());
65- param->get_pattern ()->accept_vis (*this );
74+ if (param->has_pattern ())
75+ param->get_pattern ()->accept_vis (*this );
6676 }
6777 else if (p->is_self ())
6878 {
6979 auto param = static_cast <AST ::SelfParam *> (p.get ());
70- param->get_type ()->accept_vis (*this );
80+ if (param->has_type ())
81+ param->get_type ()->accept_vis (*this );
7182 param->get_lifetime ().accept_vis (*this );
7283 }
7384 else
@@ -78,6 +89,9 @@ DefaultResolver::visit (AST::Function &function)
7889 }
7990 }
8091
92+ if (function.has_return_type ())
93+ function.get_return_type ()->accept_vis (*this );
94+
8195 if (function.has_body ())
8296 function.get_definition ().value ()->accept_vis (*this );
8397 };
@@ -154,6 +168,19 @@ DefaultResolver::visit (AST::StructStruct &type)
154168 // FIXME: ???
155169}
156170
171+ void
172+ DefaultResolver::visit (AST ::TupleStruct &type)
173+ {
174+ // do we need to scope anything here? no, right?
175+
176+ // we also can't visit `StructField`s by default, so there's nothing to do -
177+ // correct? or should we do something like
178+
179+ AST::DefaultASTVisitor::visit (type);
180+
181+ // FIXME: ???
182+ }
183+
157184void
158185DefaultResolver::visit (AST ::Enum &type)
159186{
@@ -177,12 +204,43 @@ DefaultResolver::visit (AST::StructExprFieldIndexValue &)
177204{}
178205
179206void
180- DefaultResolver::visit (AST ::ClosureExprInner &)
181- {}
207+ DefaultResolver::visit (AST ::ClosureExprInner &expr)
208+ {
209+ if (expr.is_marked_for_strip ())
210+ return ;
211+
212+ for (auto ¶m : expr.get_params ())
213+ {
214+ if (param.is_error ())
215+ continue ;
216+
217+ param.get_pattern ()->accept_vis (*this );
218+ if (param.has_type_given ())
219+ param.get_type ()->accept_vis (*this );
220+ }
221+
222+ expr.get_definition_expr ()->accept_vis (*this );
223+ }
182224
183225void
184- DefaultResolver::visit (AST ::ClosureExprInnerTyped &)
185- {}
226+ DefaultResolver::visit (AST ::ClosureExprInnerTyped &expr)
227+ {
228+ if (expr.is_marked_for_strip ())
229+ return ;
230+
231+ for (auto ¶m : expr.get_params ())
232+ {
233+ if (param.is_error ())
234+ continue ;
235+
236+ param.get_pattern ()->accept_vis (*this );
237+ if (param.has_type_given ())
238+ param.get_type ()->accept_vis (*this );
239+ }
240+
241+ expr.get_definition_block ()->accept_vis (*this );
242+ expr.get_return_type ()->accept_vis (*this );
243+ }
186244
187245void
188246DefaultResolver::visit (AST ::ContinueExpr &expr)
@@ -212,6 +270,36 @@ void
212270DefaultResolver::visit (AST ::ReturnExpr &expr)
213271{}
214272
273+ void
274+ DefaultResolver::visit (AST ::CallExpr &expr)
275+ {
276+ expr.get_function_expr ()->accept_vis (*this );
277+
278+ for (auto ¶m : expr.get_params ())
279+ param->accept_vis (*this );
280+ }
281+
282+ void
283+ DefaultResolver::visit (AST ::MethodCallExpr &expr)
284+ {
285+ expr.get_receiver_expr ()->accept_vis (*this );
286+
287+ if (expr.get_method_name ().has_generic_args ())
288+ {
289+ auto &args = expr.get_method_name ().get_generic_args ();
290+ for (auto &arg : args.get_generic_args ())
291+ arg.accept_vis (*this );
292+ for (auto &arg : args.get_binding_args ())
293+ if (!arg.is_error ())
294+ arg.get_type ()->accept_vis (*this );
295+ for (auto &arg : args.get_lifetime_args ())
296+ arg.accept_vis (*this );
297+ }
298+
299+ for (auto ¶m : expr.get_params ())
300+ param->accept_vis (*this );
301+ }
302+
215303void
216304DefaultResolver::visit (AST ::UnsafeBlockExpr &expr)
217305{}
@@ -230,11 +318,18 @@ DefaultResolver::visit (AST::WhileLetLoopExpr &expr)
230318
231319void
232320DefaultResolver::visit (AST ::IfExpr &expr)
233- {}
321+ {
322+ expr.get_condition_expr ()->accept_vis (*this );
323+ expr.get_if_block ()->accept_vis (*this );
324+ }
234325
235326void
236- DefaultResolver::visit (AST ::IfExprConseqElse &)
237- {}
327+ DefaultResolver::visit (AST ::IfExprConseqElse &expr)
328+ {
329+ expr.get_condition_expr ()->accept_vis (*this );
330+ expr.get_if_block ()->accept_vis (*this );
331+ expr.get_else_block ()->accept_vis (*this );
332+ }
238333
239334void
240335DefaultResolver::visit (AST ::IfLetExpr &expr)
@@ -246,7 +341,20 @@ DefaultResolver::visit (AST::IfLetExprConseqElse &)
246341
247342void
248343DefaultResolver::visit (AST ::MatchExpr &expr)
249- {}
344+ {
345+ if (expr.is_marked_for_strip ())
346+ return ;
347+
348+ expr.get_scrutinee_expr ()->accept_vis (*this );
349+ for (auto &arm : expr.get_match_cases ())
350+ {
351+ arm.get_expr ()->accept_vis (*this );
352+ for (auto &pat : arm.get_arm ().get_patterns ())
353+ pat->accept_vis (*this );
354+ if (arm.get_arm ().has_match_arm_guard ())
355+ arm.get_arm ().get_guard_expr ()->accept_vis (*this );
356+ }
357+ }
250358
251359void
252360DefaultResolver::visit (AST ::AwaitExpr &expr)
@@ -277,8 +385,21 @@ DefaultResolver::visit (AST::ConstGenericParam &)
277385{}
278386
279387void
280- DefaultResolver::visit (AST ::PathInExpression &)
281- {}
388+ DefaultResolver::visit (AST ::PathInExpression &expr)
389+ {
390+ for (auto &seg : expr.get_segments ())
391+ if (seg.has_generic_args ())
392+ {
393+ auto &args = seg.get_generic_args ();
394+ for (auto &arg : args.get_generic_args ())
395+ arg.accept_vis (*this );
396+ for (auto &arg : args.get_binding_args ())
397+ if (!arg.is_error ())
398+ arg.get_type ()->accept_vis (*this );
399+ for (auto &arg : args.get_lifetime_args ())
400+ arg.accept_vis (*this );
401+ }
402+ }
282403
283404void
284405DefaultResolver::visit (AST ::TypePathSegmentGeneric &)
@@ -373,24 +494,34 @@ DefaultResolver::visit (AST::EnumItem &)
373494{}
374495
375496void
376- DefaultResolver::visit (AST ::EnumItemTuple &)
377- {}
497+ DefaultResolver::visit (AST ::EnumItemTuple &item)
498+ {
499+ for (auto &field : item.get_tuple_fields ())
500+ field.get_field_type ()->accept_vis (*this );
501+ }
378502
379503void
380- DefaultResolver::visit (AST ::EnumItemStruct &)
381- {}
504+ DefaultResolver::visit (AST ::EnumItemStruct &item)
505+ {
506+ for (auto &field : item.get_struct_fields ())
507+ field.get_field_type ()->accept_vis (*this );
508+ }
382509
383510void
384- DefaultResolver::visit (AST ::EnumItemDiscriminant &)
385- {}
511+ DefaultResolver::visit (AST ::EnumItemDiscriminant &item)
512+ {
513+ if (item.has_expr ())
514+ item.get_expr ()->accept_vis (*this );
515+ }
386516
387517void
388518DefaultResolver::visit (AST ::ConstantItem &item)
389519{
390520 auto expr_vis = [this , &item] () { item.get_expr ()->accept_vis (*this ); };
391521
392522 // FIXME: Why do we need a Rib here?
393- ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
523+ if (item.has_expr ())
524+ ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
394525}
395526
396527void
@@ -419,8 +550,18 @@ DefaultResolver::visit (AST::ExternalStaticItem &)
419550{}
420551
421552void
422- DefaultResolver::visit (AST ::ExternalFunctionItem &)
423- {}
553+ DefaultResolver::visit (AST ::ExternalFunctionItem &function)
554+ {
555+ auto def_fn = [this , &function] () {
556+ for (auto &p : function.get_function_params ())
557+ if (p.has_type ())
558+ p.get_type ()->accept_vis (*this );
559+ if (function.has_return_type ())
560+ function.get_return_type ()->accept_vis (*this );
561+ };
562+
563+ ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn);
564+ }
424565
425566void
426567DefaultResolver::visit (AST ::MacroMatchRepetition &)
0 commit comments