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
This commit is contained in:
commit
9a2f68e159
2 changed files with 97 additions and 80 deletions
|
|
@ -169,7 +169,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
};
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
};
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
let (ref span, ref qualname) = sub_paths[len-2];
|
||||
self.fmt.sub_type_ref_str(path.span,
|
||||
*span,
|
||||
&qualname[..]);
|
||||
&qualname);
|
||||
|
||||
// write the other sub-paths
|
||||
if len <= 2 {
|
||||
|
|
@ -221,7 +221,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
for &(ref span, ref qualname) in sub_paths {
|
||||
self.fmt.sub_mod_ref_str(path.span,
|
||||
*span,
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
self.cur_scope);
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
id,
|
||||
qualname,
|
||||
&path_to_string(p),
|
||||
&typ[..]);
|
||||
&typ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -451,9 +451,9 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
Some(sub_span) => self.fmt.field_str(field.span,
|
||||
Some(sub_span),
|
||||
field.node.id,
|
||||
&name[..],
|
||||
&qualname[..],
|
||||
&typ[..],
|
||||
&name,
|
||||
&qualname,
|
||||
&typ,
|
||||
scope_id),
|
||||
None => self.sess.span_bug(field.span,
|
||||
&format!("Could not find sub-span for field {}",
|
||||
|
|
@ -485,7 +485,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
self.fmt.typedef_str(full_span,
|
||||
Some(*param_ss),
|
||||
param.id,
|
||||
&name[..],
|
||||
&name,
|
||||
"");
|
||||
}
|
||||
self.visit_generics(generics);
|
||||
|
|
@ -561,7 +561,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
sub_span,
|
||||
id,
|
||||
&get_ident((*ident).clone()),
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
&self.span.snippet(expr.span),
|
||||
&ty_to_string(&*typ),
|
||||
self.cur_scope);
|
||||
|
|
@ -587,82 +587,77 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
sub_span,
|
||||
item.id,
|
||||
ctor_id,
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
self.cur_scope,
|
||||
&val[..]);
|
||||
&val);
|
||||
|
||||
// fields
|
||||
for field in &def.fields {
|
||||
self.process_struct_field_def(field, &qualname[..], item.id);
|
||||
self.process_struct_field_def(field, &qualname, item.id);
|
||||
self.visit_ty(&*field.node.ty);
|
||||
}
|
||||
|
||||
self.process_generic_params(ty_params, item.span, &qualname[..], item.id);
|
||||
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
||||
}
|
||||
|
||||
fn process_enum(&mut self,
|
||||
item: &ast::Item,
|
||||
enum_definition: &ast::EnumDef,
|
||||
ty_params: &ast::Generics) {
|
||||
let enum_name = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
|
||||
let val = self.span.snippet(item.span);
|
||||
match self.span.sub_span_after_keyword(item.span, keywords::Enum) {
|
||||
Some(sub_span) => self.fmt.enum_str(item.span,
|
||||
Some(sub_span),
|
||||
item.id,
|
||||
&enum_name[..],
|
||||
self.cur_scope,
|
||||
&val[..]),
|
||||
None => self.sess.span_bug(item.span,
|
||||
&format!("Could not find subspan for enum {}",
|
||||
enum_name)),
|
||||
}
|
||||
for variant in &enum_definition.variants {
|
||||
let name = get_ident(variant.node.name);
|
||||
let name = &name;
|
||||
let mut qualname = enum_name.clone();
|
||||
qualname.push_str("::");
|
||||
qualname.push_str(name);
|
||||
let val = self.span.snippet(variant.span);
|
||||
match variant.node.kind {
|
||||
ast::TupleVariantKind(ref args) => {
|
||||
// first ident in span is the variant's name
|
||||
self.fmt.tuple_variant_str(variant.span,
|
||||
self.span.span_for_first_ident(variant.span),
|
||||
variant.node.id,
|
||||
name,
|
||||
&qualname[..],
|
||||
&enum_name[..],
|
||||
&val[..],
|
||||
item.id);
|
||||
for arg in args {
|
||||
self.visit_ty(&*arg.ty);
|
||||
let enum_data = self.save_ctxt.get_item_data(item);
|
||||
if let super::Data::EnumData(enum_data) = enum_data {
|
||||
self.fmt.enum_str(item.span,
|
||||
Some(enum_data.span),
|
||||
enum_data.id,
|
||||
&enum_data.qualname,
|
||||
self.cur_scope,
|
||||
&enum_data.value);
|
||||
for variant in &enum_definition.variants {
|
||||
let name = &get_ident(variant.node.name);
|
||||
let mut qualname = enum_data.qualname.clone();
|
||||
qualname.push_str("::");
|
||||
qualname.push_str(name);
|
||||
let val = self.span.snippet(variant.span);
|
||||
match variant.node.kind {
|
||||
ast::TupleVariantKind(ref args) => {
|
||||
// first ident in span is the variant's name
|
||||
self.fmt.tuple_variant_str(variant.span,
|
||||
self.span.span_for_first_ident(variant.span),
|
||||
variant.node.id,
|
||||
name,
|
||||
&qualname,
|
||||
&enum_data.qualname,
|
||||
&val,
|
||||
item.id);
|
||||
for arg in args {
|
||||
self.visit_ty(&*arg.ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::StructVariantKind(ref struct_def) => {
|
||||
let ctor_id = match struct_def.ctor_id {
|
||||
Some(node_id) => node_id,
|
||||
None => -1,
|
||||
};
|
||||
self.fmt.struct_variant_str(
|
||||
variant.span,
|
||||
self.span.span_for_first_ident(variant.span),
|
||||
variant.node.id,
|
||||
ctor_id,
|
||||
&qualname[..],
|
||||
&enum_name[..],
|
||||
&val[..],
|
||||
item.id);
|
||||
ast::StructVariantKind(ref struct_def) => {
|
||||
let ctor_id = match struct_def.ctor_id {
|
||||
Some(node_id) => node_id,
|
||||
None => -1,
|
||||
};
|
||||
self.fmt.struct_variant_str(variant.span,
|
||||
self.span.span_for_first_ident(variant.span),
|
||||
variant.node.id,
|
||||
ctor_id,
|
||||
&qualname,
|
||||
&enum_data.qualname,
|
||||
&val,
|
||||
item.id);
|
||||
|
||||
for field in &struct_def.fields {
|
||||
self.process_struct_field_def(field, &qualname, variant.node.id);
|
||||
self.visit_ty(&*field.node.ty);
|
||||
for field in &struct_def.fields {
|
||||
self.process_struct_field_def(field, &qualname, variant.node.id);
|
||||
self.visit_ty(&*field.node.ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.process_generic_params(ty_params, item.span, &enum_data.qualname, item.id);
|
||||
} else {
|
||||
self.sess.span_bug(item.span, "expected EnumData");
|
||||
}
|
||||
|
||||
self.process_generic_params(ty_params, item.span, &enum_name[..], item.id);
|
||||
}
|
||||
|
||||
fn process_impl(&mut self,
|
||||
|
|
@ -727,9 +722,9 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
self.fmt.trait_str(item.span,
|
||||
sub_span,
|
||||
item.id,
|
||||
&qualname[..],
|
||||
&qualname,
|
||||
self.cur_scope,
|
||||
&val[..]);
|
||||
&val);
|
||||
|
||||
// super-traits
|
||||
for super_bound in &**trait_refs {
|
||||
|
|
@ -761,7 +756,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
}
|
||||
|
||||
// walk generics and methods
|
||||
self.process_generic_params(generics, item.span, &qualname[..], item.id);
|
||||
self.process_generic_params(generics, item.span, &qualname, item.id);
|
||||
for method in methods {
|
||||
self.visit_trait_item(method)
|
||||
}
|
||||
|
|
@ -1001,7 +996,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
|||
self.cur_scope);
|
||||
|
||||
// walk receiver and args
|
||||
visit::walk_exprs(self, &args[..]);
|
||||
visit::walk_exprs(self, &args);
|
||||
}
|
||||
|
||||
fn process_pat(&mut self, p:&ast::Pat) {
|
||||
|
|
@ -1160,7 +1155,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
|
|||
item.id,
|
||||
cnum,
|
||||
name,
|
||||
&location[..],
|
||||
&location,
|
||||
self.cur_scope);
|
||||
}
|
||||
ast::ItemFn(ref decl, _, _, _, ref ty_params, ref body) =>
|
||||
|
|
@ -1195,8 +1190,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
|
|||
self.fmt.typedef_str(item.span,
|
||||
sub_span,
|
||||
item.id,
|
||||
&qualname[..],
|
||||
&value[..]);
|
||||
&qualname,
|
||||
&value);
|
||||
|
||||
self.visit_ty(&**ty);
|
||||
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> {
|
|||
|
||||
let mut id = String::from_str("$");
|
||||
id.push_str(&ex.id.to_string());
|
||||
self.process_formals(&decl.inputs, &id[..]);
|
||||
self.process_formals(&decl.inputs, &id);
|
||||
|
||||
// walk arg and return types
|
||||
for arg in &decl.inputs {
|
||||
|
|
@ -1408,7 +1403,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
|
|||
Some(p.span),
|
||||
id,
|
||||
&path_to_string(p),
|
||||
&value[..],
|
||||
&value,
|
||||
"")
|
||||
}
|
||||
def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
|
||||
|
|
@ -1466,8 +1461,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
|
|||
sub_span,
|
||||
id,
|
||||
&path_to_string(p),
|
||||
&value[..],
|
||||
&typ[..]);
|
||||
&value,
|
||||
&typ);
|
||||
}
|
||||
|
||||
// Just walk the initialiser and type (don't want to walk the pattern again).
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ pub enum Data {
|
|||
VariableData(VariableData),
|
||||
/// Data for modules.
|
||||
ModData(ModData),
|
||||
/// Data for Enums.
|
||||
EnumData(EnumData),
|
||||
|
||||
/// Data for the use of some variable (e.g., the use of a local variable, which
|
||||
/// will refere to that variables declaration).
|
||||
|
|
@ -88,6 +90,14 @@ pub struct ModData {
|
|||
pub filename: String,
|
||||
}
|
||||
|
||||
/// Data for enum declarations.
|
||||
pub struct EnumData {
|
||||
pub id: NodeId,
|
||||
pub value: String,
|
||||
pub qualname: String,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Data for the use of some item (e.g., the use of a local variable, which
|
||||
/// will refere to that variables declaration (by ref_id)).
|
||||
pub struct VariableRefData {
|
||||
|
|
@ -188,7 +198,19 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
scope: self.analysis.ty_cx.map.get_parent(item.id),
|
||||
filename: filename,
|
||||
})
|
||||
}
|
||||
},
|
||||
ast::ItemEnum(..) => {
|
||||
let enum_name = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
|
||||
let val = self.span_utils.snippet(item.span);
|
||||
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Enum);
|
||||
|
||||
Data::EnumData(EnumData {
|
||||
id: item.id,
|
||||
value: val,
|
||||
span: sub_span.unwrap(),
|
||||
qualname: enum_name,
|
||||
})
|
||||
},
|
||||
_ => {
|
||||
// FIXME
|
||||
unimplemented!();
|
||||
|
|
@ -345,7 +367,7 @@ pub fn process_crate(sess: &Session,
|
|||
|
||||
let mut visitor = dump_csv::DumpCsvVisitor::new(sess, analysis, output_file);
|
||||
|
||||
visitor.dump_crate_info(&cratename[..], krate);
|
||||
visitor.dump_crate_info(&cratename, krate);
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue