Skip to content

Commit

Permalink
save-analysis: emit a type for enum variants
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Nov 23, 2014
1 parent ccc4a7c commit e83785c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -589,21 +589,21 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
item: &ast::Item,
enum_definition: &ast::EnumDef,
ty_params: &ast::Generics) {
let qualname = self.analysis.ty_cx.map.path_to_string(item.id);
let enum_name = self.analysis.ty_cx.map.path_to_string(item.id);
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,
qualname.as_slice(),
enum_name.as_slice(),
self.cur_scope),
None => self.sess.span_bug(item.span,
format!("Could not find subspan for enum {}",
qualname).as_slice()),
enum_name).as_slice()),
}
for variant in enum_definition.variants.iter() {
let name = get_ident(variant.node.name);
let name = name.get();
let mut qualname = qualname.clone();
let mut qualname = enum_name.clone();
qualname.push_str("::");
qualname.push_str(name);
let val = self.span.snippet(variant.span);
Expand All @@ -615,6 +615,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
variant.node.id,
name,
qualname.as_slice(),
enum_name.as_slice(),
val.as_slice(),
item.id);
for arg in args.iter() {
Expand All @@ -632,18 +633,19 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
variant.node.id,
ctor_id,
qualname.as_slice(),
enum_name.as_slice(),
val.as_slice(),
item.id);

for field in struct_def.fields.iter() {
self.process_struct_field_def(field, qualname.as_slice(), variant.node.id);
self.process_struct_field_def(field, enum_name.as_slice(), variant.node.id);
self.visit_ty(&*field.node.ty);
}
}
}
}

self.process_generic_params(ty_params, item.span, qualname.as_slice(), item.id);
self.process_generic_params(ty_params, item.span, enum_name.as_slice(), item.id);
}

fn process_impl(&mut self,
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_trans/save/recorder.rs
Expand Up @@ -107,10 +107,14 @@ impl<'a> FmtStrs<'a> {
vec!("id","name","qualname","value","type","scopeid"),
true, true),
Enum => ("enum", vec!("id","qualname","scopeid"), true, true),
Variant => ("variant", vec!("id","name","qualname","value","scopeid"), true, true),
Variant => ("variant",
vec!("id","name","qualname","type","value","scopeid"),
true, true),
VariantStruct => ("variant_struct",
vec!("id","ctor_id","qualname","value","scopeid"), true, true),
Function => ("function", vec!("id","qualname","declid","declidcrate","scopeid"),
vec!("id","ctor_id","qualname","type","value","scopeid"),
true, true),
Function => ("function",
vec!("id","qualname","declid","declidcrate","scopeid"),
true, true),
MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true),
Struct => ("struct", vec!("id","ctor_id","qualname","scopeid"), true, true),
Expand All @@ -128,7 +132,7 @@ impl<'a> FmtStrs<'a> {
true, false),
MethodCall => ("method_call",
vec!("refid","refidcrate","declid","declidcrate","scopeid"),
true, true),
true, true),
Typedef => ("typedef", vec!("id","qualname","value"), true, true),
ExternalCrate => ("external_crate", vec!("name","crate","file_name"), false, false),
Crate => ("crate", vec!("name"), true, false),
Expand All @@ -140,7 +144,7 @@ impl<'a> FmtStrs<'a> {
true, true),
StructRef => ("struct_ref",
vec!("refid","refidcrate","qualname","scopeid"),
true, true),
true, true),
FnRef => ("fn_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true)
}
}
Expand Down Expand Up @@ -336,12 +340,13 @@ impl<'a> FmtStrs<'a> {
id: NodeId,
name: &str,
qualname: &str,
typ: &str,
val: &str,
scope_id: NodeId) {
self.check_and_record(Variant,
span,
sub_span,
svec!(id, name, qualname, val, scope_id));
svec!(id, name, qualname, typ, val, scope_id));
}

pub fn struct_variant_str(&mut self,
Expand All @@ -350,12 +355,13 @@ impl<'a> FmtStrs<'a> {
id: NodeId,
ctor_id: NodeId,
name: &str,
typ: &str,
val: &str,
scope_id: NodeId) {
self.check_and_record(VariantStruct,
span,
sub_span,
svec!(id, ctor_id, name, val, scope_id));
svec!(id, ctor_id, name, typ, val, scope_id));
}

pub fn fn_str(&mut self,
Expand Down

0 comments on commit e83785c

Please sign in to comment.