@@ -397,29 +397,33 @@ impl id_range {
397397 }
398398}
399399
400- pub fn id_visitor ( vfn : @fn ( NodeId ) , pass_through_items : bool )
400+ pub fn id_visitor ( operation : @IdVisitingOperation , pass_through_items : bool )
401401 -> @mut Visitor < ( ) > {
402402 let visitor = @mut IdVisitor {
403- visit_callback : vfn ,
403+ operation : operation ,
404404 pass_through_items : pass_through_items,
405405 visited_outermost : false ,
406406 } ;
407407 visitor as @mut Visitor < ( ) >
408408}
409409
410+ pub trait IdVisitingOperation {
411+ fn visit_id ( & self , node_id : NodeId ) ;
412+ }
413+
410414pub struct IdVisitor {
411- visit_callback : @fn ( NodeId ) ,
415+ operation : @IdVisitingOperation ,
412416 pass_through_items : bool ,
413417 visited_outermost : bool ,
414418}
415419
416420impl IdVisitor {
417421 fn visit_generics_helper ( & self , generics : & Generics ) {
418422 for type_parameter in generics. ty_params . iter ( ) {
419- ( self . visit_callback ) ( type_parameter. id )
423+ self . operation . visit_id ( type_parameter. id )
420424 }
421425 for lifetime in generics. lifetimes . iter ( ) {
422- ( self . visit_callback ) ( lifetime. id )
426+ self . operation . visit_id ( lifetime. id )
423427 }
424428 }
425429}
@@ -430,26 +434,26 @@ impl Visitor<()> for IdVisitor {
430434 _: Span ,
431435 node_id : NodeId ,
432436 env : ( ) ) {
433- ( self . visit_callback ) ( node_id) ;
437+ self . operation . visit_id ( node_id) ;
434438 visit:: walk_mod ( self , module, env)
435439 }
436440
437441 fn visit_view_item ( & mut self , view_item : & view_item , env : ( ) ) {
438442 match view_item. node {
439443 view_item_extern_mod( _, _, _, node_id) => {
440- ( self . visit_callback ) ( node_id)
444+ self . operation . visit_id ( node_id)
441445 }
442446 view_item_use( ref view_paths) => {
443447 for view_path in view_paths. iter ( ) {
444448 match view_path. node {
445449 view_path_simple( _, _, node_id) |
446450 view_path_glob( _, node_id) => {
447- ( self . visit_callback ) ( node_id)
451+ self . operation . visit_id ( node_id)
448452 }
449453 view_path_list( _, ref paths, node_id) => {
450- ( self . visit_callback ) ( node_id) ;
454+ self . operation . visit_id ( node_id) ;
451455 for path in paths. iter ( ) {
452- ( self . visit_callback ) ( path. node . id )
456+ self . operation . visit_id ( path. node . id )
453457 }
454458 }
455459 }
@@ -460,7 +464,7 @@ impl Visitor<()> for IdVisitor {
460464 }
461465
462466 fn visit_foreign_item ( & mut self , foreign_item : @foreign_item , env : ( ) ) {
463- ( self . visit_callback ) ( foreign_item. id ) ;
467+ self . operation . visit_id ( foreign_item. id ) ;
464468 visit:: walk_foreign_item ( self , foreign_item, env)
465469 }
466470
@@ -473,11 +477,11 @@ impl Visitor<()> for IdVisitor {
473477 }
474478 }
475479
476- ( self . visit_callback ) ( item. id ) ;
480+ self . operation . visit_id ( item. id ) ;
477481 match item. node {
478482 item_enum( ref enum_definition, _) => {
479483 for variant in enum_definition. variants . iter ( ) {
480- ( self . visit_callback ) ( variant. node . id )
484+ self . operation . visit_id ( variant. node . id )
481485 }
482486 }
483487 _ => { }
@@ -489,22 +493,22 @@ impl Visitor<()> for IdVisitor {
489493 }
490494
491495 fn visit_local ( & mut self , local : @Local , env : ( ) ) {
492- ( self . visit_callback ) ( local. id ) ;
496+ self . operation . visit_id ( local. id ) ;
493497 visit:: walk_local ( self , local, env)
494498 }
495499
496500 fn visit_block ( & mut self , block : & Block , env : ( ) ) {
497- ( self . visit_callback ) ( block. id ) ;
501+ self . operation . visit_id ( block. id ) ;
498502 visit:: walk_block ( self , block, env)
499503 }
500504
501505 fn visit_stmt ( & mut self , statement : @Stmt , env : ( ) ) {
502- ( self . visit_callback ) ( ast_util:: stmt_id ( statement) ) ;
506+ self . operation . visit_id ( ast_util:: stmt_id ( statement) ) ;
503507 visit:: walk_stmt ( self , statement, env)
504508 }
505509
506510 fn visit_pat ( & mut self , pattern : @Pat , env : ( ) ) {
507- ( self . visit_callback ) ( pattern. id ) ;
511+ self . operation . visit_id ( pattern. id ) ;
508512 visit:: walk_pat ( self , pattern, env)
509513 }
510514
@@ -513,17 +517,17 @@ impl Visitor<()> for IdVisitor {
513517 {
514518 let optional_callee_id = expression. get_callee_id ( ) ;
515519 for callee_id in optional_callee_id. iter ( ) {
516- ( self . visit_callback ) ( * callee_id)
520+ self . operation . visit_id ( * callee_id)
517521 }
518522 }
519- ( self . visit_callback ) ( expression. id ) ;
523+ self . operation . visit_id ( expression. id ) ;
520524 visit:: walk_expr ( self , expression, env)
521525 }
522526
523527 fn visit_ty ( & mut self , typ : & Ty , env : ( ) ) {
524- ( self . visit_callback ) ( typ. id ) ;
528+ self . operation . visit_id ( typ. id ) ;
525529 match typ. node {
526- ty_path( _, _, id) => ( self . visit_callback ) ( id) ,
530+ ty_path( _, _, id) => self . operation . visit_id ( id) ,
527531 _ => { }
528532 }
529533 visit:: walk_ty ( self , typ, env)
@@ -549,21 +553,21 @@ impl Visitor<()> for IdVisitor {
549553 }
550554 }
551555
552- ( self . visit_callback ) ( node_id) ;
556+ self . operation . visit_id ( node_id) ;
553557
554558 match * function_kind {
555559 visit:: fk_item_fn( _, generics, _, _) => {
556560 self . visit_generics_helper ( generics)
557561 }
558562 visit:: fk_method( _, generics, method) => {
559- ( self . visit_callback ) ( method. self_id ) ;
563+ self . operation . visit_id ( method. self_id ) ;
560564 self . visit_generics_helper ( generics)
561565 }
562566 visit:: fk_anon( _) | visit:: fk_fn_block => { }
563567 }
564568
565569 for argument in function_declaration. inputs . iter ( ) {
566- ( self . visit_callback ) ( argument. id )
570+ self . operation . visit_id ( argument. id )
567571 }
568572
569573 visit:: walk_fn ( self ,
@@ -583,25 +587,36 @@ impl Visitor<()> for IdVisitor {
583587 }
584588
585589 fn visit_struct_field ( & mut self , struct_field : @struct_field , env : ( ) ) {
586- ( self . visit_callback ) ( struct_field. node . id ) ;
590+ self . operation . visit_id ( struct_field. node . id ) ;
587591 visit:: walk_struct_field ( self , struct_field, env)
588592 }
589593}
590594
591- pub fn visit_ids_for_inlined_item ( item : & inlined_item , vfn : @fn ( NodeId ) ) {
595+ pub fn visit_ids_for_inlined_item ( item : & inlined_item ,
596+ operation : @IdVisitingOperation ) {
592597 let mut id_visitor = IdVisitor {
593- visit_callback : vfn ,
598+ operation : operation ,
594599 pass_through_items : true ,
595600 visited_outermost : false ,
596601 } ;
597602 item. accept ( ( ) , & mut id_visitor) ;
598603}
599604
600- pub fn compute_id_range ( visit_ids_fn : & fn ( @fn ( NodeId ) ) ) -> id_range {
601- let result = @mut id_range:: max ( ) ;
602- do visit_ids_fn |id| {
603- result. add ( id) ;
605+ struct IdRangeComputingVisitor {
606+ result : @mut id_range ,
607+ }
608+
609+ impl IdVisitingOperation for IdRangeComputingVisitor {
610+ fn visit_id ( & self , id : NodeId ) {
611+ self . result . add ( id)
604612 }
613+ }
614+
615+ pub fn compute_id_range ( visit_ids_fn : & fn ( @IdVisitingOperation ) ) -> id_range {
616+ let result = @mut id_range:: max ( ) ;
617+ visit_ids_fn ( @IdRangeComputingVisitor {
618+ result : result,
619+ } as @IdVisitingOperation ) ;
605620 * result
606621}
607622
0 commit comments