Skip to content

Commit 616bfb6

Browse files
Extended save-analysis to support generated code, alterned some spans in format_args! and derive to maintain compatability
1 parent 9ae76b3 commit 616bfb6

File tree

8 files changed

+248
-198
lines changed

8 files changed

+248
-198
lines changed

Diff for: src/librustc_trans/save/dump_csv.rs

+86-127
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
135135
// always using the first ones. So, only error out if we don't have enough spans.
136136
// What could go wrong...?
137137
if spans.len() < path.segments.len() {
138+
if generated_code(path.span) {
139+
return vec!();
140+
}
138141
error!("Mis-calculated spans for path '{}'. Found {} spans, expected {}. Found spans:",
139142
path_to_string(path),
140143
spans.len(),
@@ -308,28 +311,26 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
308311
id: ast::NodeId,
309312
name: ast::Name,
310313
span: Span) {
311-
if generated_code(span) {
312-
return;
313-
}
314-
315314
debug!("process_method: {}:{}", id, name);
316315

317-
let method_data = self.save_ctxt.get_method_data(id, name, span);
316+
if let Some(method_data) = self.save_ctxt.get_method_data(id, name, span) {
318317

319-
if body.is_some() {
320-
self.fmt.method_str(span,
321-
Some(method_data.span),
322-
method_data.id,
323-
&method_data.qualname,
324-
method_data.declaration,
325-
method_data.scope);
326-
self.process_formals(&sig.decl.inputs, &method_data.qualname);
327-
} else {
328-
self.fmt.method_decl_str(span,
329-
Some(method_data.span),
330-
method_data.id,
331-
&method_data.qualname,
332-
method_data.scope);
318+
if body.is_some() {
319+
self.fmt.method_str(span,
320+
Some(method_data.span),
321+
method_data.id,
322+
&method_data.qualname,
323+
method_data.declaration,
324+
method_data.scope);
325+
self.process_formals(&sig.decl.inputs, &method_data.qualname);
326+
} else {
327+
self.fmt.method_decl_str(span,
328+
Some(method_data.span),
329+
method_data.id,
330+
&method_data.qualname,
331+
method_data.scope);
332+
}
333+
self.process_generic_params(&sig.generics, span, &method_data.qualname, id);
333334
}
334335

335336
// walk arg and return types
@@ -345,8 +346,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
345346
if let Some(body) = body {
346347
self.nest(id, |v| v.visit_block(body));
347348
}
348-
349-
self.process_generic_params(&sig.generics, span, &method_data.qualname, id);
350349
}
351350

352351
fn process_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
@@ -402,17 +401,17 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
402401
decl: &ast::FnDecl,
403402
ty_params: &ast::Generics,
404403
body: &ast::Block) {
405-
let fn_data = self.save_ctxt.get_item_data(item);
406-
down_cast_data!(fn_data, FunctionData, self, item.span);
407-
self.fmt.fn_str(item.span,
408-
Some(fn_data.span),
409-
fn_data.id,
410-
&fn_data.qualname,
411-
fn_data.scope);
412-
413-
414-
self.process_formals(&decl.inputs, &fn_data.qualname);
415-
self.process_generic_params(ty_params, item.span, &fn_data.qualname, item.id);
404+
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
405+
down_cast_data!(fn_data, FunctionData, self, item.span);
406+
self.fmt.fn_str(item.span,
407+
Some(fn_data.span),
408+
fn_data.id,
409+
&fn_data.qualname,
410+
fn_data.scope);
411+
412+
self.process_formals(&decl.inputs, &fn_data.qualname);
413+
self.process_generic_params(ty_params, item.span, &fn_data.qualname, item.id);
414+
}
416415

417416
for arg in &decl.inputs {
418417
self.visit_ty(&arg.ty);
@@ -426,17 +425,17 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
426425
}
427426

428427
fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) {
429-
let var_data = self.save_ctxt.get_item_data(item);
430-
down_cast_data!(var_data, VariableData, self, item.span);
431-
self.fmt.static_str(item.span,
432-
Some(var_data.span),
433-
var_data.id,
434-
&var_data.name,
435-
&var_data.qualname,
436-
&var_data.value,
437-
&var_data.type_value,
438-
var_data.scope);
439-
428+
if let Some(var_data) = self.save_ctxt.get_item_data(item) {
429+
down_cast_data!(var_data, VariableData, self, item.span);
430+
self.fmt.static_str(item.span,
431+
Some(var_data.span),
432+
var_data.id,
433+
&var_data.name,
434+
&var_data.qualname,
435+
&var_data.value,
436+
&var_data.type_value,
437+
var_data.scope);
438+
}
440439
self.visit_ty(&typ);
441440
self.visit_expr(expr);
442441
}
@@ -495,6 +494,10 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
495494
enum_definition: &ast::EnumDef,
496495
ty_params: &ast::Generics) {
497496
let enum_data = self.save_ctxt.get_item_data(item);
497+
let enum_data = match enum_data {
498+
None => return,
499+
Some(data) => data,
500+
};
498501
down_cast_data!(enum_data, EnumData, self, item.span);
499502
self.fmt.enum_str(item.span,
500503
Some(enum_data.span),
@@ -533,36 +536,36 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
533536
trait_ref: &Option<ast::TraitRef>,
534537
typ: &ast::Ty,
535538
impl_items: &[P<ast::ImplItem>]) {
536-
let impl_data = self.save_ctxt.get_item_data(item);
537-
down_cast_data!(impl_data, ImplData, self, item.span);
538-
match impl_data.self_ref {
539-
Some(ref self_ref) => {
539+
let mut has_self_ref = false;
540+
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
541+
down_cast_data!(impl_data, ImplData, self, item.span);
542+
if let Some(ref self_ref) = impl_data.self_ref {
543+
has_self_ref = true;
540544
self.fmt.ref_str(recorder::TypeRef,
541545
item.span,
542546
Some(self_ref.span),
543547
self_ref.ref_id,
544548
self_ref.scope);
545549
}
546-
None => {
547-
self.visit_ty(&typ);
550+
if let Some(ref trait_ref_data) = impl_data.trait_ref {
551+
self.fmt.ref_str(recorder::TypeRef,
552+
item.span,
553+
Some(trait_ref_data.span),
554+
trait_ref_data.ref_id,
555+
trait_ref_data.scope);
556+
visit::walk_path(self, &trait_ref.as_ref().unwrap().path);
548557
}
558+
559+
self.fmt.impl_str(item.span,
560+
Some(impl_data.span),
561+
impl_data.id,
562+
impl_data.self_ref.map(|data| data.ref_id),
563+
impl_data.trait_ref.map(|data| data.ref_id),
564+
impl_data.scope);
549565
}
550-
if let Some(ref trait_ref_data) = impl_data.trait_ref {
551-
self.fmt.ref_str(recorder::TypeRef,
552-
item.span,
553-
Some(trait_ref_data.span),
554-
trait_ref_data.ref_id,
555-
trait_ref_data.scope);
556-
visit::walk_path(self, &trait_ref.as_ref().unwrap().path);
566+
if !has_self_ref {
567+
self.visit_ty(&typ);
557568
}
558-
559-
self.fmt.impl_str(item.span,
560-
Some(impl_data.span),
561-
impl_data.id,
562-
impl_data.self_ref.map(|data| data.ref_id),
563-
impl_data.trait_ref.map(|data| data.ref_id),
564-
impl_data.scope);
565-
566569
self.process_generic_params(type_parameters, item.span, "", item.id);
567570
for impl_item in impl_items {
568571
self.visit_impl_item(impl_item);
@@ -619,22 +622,23 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
619622

620623
// `item` is the module in question, represented as an item.
621624
fn process_mod(&mut self, item: &ast::Item) {
622-
let mod_data = self.save_ctxt.get_item_data(item);
623-
down_cast_data!(mod_data, ModData, self, item.span);
624-
self.fmt.mod_str(item.span,
625-
Some(mod_data.span),
626-
mod_data.id,
627-
&mod_data.qualname,
628-
mod_data.scope,
629-
&mod_data.filename);
625+
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
626+
down_cast_data!(mod_data, ModData, self, item.span);
627+
self.fmt.mod_str(item.span,
628+
Some(mod_data.span),
629+
mod_data.id,
630+
&mod_data.qualname,
631+
mod_data.scope,
632+
&mod_data.filename);
633+
}
630634
}
631635

632636
fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<recorder::Row>) {
633-
if generated_code(path.span) {
637+
let path_data = self.save_ctxt.get_path_data(id, path);
638+
if generated_code(path.span) && path_data.is_none() {
634639
return;
635640
}
636641

637-
let path_data = self.save_ctxt.get_path_data(id, path);
638642
let path_data = match path_data {
639643
Some(pd) => pd,
640644
None => {
@@ -705,10 +709,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
705709
fields: &Vec<ast::Field>,
706710
variant: ty::VariantDef,
707711
base: &Option<P<ast::Expr>>) {
708-
if generated_code(path.span) {
709-
return
710-
}
711-
712712
self.write_sub_paths_truncated(path, false);
713713

714714
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
@@ -721,16 +721,15 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
721721
let scope = self.save_ctxt.enclosing_scope(ex.id);
722722

723723
for field in fields {
724-
if generated_code(field.ident.span) {
725-
continue;
726-
}
724+
if let Some(field_data) = self.save_ctxt
725+
.get_field_ref_data(field, variant, scope) {
727726

728-
let field_data = self.save_ctxt.get_field_ref_data(field, variant, scope);
729-
self.fmt.ref_str(recorder::VarRef,
730-
field.ident.span,
731-
Some(field_data.span),
732-
field_data.ref_id,
733-
field_data.scope);
727+
self.fmt.ref_str(recorder::VarRef,
728+
field.ident.span,
729+
Some(field_data.span),
730+
field_data.ref_id,
731+
field_data.scope);
732+
}
734733

735734
self.visit_expr(&field.expr)
736735
}
@@ -754,10 +753,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
754753
}
755754

756755
fn process_pat(&mut self, p: &ast::Pat) {
757-
if generated_code(p.span) {
758-
return;
759-
}
760-
761756
match p.node {
762757
ast::PatStruct(ref path, ref fields, _) => {
763758
visit::walk_path(self, path);
@@ -766,10 +761,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
766761
let variant = adt.variant_of_def(def);
767762

768763
for &Spanned { node: ref field, span } in fields {
769-
if generated_code(span) {
770-
continue;
771-
}
772-
773764
let sub_span = self.span.span_for_first_ident(span);
774765
if let Some(f) = variant.find_field_named(field.ident.name) {
775766
self.fmt.ref_str(recorder::VarRef, span, sub_span, f.did, self.cur_scope);
@@ -813,10 +804,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
813804

814805
impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
815806
fn visit_item(&mut self, item: &ast::Item) {
816-
if generated_code(item.span) {
817-
return
818-
}
819-
820807
match item.node {
821808
ast::ItemUse(ref use_item) => {
822809
match use_item.node {
@@ -1011,10 +998,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
1011998
}
1012999

10131000
fn visit_ty(&mut self, t: &ast::Ty) {
1014-
if generated_code(t.span) {
1015-
return
1016-
}
1017-
10181001
match t.node {
10191002
ast::TyPath(_, ref path) => {
10201003
match self.lookup_type_ref(t.id) {
@@ -1034,10 +1017,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
10341017
}
10351018

10361019
fn visit_expr(&mut self, ex: &ast::Expr) {
1037-
if generated_code(ex.span) {
1038-
return
1039-
}
1040-
10411020
match ex.node {
10421021
ast::ExprCall(ref _f, ref _args) => {
10431022
// Don't need to do anything for function calls,
@@ -1056,10 +1035,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
10561035
}
10571036
ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args),
10581037
ast::ExprField(ref sub_ex, _) => {
1059-
if generated_code(sub_ex.span) {
1060-
return
1061-
}
1062-
10631038
self.visit_expr(&sub_ex);
10641039

10651040
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
@@ -1072,10 +1047,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
10721047
}
10731048
}
10741049
ast::ExprTupField(ref sub_ex, idx) => {
1075-
if generated_code(sub_ex.span) {
1076-
return
1077-
}
1078-
10791050
self.visit_expr(&**sub_ex);
10801051

10811052
let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex);
@@ -1096,10 +1067,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
10961067
}
10971068
}
10981069
ast::ExprClosure(_, ref decl, ref body) => {
1099-
if generated_code(body.span) {
1100-
return
1101-
}
1102-
11031070
let mut id = String::from("$");
11041071
id.push_str(&ex.id.to_string());
11051072
self.process_formals(&decl.inputs, &id);
@@ -1196,18 +1163,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11961163
}
11971164

11981165
fn visit_stmt(&mut self, s: &ast::Stmt) {
1199-
if generated_code(s.span) {
1200-
return
1201-
}
1202-
12031166
visit::walk_stmt(self, s)
12041167
}
12051168

12061169
fn visit_local(&mut self, l: &ast::Local) {
1207-
if generated_code(l.span) {
1208-
return
1209-
}
1210-
12111170
let value = self.span.snippet(l.span);
12121171
self.process_var_decl(&l.pat, value);
12131172

0 commit comments

Comments
 (0)