Skip to content

Commit

Permalink
move out function data
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 14, 2015
1 parent b248ee8 commit cea73bf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -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>,

Expand All @@ -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,
Expand Down
57 changes: 52 additions & 5 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -15,27 +15,50 @@ 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 {
pub name: String,
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,
}
}

Expand All @@ -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)]
Expand Down

0 comments on commit cea73bf

Please sign in to comment.