Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librustc/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ impl<'ast> Map<'ast> {
}
}

pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
match self.find(id) {
Some(NodeTraitItem(item)) => item,
_ => panic!("expected trait item, found {}", self.node_to_string(id))
}
}

pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
match self.find(id) {
Some(NodeItem(i)) => {
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_trans/save/dump_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
45 changes: 33 additions & 12 deletions src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -527,7 +532,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
ref_id: def.def_id(),
})
}
def::DefStruct(def_id) | def::DefTy(def_id, _) => {
def::DefStruct(def_id) |
def::DefTy(def_id, _) |
def::DefTrait(def_id) |
def::DefTyParam(_, _, def_id, _) => {
Data::TypeRefData(TypeRefData {
span: sub_span.unwrap(),
ref_id: def_id,
Expand All @@ -540,13 +548,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let ti = self.tcx.impl_or_trait_item(decl_id);
match provenence {
def::FromTrait(def_id) => {
Some(self.tcx.trait_items(def_id)
.iter()
.find(|mr| {
mr.name() == ti.name()
})
.unwrap()
.def_id())
self.tcx.trait_items(def_id)
.iter()
.find(|mr| {
mr.name() == ti.name() && self.trait_method_has_body(mr)
})
.map(|mr| mr.def_id())
}
def::FromImpl(def_id) => {
let impl_items = self.tcx.impl_items.borrow();
Expand Down Expand Up @@ -586,6 +593,20 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}

fn trait_method_has_body(&self, mr: &ty::ImplOrTraitItem) -> bool {
let def_id = mr.def_id();
if def_id.krate != ast::LOCAL_CRATE {
return false;
}

let trait_item = self.tcx.map.expect_trait_item(def_id.node);
if let ast::TraitItem_::MethodTraitItem(_, Some(_)) = trait_item.node {
true
} else {
false
}
}

pub fn get_field_ref_data(&self,
field_ref: &ast::Field,
struct_id: DefId,
Expand Down Expand Up @@ -753,6 +774,6 @@ fn escape(s: String) -> String {

// If the expression is a macro expansion or other generated code, run screaming
// and don't index.
fn generated_code(span: Span) -> bool {
pub fn generated_code(span: Span) -> bool {
span.expn_id != NO_EXPANSION || span == DUMMY_SP
}
7 changes: 7 additions & 0 deletions src/librustc_trans/save/span_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down