Skip to content

Commit b248ee8

Browse files
committed
Use the new-style API for external crate listings
1 parent 4f9b04b commit b248ee8

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

src/librustc_trans/save/dump_csv.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
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};
30+
use super::{escape, generated_code, recorder, SaveContext};
3131

3232
use session::Session;
3333

@@ -55,6 +55,7 @@ use util::ppaux;
5555

5656

5757
pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
58+
save_ctxt: SaveContext<'l>,
5859
sess: &'l Session,
5960
analysis: &'l ty::CrateAnalysis<'tcx>,
6061

@@ -68,20 +69,12 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
6869
}
6970

7071
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
71-
fn nest<F>(&mut self, scope_id: NodeId, f: F) where
72-
F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
73-
{
74-
let parent_scope = self.cur_scope;
75-
self.cur_scope = scope_id;
76-
f(self);
77-
self.cur_scope = parent_scope;
78-
}
79-
8072
pub fn new(sess: &'l Session,
8173
analysis: &'l ty::CrateAnalysis<'tcx>,
8274
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
8375
DumpCsvVisitor {
8476
sess: sess,
77+
save_ctxt: SaveContext { sess: sess },
8578
analysis: analysis,
8679
collected_paths: vec![],
8780
collecting: false,
@@ -101,14 +94,23 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
10194
}
10295
}
10396

97+
fn nest<F>(&mut self, scope_id: NodeId, f: F) where
98+
F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
99+
{
100+
let parent_scope = self.cur_scope;
101+
self.cur_scope = scope_id;
102+
f(self);
103+
self.cur_scope = parent_scope;
104+
}
105+
104106
pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
105-
// the current crate
107+
// The current crate.
106108
self.fmt.crate_str(krate.span, name);
107109

108-
// dump info about all the external crates referenced from this crate
109-
self.sess.cstore.iter_crate_data(|n, cmd| {
110-
self.fmt.external_crate_str(krate.span, &cmd.name, n);
111-
});
110+
// Dump info about all the external crates referenced from this crate.
111+
for c in &self.save_ctxt.get_external_crates() {
112+
self.fmt.external_crate_str(krate.span, &c.name, c.number);
113+
}
112114
self.fmt.recorder.record("end_external_crates\n");
113115
}
114116

src/librustc_trans/save/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ mod recorder;
2323

2424
mod dump_csv;
2525

26+
pub struct SaveContext<'l> {
27+
sess: &'l Session,
28+
}
29+
30+
pub struct CrateData {
31+
pub name: String,
32+
pub number: u32,
33+
}
34+
35+
impl<'l> SaveContext<'l> {
36+
pub fn new<'ll>(sess: &'ll Session) -> SaveContext<'ll> {
37+
SaveContext {
38+
sess: sess
39+
}
40+
}
41+
42+
// List external crates used by the current crate.
43+
pub fn get_external_crates(&self) -> Vec<CrateData> {
44+
let mut result = Vec::new();
45+
46+
self.sess.cstore.iter_crate_data(|n, cmd| {
47+
result.push(CrateData { name: cmd.name.clone(), number: n });
48+
});
49+
50+
result
51+
}
52+
}
53+
2654
#[allow(deprecated)]
2755
pub fn process_crate(sess: &Session,
2856
krate: &ast::Crate,

0 commit comments

Comments
 (0)