about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-05-05 18:46:09 +1200
committerNick Cameron <ncameron@mozilla.com>2015-05-14 15:28:01 +1200
commitb248ee8746c4c016dd3001e59086f2c2f868f07e (patch)
treec4d6b572841d35eae038583e507c7ced031cde42
parent4f9b04bf9e14bb8cb718e5dd9564ac0b698a8395 (diff)
downloadrust-b248ee8746c4c016dd3001e59086f2c2f868f07e.tar.gz
rust-b248ee8746c4c016dd3001e59086f2c2f868f07e.zip
Use the new-style API for external crate listings
-rw-r--r--src/librustc_trans/save/dump_csv.rs32
-rw-r--r--src/librustc_trans/save/mod.rs28
2 files changed, 45 insertions, 15 deletions
diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs
index ab66123c4d7..bfd5a618769 100644
--- a/src/librustc_trans/save/dump_csv.rs
+++ b/src/librustc_trans/save/dump_csv.rs
@@ -27,7 +27,7 @@
 //! the format of the output away from extracting it from the compiler.
 //! DumpCsvVisitor walks the AST and processes it.
 
-use super::{escape, generated_code, recorder};
+use super::{escape, generated_code, recorder, SaveContext};
 
 use session::Session;
 
@@ -55,6 +55,7 @@ use util::ppaux;
 
 
 pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
+    save_ctxt: SaveContext<'l>,
     sess: &'l Session,
     analysis: &'l ty::CrateAnalysis<'tcx>,
 
@@ -68,20 +69,12 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
 }
 
 impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
-    fn nest<F>(&mut self, scope_id: NodeId, f: F) where
-        F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
-    {
-        let parent_scope = self.cur_scope;
-        self.cur_scope = scope_id;
-        f(self);
-        self.cur_scope = parent_scope;
-    }
-
     pub fn new(sess: &'l Session,
                analysis: &'l ty::CrateAnalysis<'tcx>,
                output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
         DumpCsvVisitor {
             sess: sess,
+            save_ctxt: SaveContext { sess: sess },
             analysis: analysis,
             collected_paths: vec![],
             collecting: false,
@@ -101,14 +94,23 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
         }
     }
 
+    fn nest<F>(&mut self, scope_id: NodeId, f: F) where
+        F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
+    {
+        let parent_scope = self.cur_scope;
+        self.cur_scope = scope_id;
+        f(self);
+        self.cur_scope = parent_scope;
+    }
+
     pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
-        // the current crate
+        // The current crate.
         self.fmt.crate_str(krate.span, name);
 
-        // dump info about all the external crates referenced from this crate
-        self.sess.cstore.iter_crate_data(|n, cmd| {
-            self.fmt.external_crate_str(krate.span, &cmd.name, n);
-        });
+        // Dump info about all the external crates referenced from this crate.
+        for c in &self.save_ctxt.get_external_crates() {
+            self.fmt.external_crate_str(krate.span, &c.name, c.number);            
+        }
         self.fmt.recorder.record("end_external_crates\n");
     }
 
diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs
index 7421344548c..260879ed324 100644
--- a/src/librustc_trans/save/mod.rs
+++ b/src/librustc_trans/save/mod.rs
@@ -23,6 +23,34 @@ mod recorder;
 
 mod dump_csv;
 
+pub struct SaveContext<'l> {
+    sess: &'l Session,
+}
+
+pub struct CrateData {
+    pub name: String,
+    pub number: u32,
+}
+
+impl<'l> SaveContext<'l> {
+    pub fn new<'ll>(sess: &'ll Session) -> SaveContext<'ll> {
+        SaveContext {
+            sess: sess
+        }
+    }
+
+    // List external crates used by the current crate.
+    pub fn get_external_crates(&self) -> Vec<CrateData> {
+        let mut result = Vec::new();
+
+        self.sess.cstore.iter_crate_data(|n, cmd| {
+            result.push(CrateData { name: cmd.name.clone(), number: n });
+        });
+
+        result
+    }
+}
+
 #[allow(deprecated)]
 pub fn process_crate(sess: &Session,
                      krate: &ast::Crate,