@@ -27,23 +27,22 @@ tag scope {
27
27
scope_arm ( ast. arm ) ;
28
28
}
29
29
30
- // This indicates whether we're searching up the scope chain
31
- // or whether we've found a path component and started following
32
- // it back down, which has an effect on export visibility
33
- tag search_direction {
34
- up;
35
- down;
36
- }
37
-
38
30
type env = rec ( list[ scope] scopes ,
39
- session . session sess,
40
- search_direction direction) ;
31
+ session . session sess) ;
41
32
42
33
tag namespace {
43
34
ns_value;
44
35
ns_type;
45
36
}
46
37
38
+ // This indicates whether we're searching up the scope chain or whether we've
39
+ // found a path component and started following it back down, which has an
40
+ // effect on export visibility
41
+ tag direction {
42
+ up;
43
+ down;
44
+ }
45
+
47
46
type import_map = std. map. hashmap [ ast. def_id , def_wrap] ;
48
47
49
48
// A simple wrapper over defs that stores a bit more information about modules
@@ -157,11 +156,10 @@ fn find_final_def(&env e, import_map index,
157
156
auto len = _vec. len [ ident] ( idents) ;
158
157
auto rest_idents = _vec. slice [ ident] ( idents, 1 u, len) ;
159
158
auto empty_e = rec ( scopes = nil[ scope] ,
160
- sess = e. sess ,
161
- direction = down) ;
159
+ sess = e. sess ) ;
162
160
auto tmp_e = update_env_for_item ( empty_e, i) ;
163
161
auto next_i = rest_idents. ( 0 ) ;
164
- auto next_ = lookup_name_wrapped ( tmp_e, next_i, ns) ;
162
+ auto next_ = lookup_name_wrapped ( tmp_e, next_i, ns, down ) ;
165
163
alt ( next_) {
166
164
case ( none[ tup ( @env, def_wrap) ] ) {
167
165
e. sess . span_err ( sp, "unresolved name: " + next_i) ;
@@ -183,11 +181,10 @@ fn find_final_def(&env e, import_map index,
183
181
auto len = _vec. len [ ident] ( idents) ;
184
182
auto rest_idents = _vec. slice [ ident] ( idents, 1 u, len) ;
185
183
auto empty_e = rec ( scopes = nil[ scope] ,
186
- sess = e. sess ,
187
- direction = down) ;
184
+ sess = e. sess ) ;
188
185
auto tmp_e = update_env_for_external_mod ( empty_e, mod_id, idents) ;
189
186
auto next_i = rest_idents. ( 0 ) ;
190
- auto next_ = lookup_name_wrapped ( tmp_e, next_i, ns) ;
187
+ auto next_ = lookup_name_wrapped ( tmp_e, next_i, ns, down ) ;
191
188
alt ( next_) {
192
189
case ( none[ tup ( @env, def_wrap) ] ) {
193
190
e. sess . span_err ( sp, "unresolved name: " + next_i) ;
@@ -282,7 +279,7 @@ fn find_final_def(&env e, import_map index,
282
279
index. insert ( option. get [ ast. def_id ] ( import_id) , def_wrap_resolving) ;
283
280
}
284
281
auto first = idents. ( 0 ) ;
285
- auto d_ = lookup_name_wrapped ( e, first, ns) ;
282
+ auto d_ = lookup_name_wrapped ( e, first, ns, up ) ;
286
283
alt ( d_) {
287
284
case ( none[ tup ( @env, def_wrap) ] ) {
288
285
e. sess . span_err ( sp, "unresolved name: " + first) ;
@@ -298,8 +295,8 @@ fn find_final_def(&env e, import_map index,
298
295
}
299
296
}
300
297
301
- fn lookup_name_wrapped ( & env e, ast . ident i, namespace ns)
302
- -> option. t[ tup ( @env , def_wrap ) ] {
298
+ fn lookup_name_wrapped ( & env e, ast . ident i, namespace ns, direction dir )
299
+ -> option. t[ tup ( @env , def_wrap ) ] {
303
300
304
301
// log "resolving name " + i;
305
302
@@ -359,12 +356,12 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
359
356
fail;
360
357
}
361
358
362
- fn check_mod ( & env e , ast . ident i, ast. _mod m , namespace ns)
363
- -> option. t[ def_wrap ] {
359
+ fn check_mod ( ast . ident i, ast. _mod m , namespace ns,
360
+ direction dir ) -> option. t[ def_wrap ] {
364
361
365
- fn visible ( & env e , ast . ident i, ast. _mod m ) -> bool {
362
+ fn visible ( ast . ident i, ast. _mod m , direction dir ) -> bool {
366
363
367
- alt ( e . direction ) {
364
+ alt ( dir ) {
368
365
case ( up) {
369
366
ret true ;
370
367
}
@@ -400,14 +397,14 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
400
397
ret some ( found_def_view ( view_item) ) ;
401
398
}
402
399
case ( ast. mie_item ( ?item) ) {
403
- if ( visible ( e , i, m) ) {
400
+ if ( visible ( i, m, dir ) ) {
404
401
ret some ( found_def_item ( item, ns) ) ;
405
402
}
406
403
}
407
404
case ( ast. mie_tag_variant ( ?item, ?variant_idx) ) {
408
405
alt ( item. node ) {
409
406
case ( ast. item_tag ( _, ?variants, _, ?tid, _) ) {
410
- if ( visible ( e , i, m) ) {
407
+ if ( visible ( i, m, dir ) ) {
411
408
auto vid = variants. ( variant_idx) . node . id ;
412
409
auto t = ast. def_variant ( tid, vid) ;
413
410
ret some[ def_wrap] ( def_wrap_other ( t) ) ;
@@ -501,12 +498,12 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
501
498
}
502
499
}
503
500
504
- fn in_scope ( & env e , ast. ident identifier , & scope s,
505
- namespace ns) -> option. t[ def_wrap ] {
501
+ fn in_scope ( & session . session sess , ast. ident identifier , & scope s,
502
+ namespace ns, direction dir ) -> option. t[ def_wrap ] {
506
503
alt ( s) {
507
504
508
505
case ( scope_crate ( ?c) ) {
509
- ret check_mod ( e , identifier, c. node . module , ns) ;
506
+ ret check_mod ( identifier, c. node . module , ns, dir ) ;
510
507
}
511
508
512
509
case ( scope_item ( ?it) ) {
@@ -542,7 +539,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
542
539
}
543
540
}
544
541
case ( ast. item_mod ( _, ?m, _) ) {
545
- ret check_mod ( e , identifier, m, ns) ;
542
+ ret check_mod ( identifier, m, ns, dir ) ;
546
543
}
547
544
case ( ast. item_native_mod ( _, ?m, _) ) {
548
545
ret check_native_mod ( identifier, m) ;
@@ -570,7 +567,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
570
567
}
571
568
572
569
case ( scope_external_mod ( ?mod_id, ?path) ) {
573
- ret lookup_external_def ( e . sess , mod_id. _0 , path) ;
570
+ ret lookup_external_def ( sess, mod_id. _0 , path) ;
574
571
}
575
572
576
573
case ( scope_loop ( ?d) ) {
@@ -606,14 +603,14 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
606
603
ret none[ tup ( @env, def_wrap) ] ;
607
604
}
608
605
case ( cons[ scope] ( ?hd, ?tl) ) {
609
- auto x = in_scope ( e, i, hd, ns) ;
606
+ auto x = in_scope ( e. sess , i, hd, ns, dir ) ;
610
607
alt ( x) {
611
608
case ( some[ def_wrap] ( ?x) ) {
612
609
ret some ( tup ( @e, x) ) ;
613
610
}
614
611
case ( none[ def_wrap] ) {
615
612
auto outer_env = rec ( scopes = * tl with e) ;
616
- ret lookup_name_wrapped ( outer_env, i, ns) ;
613
+ ret lookup_name_wrapped ( outer_env, i, ns, up ) ;
617
614
}
618
615
}
619
616
}
@@ -785,8 +782,7 @@ fn resolve_imports(session.session sess, @ast.crate crate) -> @ast.crate {
785
782
with * fld ) ;
786
783
787
784
auto e = rec ( scopes = nil[ scope] ,
788
- sess = sess,
789
- direction = up) ;
785
+ sess = sess) ;
790
786
791
787
ret fold. fold_crate [ env] ( e, fld, crate ) ;
792
788
}
@@ -810,8 +806,7 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate {
810
806
with * fld ) ;
811
807
812
808
auto e = rec ( scopes = nil[ scope] ,
813
- sess = sess,
814
- direction = up) ;
809
+ sess = sess) ;
815
810
816
811
ret fold. fold_crate [ env] ( e, fld, new_crate) ;
817
812
}
0 commit comments