decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item)
}
-pub fn get_enum_variants<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
- -> Vec<Rc<ty::VariantInfo<'tcx>>> {
- let cstore = &tcx.sess.cstore;
- let cdata = cstore.get_crate_data(def.krate);
- decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx)
-}
-
/// Returns information about the given implementation.
pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: ast::DefId)
-> Vec<ty::ImplOrTraitItemId> {
decoder::get_item_attrs(&*cdata, def_id.node)
}
-pub fn get_struct_fields(cstore: &cstore::CStore,
- def: ast::DefId)
- -> Vec<ty::FieldTy> {
+pub fn get_struct_field_names(cstore: &cstore::CStore, def: ast::DefId) -> Vec<ast::Name> {
let cdata = cstore.get_crate_data(def.krate);
- decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
+ decoder::get_struct_field_names(&cstore.intr, &*cdata, def.node)
}
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashMap<ast::NodeId,
}
}
-pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
- tcx: &ty::ctxt<'tcx>) -> Vec<Rc<ty::VariantInfo<'tcx>>> {
- let data = cdata.data();
- let items = reader::get_doc(rbml::Doc::new(data), tag_items);
- let item = find_item(id, items);
- let mut disr_val = 0;
- reader::tagged_docs(item, tag_items_data_item_variant).map(|p| {
- let did = translated_def_id(cdata, p);
- let item = find_item(did.node, items);
- let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
- item, tcx, cdata);
- let name = item_name(&*intr, item);
- let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
- ty::TyBareFn(_, ref f) =>
- (Some(ctor_ty), f.sig.0.inputs.clone(), None),
- _ => { // Nullary or struct enum variant.
- let mut arg_names = Vec::new();
- let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
- .iter()
- .map(|field_ty| {
- arg_names.push(field_ty.name);
- get_type(cdata, field_ty.id.node, tcx).ty
- })
- .collect();
- let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) };
-
- (None, arg_tys, arg_names)
- }
- };
- match variant_disr_val(item) {
- Some(val) => { disr_val = val; }
- _ => { /* empty */ }
- }
- let old_disr_val = disr_val;
- disr_val = disr_val.wrapping_add(1);
- Rc::new(ty::VariantInfo {
- args: arg_tys,
- arg_names: arg_names,
- ctor_ty: ctor_ty,
- name: name,
- // I'm not even sure if we encode visibility
- // for variants -- TEST -- tjc
- id: did,
- disr_val: old_disr_val,
- vis: ast::Inherited
- })
- }).collect()
-}
-
fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
fn get_mutability(ch: u8) -> ast::Mutability {
match ch as char {
}
}
-pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
- -> Vec<ty::FieldTy> {
+pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
+ -> Vec<ast::Name> {
let data = cdata.data();
let item = lookup_item(id, data);
- reader::tagged_docs(item, tag_item_field).filter_map(|an_item| {
- let f = item_family(an_item);
- if f == PublicField || f == InheritedField {
- let name = item_name(&*intr, an_item);
- let did = item_def_id(an_item, cdata);
- let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
- let origin_id = translated_def_id(cdata, tagdoc);
- Some(ty::FieldTy {
- name: name,
- id: did,
- vis: struct_field_family_to_visibility(f),
- origin: origin_id,
- })
- } else {
- None
- }
- }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|an_item| {
- let did = item_def_id(an_item, cdata);
- let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
- let f = item_family(an_item);
- let origin_id = translated_def_id(cdata, tagdoc);
- ty::FieldTy {
- name: special_idents::unnamed_field.name,
- id: did,
- vis: struct_field_family_to_visibility(f),
- origin: origin_id,
- }
+ reader::tagged_docs(item, tag_item_field).map(|an_item| {
+ item_name(intr, an_item)
+ }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|_| {
+ special_idents::unnamed_field.name
})).collect()
}
use rustc_data_structures::ivar;
use syntax::abi;
use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE};
-use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
-use syntax::ast::{StructField, UnnamedField, Visibility};
+use syntax::ast::{MutImmutable, MutMutable, Name, NodeId, Visibility};
use syntax::ast_util::{self, is_local, local_def};
use syntax::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt};
use syntax::codemap::Span;
pub glob_map: Option<GlobMap>,
}
-#[derive(Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Field<'tcx> {
- pub name: ast::Name,
- pub mt: TypeAndMut<'tcx>
-}
-
-// Enum information
-#[derive(Clone)]
-pub struct VariantInfo<'tcx> {
- pub args: Vec<Ty<'tcx>>,
- pub arg_names: Option<Vec<ast::Name>>,
- pub ctor_ty: Option<Ty<'tcx>>,
- pub name: ast::Name,
- pub id: ast::DefId,
- pub disr_val: Disr,
- pub vis: Visibility
-}
-
-impl<'tcx> VariantInfo<'tcx> {
-
- /// Creates a new VariantInfo from the corresponding ast representation.
- ///
- /// Does not do any caching of the value in the type context.
- pub fn from_ast_variant(cx: &ctxt<'tcx>,
- ast_variant: &ast::Variant,
- discriminant: Disr) -> VariantInfo<'tcx> {
- let ctor_ty = cx.node_id_to_type(ast_variant.node.id);
-
- match ast_variant.node.kind {
- ast::TupleVariantKind(ref args) => {
- let arg_tys = if !args.is_empty() {
- // the regions in the argument types come from the
- // enum def'n, and hence will all be early bound
- cx.no_late_bound_regions(&ctor_ty.fn_args()).unwrap()
- } else {
- Vec::new()
- };
-
- return VariantInfo {
- args: arg_tys,
- arg_names: None,
- ctor_ty: Some(ctor_ty),
- name: ast_variant.node.name.name,
- id: ast_util::local_def(ast_variant.node.id),
- disr_val: discriminant,
- vis: ast_variant.node.vis
- };
- },
- ast::StructVariantKind(ref struct_def) => {
- let fields: &[StructField] = &struct_def.fields;
-
- assert!(!fields.is_empty());
-
- let arg_tys = struct_def.fields.iter()
- .map(|field| cx.node_id_to_type(field.node.id)).collect();
- let arg_names = fields.iter().map(|field| {
- match field.node.kind {
- NamedField(ident, _) => ident.name,
- UnnamedField(..) => cx.sess.bug(
- "enum_variants: all fields in struct must have a name")
- }
- }).collect();
-
- return VariantInfo {
- args: arg_tys,
- arg_names: Some(arg_names),
- ctor_ty: None,
- name: ast_variant.node.name.name,
- id: ast_util::local_def(ast_variant.node.id),
- disr_val: discriminant,
- vis: ast_variant.node.vis
- };
- }
- }
- }
-}
-
#[derive(Copy, Clone)]
pub enum DtorKind {
NoDtor,
pub mutbl: ast::Mutability,
}
-#[derive(Clone, Copy, Debug)]
-pub struct FieldTy {
- pub name: Name,
- pub id: DefId,
- pub vis: ast::Visibility,
- pub origin: ast::DefId, // The DefId of the struct in which the field is declared.
-}
-
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
pub struct ItemVariances {
pub types: VecPerParamSpace<Variance>,
}
}
- pub fn field_idx_strict(&self, name: ast::Name, fields: &[Field<'tcx>])
- -> usize {
- let mut i = 0;
- for f in fields { if f.name == name { return i; } i += 1; }
- self.sess.bug(&format!(
- "no field named `{}` found in the list of fields `{:?}`",
- name,
- fields.iter()
- .map(|f| f.name.to_string())
- .collect::<Vec<String>>()));
- }
-
pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
use self::TypeError::*;
}
}
-impl<'tcx> HasTypeFlags for Field<'tcx> {
- fn has_type_flags(&self, flags: TypeFlags) -> bool {
- self.mt.ty.has_type_flags(flags)
- }
-}
-
impl<'tcx> HasTypeFlags for BareFnTy<'tcx> {
fn has_type_flags(&self, flags: TypeFlags) -> bool {
self.sig.has_type_flags(flags)
}
}
-impl<'tcx> fmt::Debug for Field<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "field({},{})", self.name, self.mt)
- }
-}
-
impl<'a, 'tcx> fmt::Debug for ParameterEnvironment<'a, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ParameterEnvironment(\
}
}
-impl<'tcx> TypeFoldable<'tcx> for ty::Field<'tcx> {
- fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Field<'tcx> {
- ty::Field {
- name: self.name,
- mt: self.mt.fold_with(folder),
- }
- }
-}
-
impl<'tcx> TypeFoldable<'tcx> for ty::Region {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region {
folder.fold_region(*self)
crate) building type and value for {}",
final_ident);
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
- let fields = csearch::get_struct_fields(&self.session.cstore, def_id).iter().map(|f| {
- f.name
- }).collect::<Vec<_>>();
+ let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
if fields.is_empty() {
child_name_bindings.define_value(def, DUMMY_SP, modifiers);