2727//! the format of the output away from extracting it from the compiler.
2828//! DumpCsvVisitor walks the AST and processes it.
2929
30- use super :: { escape, generated_code, recorder, SaveContext } ;
30+
31+ use super :: { escape, generated_code, recorder, SaveContext , PathCollector } ;
3132
3233use session:: Session ;
3334
@@ -59,9 +60,6 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
5960 sess : & ' l Session ,
6061 analysis : & ' l ty:: CrateAnalysis < ' tcx > ,
6162
62- collected_paths : Vec < ( NodeId , ast:: Path , bool , recorder:: Row ) > ,
63- collecting : bool ,
64-
6563 span : SpanUtils < ' l > ,
6664 fmt : FmtStrs < ' l > ,
6765
@@ -79,8 +77,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
7977 err_count : Cell :: new ( 0 )
8078 } ) ,
8179 analysis : analysis,
82- collected_paths : vec ! [ ] ,
83- collecting : false ,
8480 span : SpanUtils {
8581 sess : sess,
8682 err_count : Cell :: new ( 0 )
@@ -281,12 +277,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
281277
282278 fn process_formals ( & mut self , formals : & Vec < ast:: Arg > , qualname : & str ) {
283279 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 ) ;
288283 let span_utils = self . span . clone ( ) ;
289- for & ( id, ref p, _, _) in & self . collected_paths {
284+ for & ( id, ref p, _, _) in & collector . collected_paths {
290285 let typ =
291286 ppaux:: ty_to_string (
292287 & self . analysis . ty_cx ,
@@ -300,7 +295,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
300295 & path_to_string ( p) ,
301296 & typ[ ..] ) ;
302297 }
303- self . collected_paths . clear ( ) ;
304298 }
305299 }
306300
@@ -1026,7 +1020,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
10261020
10271021 match p. node {
10281022 ast:: PatStruct ( ref path, ref fields, _) => {
1029- self . collected_paths . push ( ( p. id , path. clone ( ) , false , recorder:: StructRef ) ) ;
10301023 visit:: walk_path ( self , path) ;
10311024
10321025 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> {
10631056 }
10641057 }
10651058 }
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- }
10921059 _ => visit:: walk_pat ( self , p)
10931060 }
10941061 }
@@ -1421,23 +1388,20 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14211388
14221389 fn visit_pat ( & mut self , p : & ast:: Pat ) {
14231390 self . process_pat ( p) ;
1424- if !self . collecting {
1425- self . collected_paths . clear ( ) ;
1426- }
14271391 }
14281392
14291393 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 ( ) ;
14321395 for pattern in & arm. pats {
14331396 // collect paths from the arm's patterns
1434- self . visit_pat ( & * * pattern) ;
1397+ collector. visit_pat ( & pattern) ;
1398+ self . visit_pat ( & pattern) ;
14351399 }
14361400
14371401 // This is to get around borrow checking, because we need mut self to call process_path.
14381402 let mut paths_to_process = vec ! [ ] ;
14391403 // 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 {
14411405 let def_map = self . analysis . ty_cx . def_map . borrow ( ) ;
14421406 if !def_map. contains_key ( & id) {
14431407 self . sess . span_bug ( p. span ,
@@ -1475,8 +1439,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14751439 for & ( id, ref path, ref_kind) in & paths_to_process {
14761440 self . process_path ( id, path. span , path, ref_kind) ;
14771441 }
1478- self . collecting = false ;
1479- self . collected_paths . clear ( ) ;
14801442 visit:: walk_expr_opt ( self , & arm. guard ) ;
14811443 self . visit_expr ( & * arm. body ) ;
14821444 }
@@ -1496,14 +1458,13 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14961458
14971459 // The local could declare multiple new vars, we must walk the
14981460 // 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 ) ;
15031464
15041465 let value = self . span . snippet ( l. span ) ;
15051466
1506- for & ( id, ref p, ref immut, _) in & self . collected_paths {
1467+ for & ( id, ref p, ref immut, _) in & collector . collected_paths {
15071468 let value = if * immut { value. to_string ( ) } else { "<mutable>" . to_string ( ) } ;
15081469 let types = self . analysis . ty_cx . node_types ( ) ;
15091470 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> {
15181479 & value[ ..] ,
15191480 & typ[ ..] ) ;
15201481 }
1521- self . collected_paths . clear ( ) ;
15221482
15231483 // Just walk the initialiser and type (don't want to walk the pattern again).
15241484 visit:: walk_ty_opt ( self , & l. ty ) ;
0 commit comments