@@ -34,7 +34,10 @@ use syntax::codemap::span;
34
34
use syntax:: print:: pprust;
35
35
use syntax:: parse:: token;
36
36
use syntax:: parse:: token:: special_idents;
37
- use syntax:: { ast, oldvisit} ;
37
+ use syntax:: { ast, visit} ;
38
+ use syntax:: visit:: { Visitor , fn_kind} ;
39
+ use syntax:: ast:: { Block , item, fn_decl, NodeId , arm, pat, stmt, expr, Local } ;
40
+ use syntax:: ast:: { Ty , TypeMethod , struct_field} ;
38
41
39
42
/**
40
43
The region maps encode information about region relationships.
@@ -323,48 +326,53 @@ fn parent_to_expr(cx: Context, child_id: ast::NodeId, sp: span) {
323
326
}
324
327
}
325
328
326
- fn resolve_block ( blk : & ast:: Block ,
327
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
329
+ fn resolve_block ( visitor : & mut RegionResolutionVisitor ,
330
+ blk : & ast:: Block ,
331
+ cx : Context ) {
328
332
// Record the parent of this block.
329
333
parent_to_expr ( cx, blk. id , blk. span ) ;
330
334
331
335
// Descend.
332
336
let new_cx = Context { var_parent : Some ( blk. id ) ,
333
337
parent : Some ( blk. id ) ,
334
338
..cx} ;
335
- oldvisit :: visit_block ( blk , ( new_cx , visitor ) ) ;
339
+ visit :: walk_block ( visitor , blk , new_cx ) ;
336
340
}
337
341
338
- fn resolve_arm ( arm : & ast:: arm ,
339
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
340
- oldvisit:: visit_arm ( arm, ( cx, visitor) ) ;
342
+ fn resolve_arm ( visitor : & mut RegionResolutionVisitor ,
343
+ arm : & ast:: arm ,
344
+ cx : Context ) {
345
+ visit:: walk_arm ( visitor, arm, cx) ;
341
346
}
342
347
343
- fn resolve_pat ( pat : @ast:: pat ,
344
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
348
+ fn resolve_pat ( visitor : & mut RegionResolutionVisitor ,
349
+ pat : @ast:: pat ,
350
+ cx : Context ) {
345
351
assert_eq ! ( cx. var_parent, cx. parent) ;
346
352
parent_to_expr ( cx, pat. id , pat. span ) ;
347
- oldvisit :: visit_pat ( pat , ( cx , visitor ) ) ;
353
+ visit :: walk_pat ( visitor , pat , cx ) ;
348
354
}
349
355
350
- fn resolve_stmt ( stmt : @ast:: stmt ,
351
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
356
+ fn resolve_stmt ( visitor : & mut RegionResolutionVisitor ,
357
+ stmt : @ast:: stmt ,
358
+ cx : Context ) {
352
359
match stmt. node {
353
360
ast:: stmt_decl( * ) => {
354
- oldvisit :: visit_stmt ( stmt , ( cx , visitor ) ) ;
361
+ visit :: walk_stmt ( visitor , stmt , cx ) ;
355
362
}
356
363
ast:: stmt_expr( _, stmt_id) |
357
364
ast:: stmt_semi( _, stmt_id) => {
358
365
parent_to_expr ( cx, stmt_id, stmt. span ) ;
359
366
let expr_cx = Context { parent : Some ( stmt_id) , ..cx} ;
360
- oldvisit :: visit_stmt ( stmt , ( expr_cx , visitor ) ) ;
367
+ visit :: walk_stmt ( visitor , stmt , expr_cx ) ;
361
368
}
362
369
ast:: stmt_mac( * ) => cx. sess . bug ( "unexpanded macro" )
363
370
}
364
371
}
365
372
366
- fn resolve_expr ( expr : @ast:: expr ,
367
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
373
+ fn resolve_expr ( visitor : & mut RegionResolutionVisitor ,
374
+ expr : @ast:: expr ,
375
+ cx : Context ) {
368
376
parent_to_expr ( cx, expr. id , expr. span ) ;
369
377
370
378
let mut new_cx = cx;
@@ -400,30 +408,32 @@ fn resolve_expr(expr: @ast::expr,
400
408
} ;
401
409
402
410
403
- oldvisit :: visit_expr ( expr , ( new_cx , visitor ) ) ;
411
+ visit :: walk_expr ( visitor , expr , new_cx ) ;
404
412
}
405
413
406
- fn resolve_local ( local : @ast:: Local ,
407
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
414
+ fn resolve_local ( visitor : & mut RegionResolutionVisitor ,
415
+ local : @ast:: Local ,
416
+ cx : Context ) {
408
417
assert_eq ! ( cx. var_parent, cx. parent) ;
409
418
parent_to_expr ( cx, local. id , local. span ) ;
410
- oldvisit :: visit_local ( local , ( cx , visitor ) ) ;
419
+ visit :: walk_local ( visitor , local , cx ) ;
411
420
}
412
421
413
- fn resolve_item ( item : @ast:: item ,
414
- ( cx, visitor) : ( Context , oldvisit:: vt < Context > ) ) {
422
+ fn resolve_item ( visitor : & mut RegionResolutionVisitor ,
423
+ item : @ast:: item ,
424
+ cx : Context ) {
415
425
// Items create a new outer block scope as far as we're concerned.
416
426
let new_cx = Context { var_parent : None , parent : None , ..cx} ;
417
- oldvisit :: visit_item ( item , ( new_cx , visitor ) ) ;
427
+ visit :: walk_item ( visitor , item , new_cx ) ;
418
428
}
419
429
420
- fn resolve_fn ( fk : & oldvisit:: fn_kind ,
430
+ fn resolve_fn ( visitor : & mut RegionResolutionVisitor ,
431
+ fk : & visit:: fn_kind ,
421
432
decl : & ast:: fn_decl ,
422
433
body : & ast:: Block ,
423
434
sp : span ,
424
435
id : ast:: NodeId ,
425
- ( cx, visitor) : ( Context ,
426
- oldvisit:: vt < Context > ) ) {
436
+ cx : Context ) {
427
437
debug ! ( "region::resolve_fn(id=%?, \
428
438
span=%?, \
429
439
body.id=%?, \
@@ -438,26 +448,58 @@ fn resolve_fn(fk: &oldvisit::fn_kind,
438
448
var_parent : Some ( body. id ) ,
439
449
..cx} ;
440
450
match * fk {
441
- oldvisit :: fk_method( _, _, method) => {
451
+ visit :: fk_method( _, _, method) => {
442
452
cx. region_maps . record_parent ( method. self_id , body. id ) ;
443
453
}
444
454
_ => { }
445
455
}
446
- oldvisit :: visit_fn_decl ( decl , ( decl_cx , visitor ) ) ;
456
+ visit :: walk_fn_decl ( visitor , decl , decl_cx ) ;
447
457
448
458
// The body of the fn itself is either a root scope (top-level fn)
449
459
// or it continues with the inherited scope (closures).
450
460
let body_cx = match * fk {
451
- oldvisit :: fk_item_fn( * ) |
452
- oldvisit :: fk_method( * ) => {
461
+ visit :: fk_item_fn( * ) |
462
+ visit :: fk_method( * ) => {
453
463
Context { parent : None , var_parent : None , ..cx}
454
464
}
455
- oldvisit :: fk_anon( * ) |
456
- oldvisit :: fk_fn_block( * ) => {
465
+ visit :: fk_anon( * ) |
466
+ visit :: fk_fn_block( * ) => {
457
467
cx
458
468
}
459
469
} ;
460
- ( visitor. visit_block ) ( body, ( body_cx, visitor) ) ;
470
+ visitor. visit_block ( body, body_cx) ;
471
+ }
472
+
473
+ struct RegionResolutionVisitor ;
474
+
475
+ impl Visitor < Context > for RegionResolutionVisitor {
476
+
477
+ fn visit_block ( & mut self , b : & Block , cx : Context ) {
478
+ resolve_block ( self , b, cx) ;
479
+ }
480
+
481
+ fn visit_item ( & mut self , i: @item, cx : Context ) {
482
+ resolve_item ( self , i, cx) ;
483
+ }
484
+
485
+ fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl , b : & Block , s : span , n : NodeId , cx : Context ) {
486
+ resolve_fn ( self , fk, fd, b, s, n, cx) ;
487
+ }
488
+ fn visit_arm ( & mut self , a : & arm , cx : Context ) {
489
+ resolve_arm ( self , a, cx) ;
490
+ }
491
+ fn visit_pat ( & mut self , p: @pat, cx : Context ) {
492
+ resolve_pat ( self , p, cx) ;
493
+ }
494
+ fn visit_stmt ( & mut self , s: @stmt, cx : Context ) {
495
+ resolve_stmt ( self , s, cx) ;
496
+ }
497
+ fn visit_expr ( & mut self , ex: @expr, cx : Context ) {
498
+ resolve_expr ( self , ex, cx) ;
499
+ }
500
+ fn visit_local ( & mut self , l : @Local , cx : Context ) {
501
+ resolve_local ( self , l, cx) ;
502
+ }
461
503
}
462
504
463
505
pub fn resolve_crate ( sess : Session ,
@@ -474,18 +516,8 @@ pub fn resolve_crate(sess: Session,
474
516
region_maps : region_maps,
475
517
parent : None ,
476
518
var_parent : None } ;
477
- let visitor = oldvisit:: mk_vt ( @oldvisit:: Visitor {
478
- visit_block : resolve_block,
479
- visit_item : resolve_item,
480
- visit_fn : resolve_fn,
481
- visit_arm : resolve_arm,
482
- visit_pat : resolve_pat,
483
- visit_stmt : resolve_stmt,
484
- visit_expr : resolve_expr,
485
- visit_local : resolve_local,
486
- .. * oldvisit:: default_visitor ( )
487
- } ) ;
488
- oldvisit:: visit_crate ( crate , ( cx, visitor) ) ;
519
+ let mut visitor = RegionResolutionVisitor ;
520
+ visit:: walk_crate ( & mut visitor, crate , cx) ;
489
521
return region_maps;
490
522
}
491
523
@@ -700,46 +732,45 @@ impl DetermineRpCtxt {
700
732
}
701
733
}
702
734
703
- fn determine_rp_in_item ( item : @ast :: item ,
704
- ( cx , visitor ) : ( @ mut DetermineRpCtxt ,
705
- oldvisit :: vt < @mut DetermineRpCtxt > ) ) {
735
+ fn determine_rp_in_item ( visitor : & mut DetermineRpVisitor ,
736
+ item : @ast :: item ,
737
+ cx : @mut DetermineRpCtxt ) {
706
738
do cx. with ( item. id , true ) {
707
- oldvisit :: visit_item ( item , ( cx , visitor ) ) ;
739
+ visit :: walk_item ( visitor , item , cx ) ;
708
740
}
709
741
}
710
742
711
- fn determine_rp_in_fn ( fk : & oldvisit:: fn_kind ,
743
+ fn determine_rp_in_fn ( visitor : & mut DetermineRpVisitor ,
744
+ fk : & visit:: fn_kind ,
712
745
decl : & ast:: fn_decl ,
713
746
body : & ast:: Block ,
714
747
_: span ,
715
748
_: ast:: NodeId ,
716
- ( cx, visitor) : ( @mut DetermineRpCtxt ,
717
- oldvisit:: vt < @mut DetermineRpCtxt > ) ) {
749
+ cx : @mut DetermineRpCtxt ) {
718
750
do cx. with ( cx. item_id , false ) {
719
751
do cx. with_ambient_variance ( rv_contravariant) {
720
752
for a in decl. inputs . iter ( ) {
721
- ( visitor. visit_ty ) ( & a. ty , ( cx , visitor ) ) ;
753
+ visitor. visit_ty ( & a. ty , cx ) ;
722
754
}
723
755
}
724
- ( visitor. visit_ty ) ( & decl. output , ( cx , visitor ) ) ;
725
- let generics = oldvisit :: generics_of_fn ( fk) ;
726
- ( visitor. visit_generics ) ( & generics, ( cx , visitor ) ) ;
727
- ( visitor. visit_block ) ( body, ( cx , visitor ) ) ;
756
+ visitor. visit_ty ( & decl. output , cx ) ;
757
+ let generics = visit :: generics_of_fn ( fk) ;
758
+ visitor. visit_generics ( & generics, cx ) ;
759
+ visitor. visit_block ( body, cx ) ;
728
760
}
729
761
}
730
762
731
- fn determine_rp_in_ty_method ( ty_m : & ast:: TypeMethod ,
732
- ( cx, visitor) :
733
- ( @mut DetermineRpCtxt ,
734
- oldvisit:: vt < @mut DetermineRpCtxt > ) ) {
763
+ fn determine_rp_in_ty_method ( visitor : & mut DetermineRpVisitor ,
764
+ ty_m : & ast:: TypeMethod ,
765
+ cx : @mut DetermineRpCtxt ) {
735
766
do cx. with ( cx. item_id , false ) {
736
- oldvisit :: visit_ty_method ( ty_m , ( cx , visitor ) ) ;
767
+ visit :: walk_ty_method ( visitor , ty_m , cx ) ;
737
768
}
738
769
}
739
770
740
- fn determine_rp_in_ty ( ty : & ast :: Ty ,
741
- ( cx , visitor ) : ( @ mut DetermineRpCtxt ,
742
- oldvisit :: vt < @mut DetermineRpCtxt > ) ) {
771
+ fn determine_rp_in_ty ( visitor : & mut DetermineRpVisitor ,
772
+ ty : & ast :: Ty ,
773
+ cx : @mut DetermineRpCtxt ) {
743
774
// we are only interested in types that will require an item to
744
775
// be region-parameterized. if cx.item_id is zero, then this type
745
776
// is not a member of a type defn nor is it a constitutent of an
@@ -823,14 +854,14 @@ fn determine_rp_in_ty(ty: &ast::Ty,
823
854
match ty. node {
824
855
ast:: ty_box( ref mt) | ast:: ty_uniq( ref mt) | ast:: ty_vec( ref mt) |
825
856
ast:: ty_rptr( _, ref mt) | ast:: ty_ptr( ref mt) => {
826
- visit_mt ( mt , ( cx , visitor ) ) ;
857
+ visit_mt ( visitor , mt , cx ) ;
827
858
}
828
859
829
860
ast:: ty_path( ref path, _, _) => {
830
861
// type parameters are---for now, anyway---always invariant
831
862
do cx. with_ambient_variance ( rv_invariant) {
832
863
for tp in path. types . iter ( ) {
833
- ( visitor. visit_ty ) ( tp, ( cx , visitor ) ) ;
864
+ visitor. visit_ty ( tp, cx ) ;
834
865
}
835
866
}
836
867
}
@@ -843,37 +874,59 @@ fn determine_rp_in_ty(ty: &ast::Ty,
843
874
// parameters are contravariant
844
875
do cx. with_ambient_variance ( rv_contravariant) {
845
876
for a in decl. inputs . iter ( ) {
846
- ( visitor. visit_ty ) ( & a. ty , ( cx , visitor ) ) ;
877
+ visitor. visit_ty ( & a. ty , cx ) ;
847
878
}
848
879
}
849
- ( visitor. visit_ty ) ( & decl. output , ( cx , visitor ) ) ;
880
+ visitor. visit_ty ( & decl. output , cx ) ;
850
881
}
851
882
}
852
883
853
884
_ => {
854
- oldvisit :: visit_ty ( ty , ( cx , visitor ) ) ;
885
+ visit :: walk_ty ( visitor , ty , cx ) ;
855
886
}
856
887
}
857
888
858
- fn visit_mt ( mt : & ast :: mt ,
859
- ( cx , visitor ) : ( @ mut DetermineRpCtxt ,
860
- oldvisit :: vt < @mut DetermineRpCtxt > ) ) {
889
+ fn visit_mt ( visitor : & mut DetermineRpVisitor ,
890
+ mt : & ast :: mt ,
891
+ cx : @mut DetermineRpCtxt ) {
861
892
// mutability is invariant
862
893
if mt. mutbl == ast:: m_mutbl {
863
894
do cx. with_ambient_variance ( rv_invariant) {
864
- ( visitor. visit_ty ) ( mt. ty , ( cx , visitor ) ) ;
895
+ visitor. visit_ty ( mt. ty , cx ) ;
865
896
}
866
897
} else {
867
- ( visitor. visit_ty ) ( mt. ty , ( cx , visitor ) ) ;
898
+ visitor. visit_ty ( mt. ty , cx ) ;
868
899
}
869
900
}
870
901
}
871
902
872
- fn determine_rp_in_struct_field (
873
- cm : @ast:: struct_field ,
874
- ( cx, visitor) : ( @mut DetermineRpCtxt ,
875
- oldvisit:: vt < @mut DetermineRpCtxt > ) ) {
876
- oldvisit:: visit_struct_field ( cm, ( cx, visitor) ) ;
903
+ fn determine_rp_in_struct_field ( visitor : & mut DetermineRpVisitor ,
904
+ cm : @ast:: struct_field ,
905
+ cx : @mut DetermineRpCtxt ) {
906
+ visit:: walk_struct_field ( visitor, cm, cx) ;
907
+ }
908
+
909
+ struct DetermineRpVisitor ;
910
+
911
+ impl Visitor < @mut DetermineRpCtxt > for DetermineRpVisitor {
912
+
913
+ fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl ,
914
+ b : & Block , s : span , n : NodeId , e : @mut DetermineRpCtxt ) {
915
+ determine_rp_in_fn ( self , fk, fd, b, s, n, e) ;
916
+ }
917
+ fn visit_item ( & mut self , i: @item, e : @mut DetermineRpCtxt ) {
918
+ determine_rp_in_item ( self , i, e) ;
919
+ }
920
+ fn visit_ty ( & mut self , t : & Ty , e : @mut DetermineRpCtxt ) {
921
+ determine_rp_in_ty ( self , t, e) ;
922
+ }
923
+ fn visit_ty_method ( & mut self , t : & TypeMethod , e : @mut DetermineRpCtxt ) {
924
+ determine_rp_in_ty_method ( self , t, e) ;
925
+ }
926
+ fn visit_struct_field ( & mut self , s : @struct_field , e : @mut DetermineRpCtxt ) {
927
+ determine_rp_in_struct_field ( self , s, e) ;
928
+ }
929
+
877
930
}
878
931
879
932
pub fn determine_rp_in_crate ( sess : Session ,
@@ -894,15 +947,8 @@ pub fn determine_rp_in_crate(sess: Session,
894
947
} ;
895
948
896
949
// Gather up the base set, worklist and dep_map
897
- let visitor = oldvisit:: mk_vt ( @oldvisit:: Visitor {
898
- visit_fn : determine_rp_in_fn,
899
- visit_item : determine_rp_in_item,
900
- visit_ty : determine_rp_in_ty,
901
- visit_ty_method : determine_rp_in_ty_method,
902
- visit_struct_field : determine_rp_in_struct_field,
903
- .. * oldvisit:: default_visitor ( )
904
- } ) ;
905
- oldvisit:: visit_crate ( crate , ( cx, visitor) ) ;
950
+ let mut visitor = DetermineRpVisitor ;
951
+ visit:: walk_crate ( & mut visitor, crate , cx) ;
906
952
907
953
// Propagate indirect dependencies
908
954
//
0 commit comments