pub static tag_unboxed_closures: uint = 0x95;
pub static tag_unboxed_closure: uint = 0x96;
pub static tag_unboxed_closure_type: uint = 0x97;
+
+pub static tag_struct_fields: uint = 0x98;
+pub static tag_struct_field: uint = 0x99;
+pub static tag_struct_field_id: uint = 0x9a;
use syntax::diagnostic::expect;
use syntax::parse::token;
+use std::collections::hashmap::HashMap;
+
pub struct StaticMethodInfo {
pub ident: ast::Ident,
pub def_id: ast::DefId,
decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
}
+pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashMap<ast::NodeId,
+ Vec<ast::Attribute>> {
+ let cdata = cstore.get_crate_data(def.krate);
+ decoder::get_struct_field_attrs(&*cdata)
+}
+
pub fn get_type(tcx: &ty::ctxt,
def: ast::DefId)
-> ty::Polytype {
use std::hash;
use std::io::extensions::u64_from_be_bytes;
use std::io;
+use std::collections::hashmap::HashMap;
use std::rc::Rc;
use std::u64;
use serialize::ebml::reader;
f(get_attributes(item));
}
+pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap<ast::NodeId, Vec<ast::Attribute>> {
+ let data = ebml::Doc::new(cdata.data());
+ let fields = reader::get_doc(data, tag_struct_fields);
+ let mut map = HashMap::new();
+ reader::tagged_docs(fields, tag_struct_field, |field| {
+ let id = reader::doc_as_u32(reader::get_doc(field, tag_struct_field_id));
+ let attrs = get_attributes(field);
+ map.insert(id, attrs);
+ true
+ });
+ map
+}
+
fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
match family {
PublicField => ast::Public,
ebml_w.end_tag();
}
+fn encode_struct_field_attrs(ebml_w: &mut Encoder, krate: &Crate) {
+ struct StructFieldVisitor<'a, 'b> {
+ ebml_w: &'a mut Encoder<'b>,
+ }
+
+ impl<'a, 'b> Visitor<()> for StructFieldVisitor<'a, 'b> {
+ fn visit_struct_field(&mut self, field: &ast::StructField, _: ()) {
+ self.ebml_w.start_tag(tag_struct_field);
+ self.ebml_w.wr_tagged_u32(tag_struct_field_id, field.node.id);
+ encode_attributes(self.ebml_w, field.node.attrs.as_slice());
+ self.ebml_w.end_tag();
+ }
+ }
+
+ ebml_w.start_tag(tag_struct_fields);
+ visit::walk_crate(&mut StructFieldVisitor {
+ ebml_w: ebml_w
+ }, krate, ());
+ ebml_w.end_tag();
+}
+
+
+
struct ImplVisitor<'a,'b,'c> {
ecx: &'a EncodeContext<'b>,
ebml_w: &'a mut Encoder<'c>,
stats.index_bytes = ebml_w.writer.tell().unwrap() - i;
ebml_w.end_tag();
+ encode_struct_field_attrs(&mut ebml_w, krate);
+
stats.total_bytes = ebml_w.writer.tell().unwrap();
if tcx.sess.meta_stats() {
let len = results.as_slice().iter().map(|x| x.len()).sum();
let mut result: Vec<field_ty> = Vec::with_capacity(len);
- result.extend(results.as_slice().iter().flat_map(|rs| rs.iter().map(|&f| f)));
+ result.extend(results.as_slice().iter().flat_map(|rs| rs.iter().map(|f| f.clone())));
assert!(result.len() == len);
result
} else {
-> field_ty {
let r = lookup_struct_fields(cx, parent);
match r.iter().find(|f| f.id.node == field_id.node) {
- Some(t) => *t,
+ Some(t) => t.clone(),
None => cx.sess.bug("struct ID not found in parent's fields")
}
}
}
Some(&(index, ref mut used)) => {
*used = true;
- let class_field = *class_fields.get(index);
+ let class_field = class_fields.get(index).clone();
let field_type = ty::lookup_field_type(tcx,
class_id,
class_field.id,
_ => doctree::Plain,
},
generics: (&t.generics, subst::TypeSpace).clean(),
- fields: fields.iter().map(|f| f.clean()).collect(),
+ fields: fields.clean(),
fields_stripped: false,
}
}
impl Clean<Item> for ty::field_ty {
fn clean(&self) -> Item {
use syntax::parse::token::special_idents::unnamed_field;
+ use rustc::metadata::csearch;
+
+ let cx = get_cx();
+ let attrs;
+
+ let attr_map = csearch::get_struct_field_attrs(&cx.tcx().sess.cstore, self.id);
+
let name = if self.name == unnamed_field.name {
+ attrs = None;
None
} else {
+ attrs = Some(attr_map.find(&self.id.node).unwrap());
Some(self.name)
};
- let cx = get_cx();
+
let ty = ty::lookup_item_type(cx.tcx(), self.id);
+
Item {
name: name.clean(),
- attrs: inline::load_attrs(cx.tcx(), self.id),
+ attrs: attrs.unwrap_or(&Vec::new()).clean(),
source: Span::empty(),
visibility: Some(self.vis),
stability: get_stability(self.id),