mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +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> {
|
pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
|
||||||
save_ctxt: SaveContext<'l>,
|
save_ctxt: SaveContext<'l, 'tcx>,
|
||||||
sess: &'l Session,
|
sess: &'l Session,
|
||||||
analysis: &'l ty::CrateAnalysis<'tcx>,
|
analysis: &'l ty::CrateAnalysis<'tcx>,
|
||||||
|
|
||||||
@ -74,7 +74,10 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||||||
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
|
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
|
||||||
DumpCsvVisitor {
|
DumpCsvVisitor {
|
||||||
sess: sess,
|
sess: sess,
|
||||||
save_ctxt: SaveContext { sess: sess },
|
save_ctxt: SaveContext::new(sess, analysis, SpanUtils {
|
||||||
|
sess: sess,
|
||||||
|
err_count: Cell::new(0)
|
||||||
|
}),
|
||||||
analysis: analysis,
|
analysis: analysis,
|
||||||
collected_paths: vec![],
|
collected_paths: vec![],
|
||||||
collecting: false,
|
collecting: false,
|
||||||
|
@ -15,16 +15,22 @@ use std::env;
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::path::{Path, PathBuf};
|
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 syntax::codemap::*;
|
||||||
|
|
||||||
|
use self::span_utils::SpanUtils;
|
||||||
|
|
||||||
mod span_utils;
|
mod span_utils;
|
||||||
mod recorder;
|
mod recorder;
|
||||||
|
|
||||||
mod dump_csv;
|
mod dump_csv;
|
||||||
|
|
||||||
pub struct SaveContext<'l> {
|
pub struct SaveContext<'l, 'tcx: 'l> {
|
||||||
sess: &'l Session,
|
sess: &'l Session,
|
||||||
|
analysis: &'l ty::CrateAnalysis<'tcx>,
|
||||||
|
span_utils: SpanUtils<'l>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CrateData {
|
pub struct CrateData {
|
||||||
@ -32,10 +38,27 @@ pub struct CrateData {
|
|||||||
pub number: u32,
|
pub number: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'l> SaveContext<'l> {
|
pub enum Data {
|
||||||
pub fn new<'ll>(sess: &'ll Session) -> SaveContext<'ll> {
|
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 {
|
SaveContext {
|
||||||
sess: sess
|
sess: sess,
|
||||||
|
analysis: analysis,
|
||||||
|
span_utils: span_utils,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +72,30 @@ impl<'l> SaveContext<'l> {
|
|||||||
|
|
||||||
result
|
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)]
|
#[allow(deprecated)]
|
||||||
|
Loading…
Reference in New Issue
Block a user