Skip to content

Commit 225f14c

Browse files
committed
---
yaml --- r: 210825 b: refs/heads/try c: b248ee8 h: refs/heads/master i: 210823: eda2009 v: v3
1 parent c6d6011 commit 225f14c

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 4f9b04bf9e14bb8cb718e5dd9564ac0b698a8395
5+
refs/heads/try: b248ee8746c4c016dd3001e59086f2c2f868f07e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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

branches/try/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)