Skip to content

Commit cea73bf

Browse files
committed
move out function data
1 parent b248ee8 commit cea73bf

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

src/librustc_trans/save/dump_csv.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use util::ppaux;
5555

5656

5757
pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
58-
save_ctxt: SaveContext<'l>,
58+
save_ctxt: SaveContext<'l, 'tcx>,
5959
sess: &'l Session,
6060
analysis: &'l ty::CrateAnalysis<'tcx>,
6161

@@ -74,7 +74,10 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
7474
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
7575
DumpCsvVisitor {
7676
sess: sess,
77-
save_ctxt: SaveContext { sess: sess },
77+
save_ctxt: SaveContext::new(sess, analysis, SpanUtils {
78+
sess: sess,
79+
err_count: Cell::new(0)
80+
}),
7881
analysis: analysis,
7982
collected_paths: vec![],
8083
collecting: false,

src/librustc_trans/save/mod.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,50 @@ use std::env;
1515
use std::fs::{self, File};
1616
use std::path::{Path, PathBuf};
1717

18-
use syntax::{ast, attr, visit};
18+
use syntax::{attr, visit};
19+
use syntax::ast::{self, NodeId, DefId};
20+
use syntax::parse::token::keywords;
1921
use syntax::codemap::*;
2022

23+
use self::span_utils::SpanUtils;
24+
2125
mod span_utils;
2226
mod recorder;
2327

2428
mod dump_csv;
2529

26-
pub struct SaveContext<'l> {
30+
pub struct SaveContext<'l, 'tcx: 'l> {
2731
sess: &'l Session,
32+
analysis: &'l ty::CrateAnalysis<'tcx>,
33+
span_utils: SpanUtils<'l>,
2834
}
2935

3036
pub struct CrateData {
3137
pub name: String,
3238
pub number: u32,
3339
}
3440

35-
impl<'l> SaveContext<'l> {
36-
pub fn new<'ll>(sess: &'ll Session) -> SaveContext<'ll> {
41+
pub enum Data {
42+
FunctionData(FunctionData),
43+
}
44+
45+
pub struct FunctionData {
46+
pub id: NodeId,
47+
pub qualname: String,
48+
pub declaration: Option<DefId>,
49+
pub span: Span,
50+
pub scope: NodeId,
51+
}
52+
53+
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
54+
pub fn new(sess: &'l Session,
55+
analysis: &'l ty::CrateAnalysis<'tcx>,
56+
span_utils: SpanUtils<'l>)
57+
-> SaveContext<'l, 'tcx> {
3758
SaveContext {
38-
sess: sess
59+
sess: sess,
60+
analysis: analysis,
61+
span_utils: span_utils,
3962
}
4063
}
4164

@@ -49,6 +72,30 @@ impl<'l> SaveContext<'l> {
4972

5073
result
5174
}
75+
76+
pub fn get_item_data(&self, item: &ast::Item) -> Data {
77+
match item.node {
78+
ast::Item_::ItemFn(..) => {
79+
let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
80+
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn);
81+
82+
Data::FunctionData(FunctionData {
83+
id: item.id,
84+
qualname: qualname,
85+
declaration: None,
86+
span: sub_span.unwrap(),
87+
scope: self.analysis.ty_cx.map.get_parent(item.id),
88+
})
89+
}
90+
_ => {
91+
unimplemented!();
92+
}
93+
}
94+
}
95+
96+
pub fn get_data_for_id(&self, id: &NodeId) -> Data {
97+
unimplemented!();
98+
}
5299
}
53100

54101
#[allow(deprecated)]

0 commit comments

Comments
 (0)