Skip to content

Commit

Permalink
save-analysis: api-ify method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Jul 9, 2015
1 parent 9f26f14 commit 8ac0bce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -886,18 +886,14 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
fn process_method_call(&mut self,
ex: &ast::Expr,
args: &Vec<P<ast::Expr>>) {
let method_call = ty::MethodCall::expr(ex.id);
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
ty::ImplContainer(_) => (Some(method_id), None),
ty::TraitContainer(_) => (None, Some(method_id))
};
let sub_span = self.span.sub_span_for_meth_name(ex.span);
self.fmt.meth_call_str(ex.span,
sub_span,
def_id,
decl_id,
self.cur_scope);
if let Some(call_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(call_data, MethodCallData, self, ex.span);
self.fmt.meth_call_str(ex.span,
Some(call_data.span),
call_data.ref_id,
call_data.decl_id,
call_data.scope);
}

// walk receiver and args
visit::walk_exprs(self, &args);
Expand Down
27 changes: 27 additions & 0 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -61,6 +61,8 @@ pub enum Data {
VariableRefData(VariableRefData),
/// Data for a reference to a type or trait.
TypeRefData(TypeRefData),
/// Data about a method call.
MethodCallData(MethodCallData),
}

/// Data for all kinds of functions and methods.
Expand Down Expand Up @@ -137,6 +139,16 @@ pub struct TypeRefData {
pub ref_id: DefId,
}

/// Data about a method call.
#[derive(Debug)]
pub struct MethodCallData {
pub span: Span,
pub scope: NodeId,
pub ref_id: Option<DefId>,
pub decl_id: Option<DefId>,
}



impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
Expand Down Expand Up @@ -372,6 +384,21 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}
}
ast::ExprMethodCall(..) => {
let method_call = ty::MethodCall::expr(expr.id);
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
ty::ImplContainer(_) => (Some(method_id), None),
ty::TraitContainer(_) => (None, Some(method_id))
};
let sub_span = self.span_utils.sub_span_for_meth_name(expr.span);
Some(Data::MethodCallData(MethodCallData {
span: sub_span.unwrap(),
scope: self.tcx.map.get_enclosing_scope(expr.id).unwrap_or(0),
ref_id: def_id,
decl_id: decl_id,
}))
}
_ => {
// FIXME
unimplemented!();
Expand Down

0 comments on commit 8ac0bce

Please sign in to comment.