@@ -397,29 +397,33 @@ impl id_range {
397
397
}
398
398
}
399
399
400
- pub fn id_visitor ( vfn : @fn ( NodeId ) , pass_through_items : bool )
400
+ pub fn id_visitor ( operation : @IdVisitingOperation , pass_through_items : bool )
401
401
-> @mut Visitor < ( ) > {
402
402
let visitor = @mut IdVisitor {
403
- visit_callback : vfn ,
403
+ operation : operation ,
404
404
pass_through_items : pass_through_items,
405
405
visited_outermost : false ,
406
406
} ;
407
407
visitor as @mut Visitor < ( ) >
408
408
}
409
409
410
+ pub trait IdVisitingOperation {
411
+ fn visit_id ( & self , node_id : NodeId ) ;
412
+ }
413
+
410
414
pub struct IdVisitor {
411
- visit_callback : @fn ( NodeId ) ,
415
+ operation : @IdVisitingOperation ,
412
416
pass_through_items : bool ,
413
417
visited_outermost : bool ,
414
418
}
415
419
416
420
impl IdVisitor {
417
421
fn visit_generics_helper ( & self , generics : & Generics ) {
418
422
for type_parameter in generics. ty_params . iter ( ) {
419
- ( self . visit_callback ) ( type_parameter. id )
423
+ self . operation . visit_id ( type_parameter. id )
420
424
}
421
425
for lifetime in generics. lifetimes . iter ( ) {
422
- ( self . visit_callback ) ( lifetime. id )
426
+ self . operation . visit_id ( lifetime. id )
423
427
}
424
428
}
425
429
}
@@ -430,26 +434,26 @@ impl Visitor<()> for IdVisitor {
430
434
_: Span ,
431
435
node_id : NodeId ,
432
436
env : ( ) ) {
433
- ( self . visit_callback ) ( node_id) ;
437
+ self . operation . visit_id ( node_id) ;
434
438
visit:: walk_mod ( self , module, env)
435
439
}
436
440
437
441
fn visit_view_item ( & mut self , view_item : & view_item , env : ( ) ) {
438
442
match view_item. node {
439
443
view_item_extern_mod( _, _, _, node_id) => {
440
- ( self . visit_callback ) ( node_id)
444
+ self . operation . visit_id ( node_id)
441
445
}
442
446
view_item_use( ref view_paths) => {
443
447
for view_path in view_paths. iter ( ) {
444
448
match view_path. node {
445
449
view_path_simple( _, _, node_id) |
446
450
view_path_glob( _, node_id) => {
447
- ( self . visit_callback ) ( node_id)
451
+ self . operation . visit_id ( node_id)
448
452
}
449
453
view_path_list( _, ref paths, node_id) => {
450
- ( self . visit_callback ) ( node_id) ;
454
+ self . operation . visit_id ( node_id) ;
451
455
for path in paths. iter ( ) {
452
- ( self . visit_callback ) ( path. node . id )
456
+ self . operation . visit_id ( path. node . id )
453
457
}
454
458
}
455
459
}
@@ -460,7 +464,7 @@ impl Visitor<()> for IdVisitor {
460
464
}
461
465
462
466
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 ) ;
464
468
visit:: walk_foreign_item ( self , foreign_item, env)
465
469
}
466
470
@@ -473,11 +477,11 @@ impl Visitor<()> for IdVisitor {
473
477
}
474
478
}
475
479
476
- ( self . visit_callback ) ( item. id ) ;
480
+ self . operation . visit_id ( item. id ) ;
477
481
match item. node {
478
482
item_enum( ref enum_definition, _) => {
479
483
for variant in enum_definition. variants . iter ( ) {
480
- ( self . visit_callback ) ( variant. node . id )
484
+ self . operation . visit_id ( variant. node . id )
481
485
}
482
486
}
483
487
_ => { }
@@ -489,22 +493,22 @@ impl Visitor<()> for IdVisitor {
489
493
}
490
494
491
495
fn visit_local ( & mut self , local : @Local , env : ( ) ) {
492
- ( self . visit_callback ) ( local. id ) ;
496
+ self . operation . visit_id ( local. id ) ;
493
497
visit:: walk_local ( self , local, env)
494
498
}
495
499
496
500
fn visit_block ( & mut self , block : & Block , env : ( ) ) {
497
- ( self . visit_callback ) ( block. id ) ;
501
+ self . operation . visit_id ( block. id ) ;
498
502
visit:: walk_block ( self , block, env)
499
503
}
500
504
501
505
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) ) ;
503
507
visit:: walk_stmt ( self , statement, env)
504
508
}
505
509
506
510
fn visit_pat ( & mut self , pattern : @Pat , env : ( ) ) {
507
- ( self . visit_callback ) ( pattern. id ) ;
511
+ self . operation . visit_id ( pattern. id ) ;
508
512
visit:: walk_pat ( self , pattern, env)
509
513
}
510
514
@@ -513,17 +517,17 @@ impl Visitor<()> for IdVisitor {
513
517
{
514
518
let optional_callee_id = expression. get_callee_id ( ) ;
515
519
for callee_id in optional_callee_id. iter ( ) {
516
- ( self . visit_callback ) ( * callee_id)
520
+ self . operation . visit_id ( * callee_id)
517
521
}
518
522
}
519
- ( self . visit_callback ) ( expression. id ) ;
523
+ self . operation . visit_id ( expression. id ) ;
520
524
visit:: walk_expr ( self , expression, env)
521
525
}
522
526
523
527
fn visit_ty ( & mut self , typ : & Ty , env : ( ) ) {
524
- ( self . visit_callback ) ( typ. id ) ;
528
+ self . operation . visit_id ( typ. id ) ;
525
529
match typ. node {
526
- ty_path( _, _, id) => ( self . visit_callback ) ( id) ,
530
+ ty_path( _, _, id) => self . operation . visit_id ( id) ,
527
531
_ => { }
528
532
}
529
533
visit:: walk_ty ( self , typ, env)
@@ -549,21 +553,21 @@ impl Visitor<()> for IdVisitor {
549
553
}
550
554
}
551
555
552
- ( self . visit_callback ) ( node_id) ;
556
+ self . operation . visit_id ( node_id) ;
553
557
554
558
match * function_kind {
555
559
visit:: fk_item_fn( _, generics, _, _) => {
556
560
self . visit_generics_helper ( generics)
557
561
}
558
562
visit:: fk_method( _, generics, method) => {
559
- ( self . visit_callback ) ( method. self_id ) ;
563
+ self . operation . visit_id ( method. self_id ) ;
560
564
self . visit_generics_helper ( generics)
561
565
}
562
566
visit:: fk_anon( _) | visit:: fk_fn_block => { }
563
567
}
564
568
565
569
for argument in function_declaration. inputs . iter ( ) {
566
- ( self . visit_callback ) ( argument. id )
570
+ self . operation . visit_id ( argument. id )
567
571
}
568
572
569
573
visit:: walk_fn ( self ,
@@ -583,25 +587,36 @@ impl Visitor<()> for IdVisitor {
583
587
}
584
588
585
589
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 ) ;
587
591
visit:: walk_struct_field ( self , struct_field, env)
588
592
}
589
593
}
590
594
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 ) {
592
597
let mut id_visitor = IdVisitor {
593
- visit_callback : vfn ,
598
+ operation : operation ,
594
599
pass_through_items : true ,
595
600
visited_outermost : false ,
596
601
} ;
597
602
item. accept ( ( ) , & mut id_visitor) ;
598
603
}
599
604
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)
604
612
}
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 ) ;
605
620
* result
606
621
}
607
622
0 commit comments