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);
let struct_lit_data = self.save_ctxt.get_expr_data(ex);
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
self.fmt.ref_str(recorder::TypeRef,
ex.span,
Some(struct_lit_data.span),
struct_lit_data.ref_id,
struct_lit_data.scope);
let struct_def = struct_lit_data.ref_id;
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
self.fmt.ref_str(recorder::TypeRef,
ex.span,
Some(struct_lit_data.span),
struct_lit_data.ref_id,
struct_lit_data.scope);
let struct_def = struct_lit_data.ref_id;
for field in fields {
if generated_code(field.ident.span) {
continue;
for field in fields {
if generated_code(field.ident.span) {
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)
@ -1256,13 +1257,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
self.visit_expr(&sub_ex);
let field_data = self.save_ctxt.get_expr_data(ex);
down_cast_data!(field_data, VariableRefData, self, ex.span);
self.fmt.ref_str(recorder::VarRef,
ex.span,
Some(field_data.span),
field_data.ref_id,
field_data.scope);
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(field_data, VariableRefData, self, ex.span);
self.fmt.ref_str(recorder::VarRef,
ex.span,
Some(field_data.span),
field_data.ref_id,
field_data.scope);
}
},
ast::ExprTupField(ref sub_ex, idx) => {
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 {
ast::ExprField(ref sub_ex, ident) => {
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 {
if f.name == ident.node.name {
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(),
span: sub_span.unwrap(),
scope: self.analysis.ty_cx.map.get_parent(expr.id),
ref_id: f.id,
});
}));
}
}
@ -353,24 +353,28 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
&get_ident(ident.node),
ty))
}
_ => self.sess.span_bug(expr.span,
&format!("Expected struct type, found {:?}", ty)),
_ => {
debug!("Expected struct type, found {:?}", ty);
None
}
}
}
ast::ExprStruct(ref path, _, _) => {
let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, expr).sty;
match *ty {
ty::ty_struct(def_id, _) => {
ty::TyStruct(def_id, _) => {
let sub_span = self.span_utils.span_for_last_ident(path.span);
Data::TypeRefData(TypeRefData {
Some(Data::TypeRefData(TypeRefData {
span: sub_span.unwrap(),
scope: self.analysis.ty_cx.map.get_parent(expr.id),
ref_id: def_id,
})
}))
}
_ => {
self.sess.span_bug(expr.span,
&format!("expected ty_struct, found {:?}", ty));
// FIXME ty could legitimately be a TyEnum, but then we will fail
// later if we try to look up the fields.
debug!("expected TyStruct, found {:?}", ty);
None
}
}
}