mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
move out function data
This commit is contained in:
parent
b248ee8746
commit
cea73bfb15
@ -55,7 +55,7 @@ use util::ppaux;
|
||||
|
||||
|
||||
pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
|
||||
save_ctxt: SaveContext<'l>,
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
sess: &'l Session,
|
||||
analysis: &'l ty::CrateAnalysis<'tcx>,
|
||||
|
||||
@ -74,7 +74,10 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
||||
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
|
||||
DumpCsvVisitor {
|
||||
sess: sess,
|
||||
save_ctxt: SaveContext { sess: sess },
|
||||
save_ctxt: SaveContext::new(sess, analysis, SpanUtils {
|
||||
sess: sess,
|
||||
err_count: Cell::new(0)
|
||||
}),
|
||||
analysis: analysis,
|
||||
collected_paths: vec![],
|
||||
collecting: false,
|
||||
|
@ -15,16 +15,22 @@ use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use syntax::{ast, attr, visit};
|
||||
use syntax::{attr, visit};
|
||||
use syntax::ast::{self, NodeId, DefId};
|
||||
use syntax::parse::token::keywords;
|
||||
use syntax::codemap::*;
|
||||
|
||||
use self::span_utils::SpanUtils;
|
||||
|
||||
mod span_utils;
|
||||
mod recorder;
|
||||
|
||||
mod dump_csv;
|
||||
|
||||
pub struct SaveContext<'l> {
|
||||
pub struct SaveContext<'l, 'tcx: 'l> {
|
||||
sess: &'l Session,
|
||||
analysis: &'l ty::CrateAnalysis<'tcx>,
|
||||
span_utils: SpanUtils<'l>,
|
||||
}
|
||||
|
||||
pub struct CrateData {
|
||||
@ -32,10 +38,27 @@ pub struct CrateData {
|
||||
pub number: u32,
|
||||
}
|
||||
|
||||
impl<'l> SaveContext<'l> {
|
||||
pub fn new<'ll>(sess: &'ll Session) -> SaveContext<'ll> {
|
||||
pub enum Data {
|
||||
FunctionData(FunctionData),
|
||||
}
|
||||
|
||||
pub struct FunctionData {
|
||||
pub id: NodeId,
|
||||
pub qualname: String,
|
||||
pub declaration: Option<DefId>,
|
||||
pub span: Span,
|
||||
pub scope: NodeId,
|
||||
}
|
||||
|
||||
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
pub fn new(sess: &'l Session,
|
||||
analysis: &'l ty::CrateAnalysis<'tcx>,
|
||||
span_utils: SpanUtils<'l>)
|
||||
-> SaveContext<'l, 'tcx> {
|
||||
SaveContext {
|
||||
sess: sess
|
||||
sess: sess,
|
||||
analysis: analysis,
|
||||
span_utils: span_utils,
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +72,30 @@ impl<'l> SaveContext<'l> {
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_item_data(&self, item: &ast::Item) -> Data {
|
||||
match item.node {
|
||||
ast::Item_::ItemFn(..) => {
|
||||
let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn);
|
||||
|
||||
Data::FunctionData(FunctionData {
|
||||
id: item.id,
|
||||
qualname: qualname,
|
||||
declaration: None,
|
||||
span: sub_span.unwrap(),
|
||||
scope: self.analysis.ty_cx.map.get_parent(item.id),
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_data_for_id(&self, id: &NodeId) -> Data {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
|
Loading…
Reference in New Issue
Block a user