Skip to content

Move EnumData into the analysis API. #25966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 74 additions & 79 deletions src/librustc_trans/save/dump_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
};
self.fmt.sub_mod_ref_str(path.span,
*span,
&qualname[..],
&qualname,
self.cur_scope);
}
}
Expand All @@ -192,7 +192,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
};
self.fmt.sub_mod_ref_str(path.span,
*span,
&qualname[..],
&qualname,
self.cur_scope);
}
}
Expand All @@ -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 {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
id,
qualname,
&path_to_string(p),
&typ[..]);
&typ);
}
}
}
Expand Down Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

for field in &struct_def.fields {
self.process_struct_field_def(field, &qualname, variant.node.id);
self.visit_ty(&*field.node.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_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);
}
}
}
}
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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(..) => {
Expand Down Expand Up @@ -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).
Expand Down
26 changes: 24 additions & 2 deletions src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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!();
Expand Down Expand Up @@ -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);
}

Expand Down