save-analysis: tweak constructors

This commit is contained in:
Nick Cameron 2015-07-14 14:21:54 +12:00
parent e6e6368454
commit 41b056823c
3 changed files with 17 additions and 9 deletions

View file

@ -35,7 +35,6 @@ use session::Session;
use middle::def;
use middle::ty::{self, Ty};
use std::cell::Cell;
use std::fs::File;
use std::path::Path;
@ -76,14 +75,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
analysis: &'l ty::CrateAnalysis,
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
let span_utils = SpanUtils {
sess: &tcx.sess,
err_count: Cell::new(0)
};
let span_utils = SpanUtils::new(&tcx.sess);
DumpCsvVisitor {
sess: &tcx.sess,
tcx: tcx,
save_ctxt: SaveContext::new(tcx, span_utils.clone()),
save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()),
analysis: analysis,
span: span_utils.clone(),
fmt: FmtStrs::new(box Recorder {

View file

@ -163,9 +163,14 @@ pub struct MethodCallData {
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
span_utils: SpanUtils<'l>)
-> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext <'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
SaveContext::from_span_utils(tcx, span_utils)
}
pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>,
span_utils: SpanUtils<'l>)
-> SaveContext<'l, 'tcx> {
SaveContext {
tcx: tcx,
span_utils: span_utils,

View file

@ -28,6 +28,13 @@ pub struct SpanUtils<'a> {
}
impl<'a> SpanUtils<'a> {
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
SpanUtils {
sess: sess,
err_count: Cell::new(0)
}
}
// Standard string for extents/location.
pub fn extent_str(&self, span: Span) -> String {
let lo_loc = self.sess.codemap().lookup_char_pos(span.lo);