@@ -31,7 +31,8 @@ export _impl, iscopes, method_info;
31
31
tag scope {
32
32
scope_crate;
33
33
scope_item ( @ast:: item) ;
34
- scope_fn ( ast:: fn_decl, ast:: proto, [ ast:: ty_param] ) ;
34
+ scope_bare_fn ( ast:: fn_decl, node_id, [ ast:: ty_param] ) ;
35
+ scope_fn_expr ( ast:: fn_decl, node_id, [ ast:: ty_param] ) ;
35
36
scope_native_item ( @ast:: native_item) ;
36
37
scope_loop ( @ast:: local) ; // there's only 1 decl per loop.
37
38
scope_block ( ast:: blk, @mutable uint, @mutable uint) ;
@@ -335,8 +336,11 @@ fn resolve_names(e: @env, c: @ast::crate) {
335
336
visit_expr: bind walk_expr ( e, _, _, _) ,
336
337
visit_ty: bind walk_ty ( e, _, _, _) ,
337
338
visit_constr: bind walk_constr ( e, _, _, _, _, _) ,
338
- visit_fn: bind visit_fn_with_scope ( e, _, _, _, _, _, _, _)
339
- with * visit:: default_visitor ( ) } ;
339
+ visit_fn_proto:
340
+ bind visit_fn_proto_with_scope ( e, _, _, _, _, _, _, _) ,
341
+ visit_fn_block:
342
+ bind visit_fn_block_with_scope ( e, _, _, _, _, _, _)
343
+ with * visit:: default_visitor ( ) } ;
340
344
visit:: visit_crate ( * c, cons ( scope_crate, @nil) , visit:: mk_vt ( v) ) ;
341
345
e. used_imports . track = false ;
342
346
e. sess . abort_if_errors ( ) ;
@@ -400,8 +404,8 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
400
404
ast:: item_impl ( tps, sty, methods) {
401
405
visit:: visit_ty ( sty, sc, v) ;
402
406
for m in methods {
403
- v. visit_fn ( m. node . meth , tps + m. node . tps , m. span ,
404
- some ( m. node . ident ) , m. node . id , sc, v) ;
407
+ v. visit_fn_proto ( m. node . meth , tps + m. node . tps , m. span ,
408
+ some ( m. node . ident ) , m. node . id , sc, v) ;
405
409
}
406
410
}
407
411
_ { visit : : visit_item ( i, sc, v) ; }
@@ -413,9 +417,9 @@ fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
413
417
visit:: visit_native_item ( ni, cons ( scope_native_item ( ni) , @sc) , v) ;
414
418
}
415
419
416
- fn visit_fn_with_scope ( e : @env , f : ast:: _fn , tp : [ ast:: ty_param ] , sp : span ,
417
- name : fn_ident , id : node_id , sc : scopes ,
418
- v : vt < scopes > ) {
420
+ fn visit_fn_proto_with_scope ( e : @env , f : ast:: _fn , tp : [ ast:: ty_param ] ,
421
+ sp : span , name : fn_ident , id : node_id ,
422
+ sc : scopes , v : vt < scopes > ) {
419
423
// is this a main fn declaration?
420
424
alt name {
421
425
some( nm) {
@@ -431,8 +435,21 @@ fn visit_fn_with_scope(e: @env, f: ast::_fn, tp: [ast::ty_param], sp: span,
431
435
// here's where we need to set up the mapping
432
436
// for f's constrs in the table.
433
437
for c: @ast:: constr in f. decl . constraints { resolve_constr ( e, c, sc, v) ; }
434
- visit:: visit_fn ( f, tp, sp, name, id,
435
- cons ( scope_fn ( f. decl , f. proto , tp) , @sc) , v) ;
438
+ let scope = alt f. proto {
439
+ ast:: proto_bare. { scope_bare_fn ( f. decl , id, tp) }
440
+ _ { scope_fn_expr( f. decl , id, tp) }
441
+ } ;
442
+
443
+ visit:: visit_fn_proto ( f, tp, sp, name, id, cons ( scope, @sc) , v) ;
444
+ }
445
+
446
+ fn visit_fn_block_with_scope ( _e : @env , decl : fn_decl , blk : ast:: blk ,
447
+ span : span , id : node_id ,
448
+ sc : scopes , v : vt < scopes > ) {
449
+ let scope = scope_fn_expr ( decl, id, [ ] ) ;
450
+ log ( "scope=" , scope) ;
451
+ visit:: visit_fn_block ( decl, blk, span, id, cons ( scope, @sc) , v) ;
452
+ log ( "unscope" ) ;
436
453
}
437
454
438
455
fn visit_block_with_scope ( b : ast:: blk , sc : scopes , v : vt < scopes > ) {
@@ -648,7 +665,8 @@ fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
648
665
alt sc {
649
666
cons( cur, rest) {
650
667
alt cur {
651
- scope_crate. | scope_fn ( _, _, _) |
668
+ scope_crate. | scope_bare_fn ( _, _, _) |
669
+ scope_fn_expr ( _, _, _) |
652
670
scope_item ( @{ node: ast:: item_mod ( _) , _} ) {
653
671
ret some ( cur) ;
654
672
}
@@ -734,23 +752,17 @@ fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident,
734
752
735
753
fn scope_is_fn ( sc : scope ) -> bool {
736
754
ret alt sc {
737
- scope_fn( _, ast:: proto_bare. , _) |
738
- scope_native_item ( _) {
739
- true
740
- }
741
- _ { false }
742
- } ;
755
+ scope_bare_fn( _, _, _) | scope_native_item ( _) { true }
756
+ _ { false }
757
+ } ;
743
758
}
744
759
745
760
// Returns:
746
761
// none - does not close
747
- // some(true) - closes and permits mutation
748
- // some(false) - closes but no mutation
749
- fn scope_closes ( sc : scope ) -> option:: t < bool > {
762
+ // some(node_id) - closes via the expr w/ node_id
763
+ fn scope_closes ( sc : scope ) -> option:: t < node_id > {
750
764
alt sc {
751
- scope_fn( _, ast:: proto_block. , _) { some ( true ) }
752
- scope_fn ( _, ast:: proto_send. , _) { some ( false ) }
753
- scope_fn ( _, ast:: proto_shared ( _) , _) { some ( false ) }
765
+ scope_fn_expr( _, node_id, _) { some ( node_id) }
754
766
_ { none }
755
767
}
756
768
}
@@ -823,7 +835,8 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
823
835
}
824
836
}
825
837
}
826
- scope_fn ( decl, _, ty_params) {
838
+ scope_bare_fn ( decl, _, ty_params) |
839
+ scope_fn_expr ( decl, _, ty_params) {
827
840
ret lookup_in_fn ( name, decl, ty_params, ns) ;
828
841
}
829
842
scope_loop ( local) {
@@ -887,7 +900,10 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
887
900
left_fn_level2 = true ;
888
901
} else if ns == ns_value || ns == ns_type {
889
902
left_fn = scope_is_fn ( hd) ;
890
- alt scope_closes ( hd) { some ( mut) { closing += [ mut] ; } _ { } }
903
+ alt scope_closes ( hd) {
904
+ some ( node_id) { closing += [ node_id] ; }
905
+ _ { }
906
+ }
891
907
}
892
908
sc = * tl;
893
909
}
0 commit comments