提交 8ac0bce6 编写于 作者: N Nick Cameron

save-analysis: api-ify method calls

上级 9f26f14d
......@@ -886,18 +886,14 @@ fn process_struct_lit(&mut self,
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);
......
......@@ -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.
......@@ -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>,
......@@ -372,6 +384,21 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
}
}
}
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!();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册