Skip to content

Commit 8ac0bce

Browse files
committed
save-analysis: api-ify method calls
1 parent 9f26f14 commit 8ac0bce

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/librustc_trans/save/dump_csv.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -886,18 +886,14 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
886886
fn process_method_call(&mut self,
887887
ex: &ast::Expr,
888888
args: &Vec<P<ast::Expr>>) {
889-
let method_call = ty::MethodCall::expr(ex.id);
890-
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
891-
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
892-
ty::ImplContainer(_) => (Some(method_id), None),
893-
ty::TraitContainer(_) => (None, Some(method_id))
894-
};
895-
let sub_span = self.span.sub_span_for_meth_name(ex.span);
896-
self.fmt.meth_call_str(ex.span,
897-
sub_span,
898-
def_id,
899-
decl_id,
900-
self.cur_scope);
889+
if let Some(call_data) = self.save_ctxt.get_expr_data(ex) {
890+
down_cast_data!(call_data, MethodCallData, self, ex.span);
891+
self.fmt.meth_call_str(ex.span,
892+
Some(call_data.span),
893+
call_data.ref_id,
894+
call_data.decl_id,
895+
call_data.scope);
896+
}
901897

902898
// walk receiver and args
903899
visit::walk_exprs(self, &args);

src/librustc_trans/save/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub enum Data {
6161
VariableRefData(VariableRefData),
6262
/// Data for a reference to a type or trait.
6363
TypeRefData(TypeRefData),
64+
/// Data about a method call.
65+
MethodCallData(MethodCallData),
6466
}
6567

6668
/// Data for all kinds of functions and methods.
@@ -137,6 +139,16 @@ pub struct TypeRefData {
137139
pub ref_id: DefId,
138140
}
139141

142+
/// Data about a method call.
143+
#[derive(Debug)]
144+
pub struct MethodCallData {
145+
pub span: Span,
146+
pub scope: NodeId,
147+
pub ref_id: Option<DefId>,
148+
pub decl_id: Option<DefId>,
149+
}
150+
151+
140152

141153
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
142154
pub fn new(tcx: &'l ty::ctxt<'tcx>,
@@ -372,6 +384,21 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
372384
}
373385
}
374386
}
387+
ast::ExprMethodCall(..) => {
388+
let method_call = ty::MethodCall::expr(expr.id);
389+
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
390+
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
391+
ty::ImplContainer(_) => (Some(method_id), None),
392+
ty::TraitContainer(_) => (None, Some(method_id))
393+
};
394+
let sub_span = self.span_utils.sub_span_for_meth_name(expr.span);
395+
Some(Data::MethodCallData(MethodCallData {
396+
span: sub_span.unwrap(),
397+
scope: self.tcx.map.get_enclosing_scope(expr.id).unwrap_or(0),
398+
ref_id: def_id,
399+
decl_id: decl_id,
400+
}))
401+
}
375402
_ => {
376403
// FIXME
377404
unimplemented!();

0 commit comments

Comments
 (0)