Skip to content

Commit

Permalink
Use the new-style API for external crate listings
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 14, 2015
1 parent 4f9b04b commit b248ee8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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>,

Expand All @@ -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,
Expand All @@ -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");
}

Expand Down
28 changes: 28 additions & 0 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -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,
Expand Down

0 comments on commit b248ee8

Please sign in to comment.