about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-03 14:40:37 +0000
committerbors <bors@rust-lang.org>2015-06-03 14:40:37 +0000
commit9a2f68e1594718a8565139b44edfd905803134ce (patch)
tree1f025d27c78241ec5fc7b8716b44ba790a71a4f1 /src
parent5b56d73dc0e8b988f91c44fd9f9e40331451796b (diff)
parent1ef0ad8adc91ccea1cc14ac4f890dbc57f59b6ae (diff)
downloadrust-9a2f68e1594718a8565139b44edfd905803134ce.tar.gz
rust-9a2f68e1594718a8565139b44edfd905803134ce.zip
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 
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/save/dump_csv.rs153
-rw-r--r--src/librustc_trans/save/mod.rs26
2 files changed, 98 insertions, 81 deletions
diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs
index 5c630533ec3..0513653eb24 100644
--- a/src/librustc_trans/save/dump_csv.rs
+++ b/src/librustc_trans/save/dump_csv.rs
@@ -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);
-
-                    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,
@@ -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).
diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs
index 27297d8aa8d..c6dc1c9b707 100644
--- a/src/librustc_trans/save/mod.rs
+++ b/src/librustc_trans/save/mod.rs
@@ -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);
 }