Rebasing and bug fixing

This commit is contained in:
Nick Cameron 2015-06-15 10:06:01 +12:00
parent 92d6676412
commit 718268398e
2 changed files with 45 additions and 39 deletions

View File

@ -873,30 +873,31 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
self.write_sub_paths_truncated(path, false); self.write_sub_paths_truncated(path, false);
let struct_lit_data = self.save_ctxt.get_expr_data(ex); if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span); down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
self.fmt.ref_str(recorder::TypeRef, self.fmt.ref_str(recorder::TypeRef,
ex.span, ex.span,
Some(struct_lit_data.span), Some(struct_lit_data.span),
struct_lit_data.ref_id, struct_lit_data.ref_id,
struct_lit_data.scope); struct_lit_data.scope);
let struct_def = struct_lit_data.ref_id; let struct_def = struct_lit_data.ref_id;
for field in fields { for field in fields {
if generated_code(field.ident.span) { if generated_code(field.ident.span) {
continue; continue;
}
let field_data = self.save_ctxt.get_field_ref_data(field,
struct_def,
self.cur_scope);
self.fmt.ref_str(recorder::VarRef,
field.ident.span,
Some(field_data.span),
field_data.ref_id,
field_data.scope);
self.visit_expr(&field.expr)
} }
let field_data = self.save_ctxt.get_field_ref_data(field,
struct_def,
self.cur_scope);
self.fmt.ref_str(recorder::VarRef,
field.ident.span,
Some(field_data.span),
field_data.ref_id,
field_data.scope);
self.visit_expr(&field.expr)
} }
visit::walk_expr_opt(self, base) visit::walk_expr_opt(self, base)
@ -1256,13 +1257,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
self.visit_expr(&sub_ex); self.visit_expr(&sub_ex);
let field_data = self.save_ctxt.get_expr_data(ex); if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(field_data, VariableRefData, self, ex.span); down_cast_data!(field_data, VariableRefData, self, ex.span);
self.fmt.ref_str(recorder::VarRef, self.fmt.ref_str(recorder::VarRef,
ex.span, ex.span,
Some(field_data.span), Some(field_data.span),
field_data.ref_id, field_data.ref_id,
field_data.scope); field_data.scope);
}
}, },
ast::ExprTupField(ref sub_ex, idx) => { ast::ExprTupField(ref sub_ex, idx) => {
if generated_code(sub_ex.span) { if generated_code(sub_ex.span) {

View File

@ -329,7 +329,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}) })
} }
pub fn get_expr_data(&self, expr: &ast::Expr) -> Data { pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
match expr.node { match expr.node {
ast::ExprField(ref sub_ex, ident) => { ast::ExprField(ref sub_ex, ident) => {
let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &sub_ex).sty; let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &sub_ex).sty;
@ -339,12 +339,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
for f in &fields { for f in &fields {
if f.name == ident.node.name { if f.name == ident.node.name {
let sub_span = self.span_utils.span_for_last_ident(expr.span); let sub_span = self.span_utils.span_for_last_ident(expr.span);
return Data::VariableRefData(VariableRefData { return Some(Data::VariableRefData(VariableRefData {
name: get_ident(ident.node).to_string(), name: get_ident(ident.node).to_string(),
span: sub_span.unwrap(), span: sub_span.unwrap(),
scope: self.analysis.ty_cx.map.get_parent(expr.id), scope: self.analysis.ty_cx.map.get_parent(expr.id),
ref_id: f.id, ref_id: f.id,
}); }));
} }
} }
@ -353,24 +353,28 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
&get_ident(ident.node), &get_ident(ident.node),
ty)) ty))
} }
_ => self.sess.span_bug(expr.span, _ => {
&format!("Expected struct type, found {:?}", ty)), debug!("Expected struct type, found {:?}", ty);
None
}
} }
} }
ast::ExprStruct(ref path, _, _) => { ast::ExprStruct(ref path, _, _) => {
let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, expr).sty; let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, expr).sty;
match *ty { match *ty {
ty::ty_struct(def_id, _) => { ty::TyStruct(def_id, _) => {
let sub_span = self.span_utils.span_for_last_ident(path.span); let sub_span = self.span_utils.span_for_last_ident(path.span);
Data::TypeRefData(TypeRefData { Some(Data::TypeRefData(TypeRefData {
span: sub_span.unwrap(), span: sub_span.unwrap(),
scope: self.analysis.ty_cx.map.get_parent(expr.id), scope: self.analysis.ty_cx.map.get_parent(expr.id),
ref_id: def_id, ref_id: def_id,
}) }))
} }
_ => { _ => {
self.sess.span_bug(expr.span, // FIXME ty could legitimately be a TyEnum, but then we will fail
&format!("expected ty_struct, found {:?}", ty)); // later if we try to look up the fields.
debug!("expected TyStruct, found {:?}", ty);
None
} }
} }
} }