@@ -119,9 +119,8 @@ use syntax::ast::*;
119119use syntax:: codemap:: span;
120120use syntax:: parse:: token:: special_idents;
121121use syntax:: print:: pprust:: { expr_to_str, block_to_str} ;
122- use syntax:: oldvisit:: { fk_anon, fk_fn_block, fk_item_fn, fk_method} ;
123- use syntax:: oldvisit:: { vt} ;
124- use syntax:: { oldvisit, ast_util} ;
122+ use syntax:: { visit, ast_util} ;
123+ use syntax:: visit:: { Visitor , fn_kind} ;
125124
126125#[ deriving( Eq ) ]
127126struct Variable ( uint ) ;
@@ -152,22 +151,27 @@ fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
152151 }
153152}
154153
154+ struct LivenessVisitor ;
155+
156+ impl Visitor < @mut IrMaps > for LivenessVisitor {
157+ fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl , b : & Block , s : span , n : NodeId , e : @mut IrMaps ) {
158+ visit_fn ( self , fk, fd, b, s, n, e) ;
159+ }
160+ fn visit_local ( & mut self , l : @Local , e : @mut IrMaps ) { visit_local ( self , l, e) ; }
161+ fn visit_expr ( & mut self , ex: @expr, e : @mut IrMaps ) { visit_expr ( self , ex, e) ; }
162+ fn visit_arm ( & mut self , a : & arm , e : @mut IrMaps ) { visit_arm ( self , a, e) ; }
163+ }
164+
155165pub fn check_crate ( tcx : ty:: ctxt ,
156166 method_map : typeck:: method_map ,
157167 capture_map : moves:: CaptureMap ,
158168 crate : & Crate ) {
159- let visitor = oldvisit:: mk_vt ( @oldvisit:: Visitor {
160- visit_fn : visit_fn,
161- visit_local : visit_local,
162- visit_expr : visit_expr,
163- visit_arm : visit_arm,
164- .. * oldvisit:: default_visitor ( )
165- } ) ;
169+ let mut visitor = LivenessVisitor ;
166170
167171 let initial_maps = @mut IrMaps ( tcx,
168172 method_map,
169173 capture_map) ;
170- oldvisit :: visit_crate ( crate , ( initial_maps , visitor ) ) ;
174+ visit :: walk_crate ( & mut visitor , crate , initial_maps ) ;
171175 tcx. sess . abort_if_errors ( ) ;
172176}
173177
@@ -341,13 +345,30 @@ impl IrMaps {
341345 }
342346}
343347
344- fn visit_fn ( fk : & oldvisit:: fn_kind ,
348+ struct ErrorCheckVisitor ;
349+
350+ impl Visitor < @Liveness > for ErrorCheckVisitor {
351+ fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl , b : & Block , s : span , n : NodeId , e : @Liveness ) {
352+ check_fn ( self , fk, fd, b, s, n, e) ;
353+ }
354+ fn visit_local ( & mut self , l : @Local , e : @Liveness ) {
355+ check_local ( self , l, e) ;
356+ }
357+ fn visit_expr ( & mut self , ex: @expr, e : @Liveness ) {
358+ check_expr ( self , ex, e) ;
359+ }
360+ fn visit_arm ( & mut self , a : & arm , e : @Liveness ) {
361+ check_arm ( self , a, e) ;
362+ }
363+ }
364+
365+ fn visit_fn ( v : & mut LivenessVisitor ,
366+ fk : & visit:: fn_kind ,
345367 decl : & fn_decl ,
346368 body : & Block ,
347369 sp : span ,
348370 id : NodeId ,
349- ( this, v) : ( @mut IrMaps ,
350- vt < @mut IrMaps > ) ) {
371+ this : @mut IrMaps ) {
351372 debug ! ( "visit_fn: id=%d" , id) ;
352373 let _i = :: util:: common:: indenter ( ) ;
353374
@@ -371,7 +392,7 @@ fn visit_fn(fk: &oldvisit::fn_kind,
371392
372393 // Add `this`, whether explicit or implicit.
373394 match * fk {
374- fk_method( _, _, method) => {
395+ visit :: fk_method( _, _, method) => {
375396 match method. explicit_self . node {
376397 sty_value | sty_region( * ) | sty_box( _) | sty_uniq => {
377398 fn_maps. add_variable ( Arg ( method. self_id ,
@@ -380,12 +401,12 @@ fn visit_fn(fk: &oldvisit::fn_kind,
380401 sty_static => { }
381402 }
382403 }
383- fk_item_fn( * ) | fk_anon( * ) | fk_fn_block( * ) => { }
404+ visit :: fk_item_fn( * ) | visit :: fk_anon( * ) | visit :: fk_fn_block( * ) => { }
384405 }
385406
386407 // gather up the various local variables, significant expressions,
387408 // and so forth:
388- oldvisit :: visit_fn ( fk, decl, body, sp, id, ( fn_maps, v ) ) ;
409+ visit :: walk_fn ( v , fk, decl, body, sp, id, fn_maps) ;
389410
390411 // Special nodes and variables:
391412 // - exit_ln represents the end of the fn, either by return or fail
@@ -402,19 +423,13 @@ fn visit_fn(fk: &oldvisit::fn_kind,
402423 let entry_ln = ( * lsets) . compute ( decl, body) ;
403424
404425 // check for various error conditions
405- let check_vt = oldvisit:: mk_vt ( @oldvisit:: Visitor {
406- visit_fn : check_fn,
407- visit_local : check_local,
408- visit_expr : check_expr,
409- visit_arm : check_arm,
410- .. * oldvisit:: default_visitor ( )
411- } ) ;
412- ( check_vt. visit_block ) ( body, ( lsets, check_vt) ) ;
426+ let mut check_vt = ErrorCheckVisitor ;
427+ check_vt. visit_block ( body, lsets) ;
413428 lsets. check_ret ( id, sp, fk, entry_ln) ;
414429 lsets. warn_about_unused_args ( decl, entry_ln) ;
415430}
416431
417- fn visit_local( local : @Local , ( this, vt ) : ( @mut IrMaps , vt < @ mut IrMaps > ) ) {
432+ fn visit_local( v : & mut LivenessVisitor , local : @Local , this : @mut IrMaps ) {
418433 let def_map = this. tcx . def_map ;
419434 do pat_util:: pat_bindings ( def_map, local. pat ) |_bm, p_id, sp, path| {
420435 debug ! ( "adding local variable %d" , p_id) ;
@@ -431,10 +446,10 @@ fn visit_local(local: @Local, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
431446 kind : kind
432447 } ) ) ;
433448 }
434- oldvisit :: visit_local ( local , ( this , vt ) ) ;
449+ visit :: walk_local ( v , local , this ) ;
435450}
436451
437- fn visit_arm ( arm : & arm , ( this, vt ) : ( @mut IrMaps , vt < @ mut IrMaps > ) ) {
452+ fn visit_arm ( v : & mut LivenessVisitor , arm : & arm , this : @mut IrMaps ) {
438453 let def_map = this. tcx . def_map ;
439454 for pat in arm. pats . iter ( ) {
440455 do pat_util:: pat_bindings ( def_map, * pat) |bm, p_id, sp, path| {
@@ -450,10 +465,10 @@ fn visit_arm(arm: &arm, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
450465 } ) ) ;
451466 }
452467 }
453- oldvisit :: visit_arm ( arm , ( this , vt ) ) ;
468+ visit :: walk_arm ( v , arm , this ) ;
454469}
455470
456- fn visit_expr ( expr : @expr, ( this , vt ) : ( @mut IrMaps , vt < @ mut IrMaps > ) ) {
471+ fn visit_expr ( v : & mut LivenessVisitor , expr: @expr, this : @mut IrMaps ) {
457472 match expr. node {
458473 // live nodes required for uses or definitions of variables:
459474 expr_path( _) | expr_self => {
@@ -462,7 +477,7 @@ fn visit_expr(expr: @expr, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
462477 if moves:: moved_variable_node_id_from_def ( def) . is_some ( ) {
463478 this. add_live_node_for_node ( expr. id , ExprNode ( expr. span ) ) ;
464479 }
465- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
480+ visit :: walk_expr ( v , expr , this ) ;
466481 }
467482 expr_fn_block( * ) => {
468483 // Interesting control flow (for loops can contain labeled
@@ -495,18 +510,18 @@ fn visit_expr(expr: @expr, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
495510 }
496511 this. set_captures ( expr. id , call_caps) ;
497512
498- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
513+ visit :: walk_expr ( v , expr , this ) ;
499514 }
500515
501516 // live nodes required for interesting control flow:
502517 expr_if( * ) | expr_match( * ) | expr_while( * ) | expr_loop( * ) => {
503518 this. add_live_node_for_node ( expr. id , ExprNode ( expr. span ) ) ;
504- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
519+ visit :: walk_expr ( v , expr , this ) ;
505520 }
506521 expr_for_loop( * ) => fail ! ( "non-desugared expr_for_loop" ) ,
507522 expr_binary( _, op, _, _) if ast_util:: lazy_binop ( op) => {
508523 this. add_live_node_for_node ( expr. id , ExprNode ( expr. span ) ) ;
509- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
524+ visit :: walk_expr ( v , expr , this ) ;
510525 }
511526
512527 // otherwise, live nodes are not required:
@@ -518,7 +533,7 @@ fn visit_expr(expr: @expr, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
518533 expr_assign( * ) | expr_assign_op( * ) | expr_mac( * ) |
519534 expr_struct( * ) | expr_repeat( * ) | expr_paren( * ) |
520535 expr_inline_asm( * ) => {
521- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
536+ visit :: walk_expr ( v , expr , this ) ;
522537 }
523538 }
524539}
@@ -1408,7 +1423,7 @@ impl Liveness {
14081423// _______________________________________________________________________
14091424// Checking for error conditions
14101425
1411- fn check_local( local : @Local , ( this, vt ) : ( @Liveness , vt < @ Liveness > ) ) {
1426+ fn check_local( vt : & mut ErrorCheckVisitor , local : @Local , this : @Liveness ) {
14121427 match local. init {
14131428 Some ( _) => {
14141429 this. warn_about_unused_or_dead_vars_in_pat ( local. pat ) ;
@@ -1434,34 +1449,34 @@ fn check_local(local: @Local, (this, vt): (@Liveness, vt<@Liveness>)) {
14341449 }
14351450 }
14361451
1437- oldvisit :: visit_local ( local , ( this , vt ) ) ;
1452+ visit :: walk_local ( vt , local , this ) ;
14381453}
14391454
1440- fn check_arm( arm : & arm , ( this, vt ) : ( @Liveness , vt < @ Liveness > ) ) {
1455+ fn check_arm( vt : & mut ErrorCheckVisitor , arm : & arm , this : @Liveness ) {
14411456 do this. arm_pats_bindings ( arm. pats ) |ln, var, sp, id| {
14421457 this. warn_about_unused ( sp, id, ln, var) ;
14431458 }
1444- oldvisit :: visit_arm ( arm , ( this , vt ) ) ;
1459+ visit :: walk_arm ( vt , arm , this ) ;
14451460}
14461461
1447- fn check_expr ( expr : @expr, ( this , vt ) : ( @Liveness , vt < @ Liveness > ) ) {
1462+ fn check_expr ( vt : & mut ErrorCheckVisitor , expr: @expr, this : @Liveness ) {
14481463 match expr. node {
14491464 expr_assign( l, r) => {
14501465 this. check_lvalue ( l, vt) ;
1451- ( vt. visit_expr ) ( r, ( this, vt ) ) ;
1466+ vt. visit_expr ( r, this) ;
14521467
1453- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
1468+ visit :: walk_expr ( vt , expr , this ) ;
14541469 }
14551470
14561471 expr_assign_op( _, _, l, _) => {
14571472 this. check_lvalue ( l, vt) ;
14581473
1459- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
1474+ visit :: walk_expr ( vt , expr , this ) ;
14601475 }
14611476
14621477 expr_inline_asm( ref ia) => {
14631478 for & ( _, input) in ia. inputs . iter ( ) {
1464- ( vt. visit_expr ) ( input, ( this, vt ) ) ;
1479+ vt. visit_expr ( input, this) ;
14651480 }
14661481
14671482 // Output operands must be lvalues
@@ -1472,10 +1487,10 @@ fn check_expr(expr: @expr, (this, vt): (@Liveness, vt<@Liveness>)) {
14721487 }
14731488 _ => { }
14741489 }
1475- ( vt. visit_expr ) ( out, ( this, vt ) ) ;
1490+ vt. visit_expr ( out, this) ;
14761491 }
14771492
1478- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
1493+ visit :: walk_expr ( vt , expr , this ) ;
14791494 }
14801495
14811496 // no correctness conditions related to liveness
@@ -1487,18 +1502,19 @@ fn check_expr(expr: @expr, (this, vt): (@Liveness, vt<@Liveness>)) {
14871502 expr_again( * ) | expr_lit( _) | expr_block( * ) |
14881503 expr_mac( * ) | expr_addr_of( * ) | expr_struct( * ) | expr_repeat( * ) |
14891504 expr_paren( * ) | expr_fn_block( * ) | expr_path( * ) | expr_self( * ) => {
1490- oldvisit :: visit_expr ( expr , ( this , vt ) ) ;
1505+ visit :: walk_expr ( vt , expr , this ) ;
14911506 }
14921507 expr_for_loop( * ) => fail ! ( "non-desugared expr_for_loop" )
14931508 }
14941509}
14951510
1496- fn check_fn ( _fk : & oldvisit:: fn_kind ,
1511+ fn check_fn ( _v : & mut ErrorCheckVisitor ,
1512+ _fk : & visit:: fn_kind ,
14971513 _decl : & fn_decl ,
14981514 _body : & Block ,
14991515 _sp : span ,
15001516 _id : NodeId ,
1501- ( _self, _v ) : ( @Liveness , vt < @ Liveness > ) ) {
1517+ _self : @Liveness ) {
15021518 // do not check contents of nested fns
15031519}
15041520
@@ -1513,7 +1529,7 @@ impl Liveness {
15131529 pub fn check_ret ( & self ,
15141530 id : NodeId ,
15151531 sp : span ,
1516- _fk : & oldvisit :: fn_kind ,
1532+ _fk : & visit :: fn_kind ,
15171533 entry_ln : LiveNode ) {
15181534 if self . live_on_entry ( entry_ln, self . s . no_ret_var ) . is_some ( ) {
15191535 // if no_ret_var is live, then we fall off the end of the
@@ -1533,7 +1549,7 @@ impl Liveness {
15331549 }
15341550 }
15351551
1536- pub fn check_lvalue ( @self , expr: @expr, vt : vt < @ Liveness > ) {
1552+ pub fn check_lvalue ( @self , expr: @expr, vt : & mut ErrorCheckVisitor ) {
15371553 match expr. node {
15381554 expr_path( _) => {
15391555 match self . tcx . def_map . get_copy ( & expr. id ) {
@@ -1562,7 +1578,7 @@ impl Liveness {
15621578 _ => {
15631579 // For other kinds of lvalues, no checks are required,
15641580 // and any embedded expressions are actually rvalues
1565- oldvisit :: visit_expr ( expr , ( self , vt ) ) ;
1581+ visit :: walk_expr ( vt , expr , self ) ;
15661582 }
15671583 }
15681584 }
0 commit comments