Skip to content

Commit 9a2f68e

Browse files
committed
Auto merge of #25966 - pelmers:save-api, r=nrc
Move EnumData into the API, and change a few spots where we use &String[..] when it is equivalent to &String. r? @nrc
2 parents 5b56d73 + 1ef0ad8 commit 9a2f68e

File tree

2 files changed

+98
-81
lines changed

2 files changed

+98
-81
lines changed

src/librustc_trans/save/dump_csv.rs

+74-79
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
169169
};
170170
self.fmt.sub_mod_ref_str(path.span,
171171
*span,
172-
&qualname[..],
172+
&qualname,
173173
self.cur_scope);
174174
}
175175
}
@@ -192,7 +192,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
192192
};
193193
self.fmt.sub_mod_ref_str(path.span,
194194
*span,
195-
&qualname[..],
195+
&qualname,
196196
self.cur_scope);
197197
}
198198
}
@@ -211,7 +211,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
211211
let (ref span, ref qualname) = sub_paths[len-2];
212212
self.fmt.sub_type_ref_str(path.span,
213213
*span,
214-
&qualname[..]);
214+
&qualname);
215215

216216
// write the other sub-paths
217217
if len <= 2 {
@@ -221,7 +221,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
221221
for &(ref span, ref qualname) in sub_paths {
222222
self.fmt.sub_mod_ref_str(path.span,
223223
*span,
224-
&qualname[..],
224+
&qualname,
225225
self.cur_scope);
226226
}
227227
}
@@ -293,7 +293,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
293293
id,
294294
qualname,
295295
&path_to_string(p),
296-
&typ[..]);
296+
&typ);
297297
}
298298
}
299299
}
@@ -451,9 +451,9 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
451451
Some(sub_span) => self.fmt.field_str(field.span,
452452
Some(sub_span),
453453
field.node.id,
454-
&name[..],
455-
&qualname[..],
456-
&typ[..],
454+
&name,
455+
&qualname,
456+
&typ,
457457
scope_id),
458458
None => self.sess.span_bug(field.span,
459459
&format!("Could not find sub-span for field {}",
@@ -485,7 +485,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
485485
self.fmt.typedef_str(full_span,
486486
Some(*param_ss),
487487
param.id,
488-
&name[..],
488+
&name,
489489
"");
490490
}
491491
self.visit_generics(generics);
@@ -561,7 +561,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
561561
sub_span,
562562
id,
563563
&get_ident((*ident).clone()),
564-
&qualname[..],
564+
&qualname,
565565
&self.span.snippet(expr.span),
566566
&ty_to_string(&*typ),
567567
self.cur_scope);
@@ -587,82 +587,77 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
587587
sub_span,
588588
item.id,
589589
ctor_id,
590-
&qualname[..],
590+
&qualname,
591591
self.cur_scope,
592-
&val[..]);
592+
&val);
593593

594594
// fields
595595
for field in &def.fields {
596-
self.process_struct_field_def(field, &qualname[..], item.id);
596+
self.process_struct_field_def(field, &qualname, item.id);
597597
self.visit_ty(&*field.node.ty);
598598
}
599599

600-
self.process_generic_params(ty_params, item.span, &qualname[..], item.id);
600+
self.process_generic_params(ty_params, item.span, &qualname, item.id);
601601
}
602602

603603
fn process_enum(&mut self,
604604
item: &ast::Item,
605605
enum_definition: &ast::EnumDef,
606606
ty_params: &ast::Generics) {
607-
let enum_name = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
608-
let val = self.span.snippet(item.span);
609-
match self.span.sub_span_after_keyword(item.span, keywords::Enum) {
610-
Some(sub_span) => self.fmt.enum_str(item.span,
611-
Some(sub_span),
612-
item.id,
613-
&enum_name[..],
614-
self.cur_scope,
615-
&val[..]),
616-
None => self.sess.span_bug(item.span,
617-
&format!("Could not find subspan for enum {}",
618-
enum_name)),
619-
}
620-
for variant in &enum_definition.variants {
621-
let name = get_ident(variant.node.name);
622-
let name = &name;
623-
let mut qualname = enum_name.clone();
624-
qualname.push_str("::");
625-
qualname.push_str(name);
626-
let val = self.span.snippet(variant.span);
627-
match variant.node.kind {
628-
ast::TupleVariantKind(ref args) => {
629-
// first ident in span is the variant's name
630-
self.fmt.tuple_variant_str(variant.span,
631-
self.span.span_for_first_ident(variant.span),
632-
variant.node.id,
633-
name,
634-
&qualname[..],
635-
&enum_name[..],
636-
&val[..],
637-
item.id);
638-
for arg in args {
639-
self.visit_ty(&*arg.ty);
607+
let enum_data = self.save_ctxt.get_item_data(item);
608+
if let super::Data::EnumData(enum_data) = enum_data {
609+
self.fmt.enum_str(item.span,
610+
Some(enum_data.span),
611+
enum_data.id,
612+
&enum_data.qualname,
613+
self.cur_scope,
614+
&enum_data.value);
615+
for variant in &enum_definition.variants {
616+
let name = &get_ident(variant.node.name);
617+
let mut qualname = enum_data.qualname.clone();
618+
qualname.push_str("::");
619+
qualname.push_str(name);
620+
let val = self.span.snippet(variant.span);
621+
match variant.node.kind {
622+
ast::TupleVariantKind(ref args) => {
623+
// first ident in span is the variant's name
624+
self.fmt.tuple_variant_str(variant.span,
625+
self.span.span_for_first_ident(variant.span),
626+
variant.node.id,
627+
name,
628+
&qualname,
629+
&enum_data.qualname,
630+
&val,
631+
item.id);
632+
for arg in args {
633+
self.visit_ty(&*arg.ty);
634+
}
640635
}
641-
}
642-
ast::StructVariantKind(ref struct_def) => {
643-
let ctor_id = match struct_def.ctor_id {
644-
Some(node_id) => node_id,
645-
None => -1,
646-
};
647-
self.fmt.struct_variant_str(
648-
variant.span,
649-
self.span.span_for_first_ident(variant.span),
650-
variant.node.id,
651-
ctor_id,
652-
&qualname[..],
653-
&enum_name[..],
654-
&val[..],
655-
item.id);
656-
657-
for field in &struct_def.fields {
658-
self.process_struct_field_def(field, &qualname, variant.node.id);
659-
self.visit_ty(&*field.node.ty);
636+
ast::StructVariantKind(ref struct_def) => {
637+
let ctor_id = match struct_def.ctor_id {
638+
Some(node_id) => node_id,
639+
None => -1,
640+
};
641+
self.fmt.struct_variant_str(variant.span,
642+
self.span.span_for_first_ident(variant.span),
643+
variant.node.id,
644+
ctor_id,
645+
&qualname,
646+
&enum_data.qualname,
647+
&val,
648+
item.id);
649+
650+
for field in &struct_def.fields {
651+
self.process_struct_field_def(field, &qualname, variant.node.id);
652+
self.visit_ty(&*field.node.ty);
653+
}
660654
}
661655
}
662656
}
657+
self.process_generic_params(ty_params, item.span, &enum_data.qualname, item.id);
658+
} else {
659+
self.sess.span_bug(item.span, "expected EnumData");
663660
}
664-
665-
self.process_generic_params(ty_params, item.span, &enum_name[..], item.id);
666661
}
667662

668663
fn process_impl(&mut self,
@@ -727,9 +722,9 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
727722
self.fmt.trait_str(item.span,
728723
sub_span,
729724
item.id,
730-
&qualname[..],
725+
&qualname,
731726
self.cur_scope,
732-
&val[..]);
727+
&val);
733728

734729
// super-traits
735730
for super_bound in &**trait_refs {
@@ -761,7 +756,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
761756
}
762757

763758
// walk generics and methods
764-
self.process_generic_params(generics, item.span, &qualname[..], item.id);
759+
self.process_generic_params(generics, item.span, &qualname, item.id);
765760
for method in methods {
766761
self.visit_trait_item(method)
767762
}
@@ -1001,7 +996,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
1001996
self.cur_scope);
1002997

1003998
// walk receiver and args
1004-
visit::walk_exprs(self, &args[..]);
999+
visit::walk_exprs(self, &args);
10051000
}
10061001

10071002
fn process_pat(&mut self, p:&ast::Pat) {
@@ -1160,7 +1155,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11601155
item.id,
11611156
cnum,
11621157
name,
1163-
&location[..],
1158+
&location,
11641159
self.cur_scope);
11651160
}
11661161
ast::ItemFn(ref decl, _, _, _, ref ty_params, ref body) =>
@@ -1195,8 +1190,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11951190
self.fmt.typedef_str(item.span,
11961191
sub_span,
11971192
item.id,
1198-
&qualname[..],
1199-
&value[..]);
1193+
&qualname,
1194+
&value);
12001195

12011196
self.visit_ty(&**ty);
12021197
self.process_generic_params(ty_params, item.span, &qualname, item.id);
@@ -1348,7 +1343,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
13481343

13491344
let mut id = String::from_str("$");
13501345
id.push_str(&ex.id.to_string());
1351-
self.process_formals(&decl.inputs, &id[..]);
1346+
self.process_formals(&decl.inputs, &id);
13521347

13531348
// walk arg and return types
13541349
for arg in &decl.inputs {
@@ -1408,7 +1403,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14081403
Some(p.span),
14091404
id,
14101405
&path_to_string(p),
1411-
&value[..],
1406+
&value,
14121407
"")
14131408
}
14141409
def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
@@ -1466,8 +1461,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14661461
sub_span,
14671462
id,
14681463
&path_to_string(p),
1469-
&value[..],
1470-
&typ[..]);
1464+
&value,
1465+
&typ);
14711466
}
14721467

14731468
// Just walk the initialiser and type (don't want to walk the pattern again).

src/librustc_trans/save/mod.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub enum Data {
5151
VariableData(VariableData),
5252
/// Data for modules.
5353
ModData(ModData),
54+
/// Data for Enums.
55+
EnumData(EnumData),
5456

5557
/// Data for the use of some variable (e.g., the use of a local variable, which
5658
/// will refere to that variables declaration).
@@ -88,6 +90,14 @@ pub struct ModData {
8890
pub filename: String,
8991
}
9092

93+
/// Data for enum declarations.
94+
pub struct EnumData {
95+
pub id: NodeId,
96+
pub value: String,
97+
pub qualname: String,
98+
pub span: Span,
99+
}
100+
91101
/// Data for the use of some item (e.g., the use of a local variable, which
92102
/// will refere to that variables declaration (by ref_id)).
93103
pub struct VariableRefData {
@@ -188,7 +198,19 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
188198
scope: self.analysis.ty_cx.map.get_parent(item.id),
189199
filename: filename,
190200
})
191-
}
201+
},
202+
ast::ItemEnum(..) => {
203+
let enum_name = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
204+
let val = self.span_utils.snippet(item.span);
205+
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Enum);
206+
207+
Data::EnumData(EnumData {
208+
id: item.id,
209+
value: val,
210+
span: sub_span.unwrap(),
211+
qualname: enum_name,
212+
})
213+
},
192214
_ => {
193215
// FIXME
194216
unimplemented!();
@@ -345,7 +367,7 @@ pub fn process_crate(sess: &Session,
345367

346368
let mut visitor = dump_csv::DumpCsvVisitor::new(sess, analysis, output_file);
347369

348-
visitor.dump_crate_info(&cratename[..], krate);
370+
visitor.dump_crate_info(&cratename, krate);
349371
visit::walk_crate(&mut visitor, krate);
350372
}
351373

0 commit comments

Comments
 (0)