27
27
//! the format of the output away from extracting it from the compiler.
28
28
//! DumpCsvVisitor walks the AST and processes it.
29
29
30
- use super :: { escape, generated_code, recorder, SaveContext } ;
30
+
31
+ use super :: { escape, generated_code, recorder, SaveContext , PathCollector } ;
31
32
32
33
use session:: Session ;
33
34
@@ -59,9 +60,6 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
59
60
sess : & ' l Session ,
60
61
analysis : & ' l ty:: CrateAnalysis < ' tcx > ,
61
62
62
- collected_paths : Vec < ( NodeId , ast:: Path , bool , recorder:: Row ) > ,
63
- collecting : bool ,
64
-
65
63
span : SpanUtils < ' l > ,
66
64
fmt : FmtStrs < ' l > ,
67
65
@@ -79,8 +77,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
79
77
err_count : Cell :: new ( 0 )
80
78
} ) ,
81
79
analysis : analysis,
82
- collected_paths : vec ! [ ] ,
83
- collecting : false ,
84
80
span : SpanUtils {
85
81
sess : sess,
86
82
err_count : Cell :: new ( 0 )
@@ -281,12 +277,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
281
277
282
278
fn process_formals ( & mut self , formals : & Vec < ast:: Arg > , qualname : & str ) {
283
279
for arg in formals {
284
- assert ! ( self . collected_paths. is_empty( ) && !self . collecting) ;
285
- self . collecting = true ;
286
- self . visit_pat ( & * arg. pat ) ;
287
- self . collecting = false ;
280
+ self . visit_pat ( & arg. pat ) ;
281
+ let mut collector = PathCollector :: new ( ) ;
282
+ collector. visit_pat ( & arg. pat ) ;
288
283
let span_utils = self . span . clone ( ) ;
289
- for & ( id, ref p, _, _) in & self . collected_paths {
284
+ for & ( id, ref p, _, _) in & collector . collected_paths {
290
285
let typ =
291
286
ppaux:: ty_to_string (
292
287
& self . analysis . ty_cx ,
@@ -300,7 +295,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
300
295
& path_to_string ( p) ,
301
296
& typ[ ..] ) ;
302
297
}
303
- self . collected_paths . clear ( ) ;
304
298
}
305
299
}
306
300
@@ -1026,7 +1020,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
1026
1020
1027
1021
match p. node {
1028
1022
ast:: PatStruct ( ref path, ref fields, _) => {
1029
- self . collected_paths . push ( ( p. id , path. clone ( ) , false , recorder:: StructRef ) ) ;
1030
1023
visit:: walk_path ( self , path) ;
1031
1024
1032
1025
let def = self . analysis . ty_cx . def_map . borrow ( ) . get ( & p. id ) . unwrap ( ) . full_def ( ) ;
@@ -1063,32 +1056,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
1063
1056
}
1064
1057
}
1065
1058
}
1066
- ast:: PatEnum ( ref path, _) |
1067
- ast:: PatQPath ( _, ref path) => {
1068
- self . collected_paths . push ( ( p. id , path. clone ( ) , false , recorder:: VarRef ) ) ;
1069
- visit:: walk_pat ( self , p) ;
1070
- }
1071
- ast:: PatIdent ( bm, ref path1, ref optional_subpattern) => {
1072
- let immut = match bm {
1073
- // Even if the ref is mut, you can't change the ref, only
1074
- // the data pointed at, so showing the initialising expression
1075
- // is still worthwhile.
1076
- ast:: BindByRef ( _) => true ,
1077
- ast:: BindByValue ( mt) => {
1078
- match mt {
1079
- ast:: MutMutable => false ,
1080
- ast:: MutImmutable => true ,
1081
- }
1082
- }
1083
- } ;
1084
- // collect path for either visit_local or visit_arm
1085
- let path = ast_util:: ident_to_path ( path1. span , path1. node ) ;
1086
- self . collected_paths . push ( ( p. id , path, immut, recorder:: VarRef ) ) ;
1087
- match * optional_subpattern {
1088
- None => { }
1089
- Some ( ref subpattern) => self . visit_pat ( & * * subpattern)
1090
- }
1091
- }
1092
1059
_ => visit:: walk_pat ( self , p)
1093
1060
}
1094
1061
}
@@ -1421,23 +1388,20 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1421
1388
1422
1389
fn visit_pat ( & mut self , p : & ast:: Pat ) {
1423
1390
self . process_pat ( p) ;
1424
- if !self . collecting {
1425
- self . collected_paths . clear ( ) ;
1426
- }
1427
1391
}
1428
1392
1429
1393
fn visit_arm ( & mut self , arm : & ast:: Arm ) {
1430
- assert ! ( self . collected_paths. is_empty( ) && !self . collecting) ;
1431
- self . collecting = true ;
1394
+ let mut collector = PathCollector :: new ( ) ;
1432
1395
for pattern in & arm. pats {
1433
1396
// collect paths from the arm's patterns
1434
- self . visit_pat ( & * * pattern) ;
1397
+ collector. visit_pat ( & pattern) ;
1398
+ self . visit_pat ( & pattern) ;
1435
1399
}
1436
1400
1437
1401
// This is to get around borrow checking, because we need mut self to call process_path.
1438
1402
let mut paths_to_process = vec ! [ ] ;
1439
1403
// process collected paths
1440
- for & ( id, ref p, ref immut, ref_kind) in & self . collected_paths {
1404
+ for & ( id, ref p, ref immut, ref_kind) in & collector . collected_paths {
1441
1405
let def_map = self . analysis . ty_cx . def_map . borrow ( ) ;
1442
1406
if !def_map. contains_key ( & id) {
1443
1407
self . sess . span_bug ( p. span ,
@@ -1475,8 +1439,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1475
1439
for & ( id, ref path, ref_kind) in & paths_to_process {
1476
1440
self . process_path ( id, path. span , path, ref_kind) ;
1477
1441
}
1478
- self . collecting = false ;
1479
- self . collected_paths . clear ( ) ;
1480
1442
visit:: walk_expr_opt ( self , & arm. guard ) ;
1481
1443
self . visit_expr ( & * arm. body ) ;
1482
1444
}
@@ -1496,14 +1458,13 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1496
1458
1497
1459
// The local could declare multiple new vars, we must walk the
1498
1460
// pattern and collect them all.
1499
- assert ! ( self . collected_paths. is_empty( ) && !self . collecting) ;
1500
- self . collecting = true ;
1501
- self . visit_pat ( & * l. pat ) ;
1502
- self . collecting = false ;
1461
+ let mut collector = PathCollector :: new ( ) ;
1462
+ collector. visit_pat ( & l. pat ) ;
1463
+ self . visit_pat ( & l. pat ) ;
1503
1464
1504
1465
let value = self . span . snippet ( l. span ) ;
1505
1466
1506
- for & ( id, ref p, ref immut, _) in & self . collected_paths {
1467
+ for & ( id, ref p, ref immut, _) in & collector . collected_paths {
1507
1468
let value = if * immut { value. to_string ( ) } else { "<mutable>" . to_string ( ) } ;
1508
1469
let types = self . analysis . ty_cx . node_types ( ) ;
1509
1470
let typ = ppaux:: ty_to_string ( & self . analysis . ty_cx , * types. get ( & id) . unwrap ( ) ) ;
@@ -1518,7 +1479,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1518
1479
& value[ ..] ,
1519
1480
& typ[ ..] ) ;
1520
1481
}
1521
- self . collected_paths . clear ( ) ;
1522
1482
1523
1483
// Just walk the initialiser and type (don't want to walk the pattern again).
1524
1484
visit:: walk_ty_opt ( self , & l. ty ) ;
0 commit comments