@@ -688,24 +688,40 @@ impl<'v> Visitor<'v> for PathCollector {
688688 }
689689}
690690
691+ #[ derive( Clone , Copy , Debug ) ]
692+ pub enum Format {
693+ Csv ,
694+ Json ,
695+ }
696+
697+ impl Format {
698+ fn extension ( & self ) -> & ' static str {
699+ match * self {
700+ Format :: Csv => ".csv" ,
701+ Format :: Json => ".json" ,
702+ }
703+ }
704+ }
705+
691706pub fn process_crate < ' l , ' tcx > ( tcx : & ' l TyCtxt < ' tcx > ,
692707 lcx : & ' l lowering:: LoweringContext < ' l > ,
693708 krate : & ast:: Crate ,
694709 analysis : & ' l ty:: CrateAnalysis < ' l > ,
695710 cratename : & str ,
696- odir : Option < & Path > ) {
711+ odir : Option < & Path > ,
712+ format : Format ) {
697713 let _ignore = tcx. dep_graph . in_ignore ( ) ;
698714
699715 assert ! ( analysis. glob_map. is_some( ) ) ;
700716
701717 info ! ( "Dumping crate {}" , cratename) ;
702718
703719 // find a path to dump our data to
704- let mut root_path = match env:: var_os ( "DXR_RUST_TEMP_FOLDER " ) {
720+ let mut root_path = match env:: var_os ( "RUST_SAVE_ANALYSIS_FOLDER " ) {
705721 Some ( val) => PathBuf :: from ( val) ,
706722 None => match odir {
707- Some ( val) => val. join ( "dxr " ) ,
708- None => PathBuf :: from ( "dxr -temp" ) ,
723+ Some ( val) => val. join ( "save-analysis " ) ,
724+ None => PathBuf :: from ( "save-analysis -temp" ) ,
709725 } ,
710726 } ;
711727
@@ -729,22 +745,32 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l TyCtxt<'tcx>,
729745 } ;
730746 out_name. push_str ( & cratename) ;
731747 out_name. push_str ( & tcx. sess . opts . cg . extra_filename ) ;
732- out_name. push_str ( ".csv" ) ;
748+ out_name. push_str ( format . extension ( ) ) ;
733749 root_path. push ( & out_name) ;
734750 let mut output_file = File :: create ( & root_path) . unwrap_or_else ( |e| {
735751 let disp = root_path. display ( ) ;
736752 tcx. sess . fatal ( & format ! ( "Could not open {}: {}" , disp, e) ) ;
737753 } ) ;
738754 root_path. pop ( ) ;
755+ let output = & mut output_file;
739756
740757 let utils: SpanUtils < ' tcx > = SpanUtils :: new ( & tcx. sess ) ;
741758 let save_ctxt = SaveContext :: new ( tcx, lcx) ;
742- let mut dumper = CsvDumper :: new ( & mut output_file, utils) ;
743- let mut visitor = DumpVisitor :: new ( tcx, save_ctxt, analysis, & mut dumper) ;
744- // FIXME: we don't write anything!
745759
746- visitor. dump_crate_info ( cratename, krate) ;
747- visit:: walk_crate ( & mut visitor, krate) ;
760+ macro_rules! dump {
761+ ( $new_dumper: expr) => { {
762+ let mut dumper = $new_dumper;
763+ let mut visitor = DumpVisitor :: new( tcx, save_ctxt, analysis, & mut dumper) ;
764+
765+ visitor. dump_crate_info( cratename, krate) ;
766+ visit:: walk_crate( & mut visitor, krate) ;
767+ } }
768+ }
769+
770+ match format {
771+ Format :: Csv => dump ! ( CsvDumper :: new( output, utils) ) ,
772+ Format :: Json => dump ! ( JsonDumper :: new( output, utils. sess. codemap( ) ) ) ,
773+ }
748774}
749775
750776// Utility functions for the module.
0 commit comments