diff options
-rw-r--r-- | src/codegen/mod.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/derive_default.rs | 4 | ||||
-rw-r--r-- | src/ir/analysis/derive_hash.rs | 8 | ||||
-rw-r--r-- | src/ir/analysis/derive_partial_eq_or_partial_ord.rs | 8 | ||||
-rw-r--r-- | src/ir/analysis/has_destructor.rs | 2 | ||||
-rw-r--r-- | src/ir/analysis/has_float.rs | 4 | ||||
-rw-r--r-- | src/ir/analysis/has_type_param_in_array.rs | 2 | ||||
-rw-r--r-- | src/ir/comp.rs | 38 | ||||
-rw-r--r-- | src/ir/context.rs | 55 | ||||
-rw-r--r-- | src/ir/item.rs | 24 | ||||
-rw-r--r-- | src/ir/var.rs | 12 |
11 files changed, 93 insertions, 66 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index fef5d027..22abad10 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1112,7 +1112,7 @@ impl Bitfield { ctor_impl: quote::Tokens, unit_field_int_ty: "e::Tokens, ) -> quote::Tokens { - let bitfield_ty = ctx.resolve_type(self.ty().as_type_id_unchecked()); + let bitfield_ty = ctx.resolve_type(self.ty()); let bitfield_ty_layout = bitfield_ty.layout(ctx).expect( "Bitfield without layout? Gah!", ); diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs index 4c208b37..13ab29a4 100644 --- a/src/ir/analysis/derive_default.rs +++ b/src/ir/analysis/derive_default.rs @@ -305,7 +305,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> { info.fields().iter().any(|f| match *f { Field::DataMember(ref data) => { !self.ctx.whitelisted_items().contains( - &data.ty(), + &data.ty().into(), ) || self.is_not_default(data.ty()) } @@ -320,7 +320,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> { bfu.bitfields().iter().any(|b| { !self.ctx.whitelisted_items().contains( - &b.ty(), + &b.ty().into(), ) || self.is_not_default(b.ty()) }) diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs index 1cbd85fb..0d4392b3 100644 --- a/src/ir/analysis/derive_hash.rs +++ b/src/ir/analysis/derive_hash.rs @@ -279,9 +279,9 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { info.fields().iter().any(|f| match *f { Field::DataMember(ref data) => { !self.ctx.whitelisted_items().contains( - &data.ty(), + &data.ty().into(), ) || - self.cannot_derive_hash.contains(&data.ty()) + self.cannot_derive_hash.contains(&data.ty().into()) } Field::Bitfields(ref bfu) => { if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT { @@ -294,9 +294,9 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { bfu.bitfields().iter().any(|b| { !self.ctx.whitelisted_items().contains( - &b.ty(), + &b.ty().into(), ) || - self.cannot_derive_hash.contains(&b.ty()) + self.cannot_derive_hash.contains(&b.ty().into()) }) } }); diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs index 6750dc3b..f5cdc566 100644 --- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs +++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs @@ -295,10 +295,10 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { info.fields().iter().any(|f| match *f { Field::DataMember(ref data) => { !self.ctx.whitelisted_items().contains( - &data.ty(), + &data.ty().into(), ) || self.cannot_derive_partialeq_or_partialord.contains( - &data.ty(), + &data.ty().into(), ) } Field::Bitfields(ref bfu) => { @@ -312,10 +312,10 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { bfu.bitfields().iter().any(|b| { !self.ctx.whitelisted_items().contains( - &b.ty(), + &b.ty().into(), ) || self.cannot_derive_partialeq_or_partialord.contains( - &b.ty(), + &b.ty().into(), ) }) } diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index 28537b71..9966b7f2 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -126,7 +126,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { info.fields().iter().any(|field| { match *field { Field::DataMember(ref data) => - self.have_destructor.contains(&data.ty()), + self.have_destructor.contains(&data.ty().into()), Field::Bitfields(_) => false } }); diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs index 60c53b7d..8b86f48d 100644 --- a/src/ir/analysis/has_float.rs +++ b/src/ir/analysis/has_float.rs @@ -176,12 +176,12 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { .any(|f| { match *f { Field::DataMember(ref data) => { - self.has_float.contains(&data.ty()) + self.has_float.contains(&data.ty().into()) } Field::Bitfields(ref bfu) => { bfu.bitfields() .iter().any(|b| { - self.has_float.contains(&b.ty()) + self.has_float.contains(&b.ty().into()) }) }, } diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs index ce1ed77f..30e2f48b 100644 --- a/src/ir/analysis/has_type_param_in_array.rs +++ b/src/ir/analysis/has_type_param_in_array.rs @@ -191,7 +191,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } let fields_have = info.fields().iter().any(|f| match *f { Field::DataMember(ref data) => { - self.has_type_parameter_in_array.contains(&data.ty()) + self.has_type_parameter_in_array.contains(&data.ty().into()) } Field::Bitfields(..) => false, }); diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 1bc53d1d..7d3da4c5 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1,7 +1,7 @@ //! Compound types (unions and structs) in our intermediate representation. use super::annotations::Annotations; -use super::context::{BindgenContext, ItemId}; +use super::context::{BindgenContext, ItemId, TypeId}; use super::dot::DotAttributes; use super::item::{IsOpaque, Item}; use super::layout::Layout; @@ -110,7 +110,7 @@ pub trait FieldMethods { fn name(&self) -> Option<&str>; /// Get the type of this field. - fn ty(&self) -> ItemId; + fn ty(&self) -> TypeId; /// Get the comment for this field. fn comment(&self) -> Option<&str>; @@ -176,7 +176,7 @@ impl Field { layout, .. }) => Some(layout), Field::DataMember(ref data) => { - ctx.resolve_type(data.ty.as_type_id_unchecked()).layout(ctx) + ctx.resolve_type(data.ty).layout(ctx) } } } @@ -191,13 +191,13 @@ impl Trace for Field { { match *self { Field::DataMember(ref data) => { - tracer.visit_kind(data.ty, EdgeKind::Field); + tracer.visit_kind(data.ty.into(), EdgeKind::Field); } Field::Bitfields(BitfieldUnit { ref bitfields, .. }) => { for bf in bitfields { - tracer.visit_kind(bf.ty(), EdgeKind::Field); + tracer.visit_kind(bf.ty().into(), EdgeKind::Field); } } } @@ -343,7 +343,7 @@ impl FieldMethods for Bitfield { self.data.name() } - fn ty(&self) -> ItemId { + fn ty(&self) -> TypeId { self.data.ty() } @@ -380,7 +380,7 @@ impl RawField { /// Construct a new `RawField`. fn new( name: Option<String>, - ty: ItemId, + ty: TypeId, comment: Option<String>, annotations: Option<Annotations>, bitfield: Option<u32>, @@ -404,7 +404,7 @@ impl FieldMethods for RawField { self.0.name() } - fn ty(&self) -> ItemId { + fn ty(&self) -> TypeId { self.0.ty() } @@ -538,7 +538,7 @@ fn bitfields_to_allocation_units<E, I>( for bitfield in raw_bitfields { let bitfield_width = bitfield.bitfield().unwrap() as usize; - let bitfield_layout = ctx.resolve_type(bitfield.ty().as_type_id_unchecked()) + let bitfield_layout = ctx.resolve_type(bitfield.ty()) .layout(ctx) .expect("Bitfield without layout? Gah!"); let bitfield_size = bitfield_layout.size; @@ -705,7 +705,7 @@ impl Trace for CompFields { match *self { CompFields::BeforeComputingBitfieldUnits(ref fields) => { for f in fields { - tracer.visit_kind(f.ty(), EdgeKind::Field); + tracer.visit_kind(f.ty().into(), EdgeKind::Field); } } CompFields::AfterComputingBitfieldUnits(ref fields) => { @@ -724,7 +724,7 @@ pub struct FieldData { name: Option<String>, /// The inner type. - ty: ItemId, + ty: TypeId, /// The doc comment on the field if any. comment: Option<String>, @@ -747,7 +747,7 @@ impl FieldMethods for FieldData { self.name.as_ref().map(|n| &**n) } - fn ty(&self) -> ItemId { + fn ty(&self) -> TypeId { self.ty } @@ -1104,12 +1104,12 @@ impl CompInfo { let name = if name.is_empty() { None } else { Some(name) }; let field = RawField::new(name, - field_type, - comment, - annotations, - bit_width, - is_mutable, - offset); + field_type.as_type_id_unchecked(), + comment, + annotations, + bit_width, + is_mutable, + offset); ci.fields.append_raw_field(field); // No we look for things like attributes and stuff. @@ -1163,7 +1163,7 @@ impl CompInfo { let ty = cur.cur_type(); let offset = cur.offset_of_field().ok(); maybe_anonymous_struct_field = - Some((inner, ty, offset)); + Some((inner.as_type_id_unchecked(), ty, offset)); } } CXCursor_PackedAttr => { diff --git a/src/ir/context.rs b/src/ir/context.rs index 45d8ed13..2aed6872 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -9,8 +9,7 @@ use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveHash, CanDerivePartialOrd, CanDeriveOrd, CanDerivePartialEq, CanDeriveEq}; use super::int::IntKind; -use super::item::{HasTypeParamInArray, IsOpaque, Item, ItemAncestors, - ItemCanonicalPath, ItemSet}; +use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath, ItemSet}; use super::item_kind::ItemKind; use super::module::{Module, ModuleKind}; use super::template::{TemplateInstantiation, TemplateParameters}; @@ -81,20 +80,29 @@ impl ItemId { } } -impl CanDeriveDebug for ItemId { +impl<T> CanDeriveDebug for T +where + T: Copy + Into<ItemId> +{ fn can_derive_debug(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_debug && ctx.lookup_item_id_can_derive_debug(*self) } } -impl CanDeriveDefault for ItemId { +impl<T> CanDeriveDefault for T +where + T: Copy + Into<ItemId> +{ fn can_derive_default(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_default && ctx.lookup_item_id_can_derive_default(*self) } } -impl<'a> CanDeriveCopy<'a> for ItemId { +impl<'a, T> CanDeriveCopy<'a> for T +where + T: Copy + Into<ItemId> +{ fn can_derive_copy(&self, ctx: &BindgenContext) -> bool { ctx.lookup_item_id_can_derive_copy(*self) } @@ -106,33 +114,45 @@ impl CanDeriveHash for ItemId { } } -impl CanDerivePartialOrd for ItemId { +impl<T> CanDerivePartialOrd for T +where + T: Copy + Into<ItemId> +{ fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_partialord && ctx.lookup_item_id_can_derive_partialeq_or_partialord(*self) } } -impl CanDerivePartialEq for ItemId { +impl<T> CanDerivePartialEq for T +where + T: Copy + Into<ItemId> +{ fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_partialeq && ctx.lookup_item_id_can_derive_partialeq_or_partialord(*self) } } -impl CanDeriveEq for ItemId { +impl<T> CanDeriveEq for T +where + T: Copy + Into<ItemId> +{ fn can_derive_eq(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_eq && ctx.lookup_item_id_can_derive_partialeq_or_partialord(*self) && - !ctx.lookup_item_id_has_float(&self) + !ctx.lookup_item_id_has_float(*self) } } -impl CanDeriveOrd for ItemId { +impl<T> CanDeriveOrd for T +where + T: Copy + Into<ItemId> +{ fn can_derive_ord(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_ord && ctx.lookup_item_id_can_derive_partialeq_or_partialord(*self) && - !ctx.lookup_item_id_has_float(&self) + !ctx.lookup_item_id_has_float(*self) } } @@ -2224,7 +2244,7 @@ impl BindgenContext { } /// Look up whether the item with `id` can derive `Copy` or not. - pub fn lookup_item_id_can_derive_copy(&self, id: ItemId) -> bool { + pub fn lookup_item_id_can_derive_copy<Id: Into<ItemId>>(&self, id: Id) -> bool { assert!( self.in_codegen_phase(), "We only compute can_derive_debug when we enter codegen" @@ -2232,7 +2252,8 @@ impl BindgenContext { // Look up the computed value for whether the item with `id` can // derive `Copy` or not. - !id.has_type_param_in_array(self) && + let id = id.into(); + !self.lookup_item_id_has_type_param_in_array(id) && !self.cannot_derive_copy.as_ref().unwrap().contains(&id) } @@ -2245,7 +2266,7 @@ impl BindgenContext { } /// Look up whether the item with `id` has type parameter in array or not. - pub fn lookup_item_id_has_type_param_in_array(&self, id: &ItemId) -> bool { + pub fn lookup_item_id_has_type_param_in_array<Id: Into<ItemId>>(&self, id: Id) -> bool { assert!( self.in_codegen_phase(), "We only compute has array when we enter codegen" @@ -2253,7 +2274,7 @@ impl BindgenContext { // Look up the computed value for whether the item with `id` has // type parameter in array or not. - self.has_type_param_in_array.as_ref().unwrap().contains(id) + self.has_type_param_in_array.as_ref().unwrap().contains(&id.into()) } /// Compute whether the type has float. @@ -2266,13 +2287,13 @@ impl BindgenContext { } /// Look up whether the item with `id` has array or not. - pub fn lookup_item_id_has_float(&self, id: &ItemId) -> bool { + pub fn lookup_item_id_has_float<Id: Into<ItemId>>(&self, id: Id) -> bool { assert!(self.in_codegen_phase(), "We only compute has float when we enter codegen"); // Look up the computed value for whether the item with `id` has // float or not. - self.has_float.as_ref().unwrap().contains(id) + self.has_float.as_ref().unwrap().contains(&id.into()) } /// Check if `--no-partialeq` flag is enabled for this item. diff --git a/src/ir/item.rs b/src/ir/item.rs index 6baf5a06..8a386753 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -291,7 +291,7 @@ impl Trace for Item { tracer.visit(fun.signature()); } ItemKind::Var(ref var) => { - tracer.visit_kind(var.ty(), EdgeKind::VarType); + tracer.visit_kind(var.ty().into(), EdgeKind::VarType); } ItemKind::Module(_) => { // Module -> children edges are "weak", and we do not want to @@ -351,7 +351,7 @@ impl CanDeriveEq for Item { fn can_derive_eq(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_eq && ctx.lookup_item_id_can_derive_partialeq_or_partialord(self.id()) && - !ctx.lookup_item_id_has_float(&self.id()) + !ctx.lookup_item_id_has_float(self.id()) } } @@ -359,7 +359,7 @@ impl CanDeriveOrd for Item { fn can_derive_ord(&self, ctx: &BindgenContext) -> bool { ctx.options().derive_ord && ctx.lookup_item_id_can_derive_partialeq_or_partialord(self.id()) && - !ctx.lookup_item_id_has_float(&self.id()) + !ctx.lookup_item_id_has_float(self.id()) } } @@ -995,13 +995,16 @@ impl HasVtable for Item { } } -impl HasTypeParamInArray for ItemId { +impl<T> HasTypeParamInArray for T +where + T: Copy + Into<ItemId> +{ fn has_type_param_in_array(&self, ctx: &BindgenContext) -> bool { debug_assert!( ctx.in_codegen_phase(), "You're not supposed to call this yet" ); - ctx.lookup_item_id_has_type_param_in_array(self) + ctx.lookup_item_id_has_type_param_in_array(*self) } } @@ -1011,15 +1014,18 @@ impl HasTypeParamInArray for Item { ctx.in_codegen_phase(), "You're not supposed to call this yet" ); - ctx.lookup_item_id_has_type_param_in_array(&self.id()) + ctx.lookup_item_id_has_type_param_in_array(self.id()) } } -impl HasFloat for ItemId { +impl<T> HasFloat for T +where + T: Copy + Into<ItemId> +{ fn has_float(&self, ctx: &BindgenContext) -> bool { debug_assert!(ctx.in_codegen_phase(), "You're not supposed to call this yet"); - ctx.lookup_item_id_has_float(self) + ctx.lookup_item_id_has_float(*self) } } @@ -1027,7 +1033,7 @@ impl HasFloat for Item { fn has_float(&self, ctx: &BindgenContext) -> bool { debug_assert!(ctx.in_codegen_phase(), "You're not supposed to call this yet"); - ctx.lookup_item_id_has_float(&self.id()) + ctx.lookup_item_id_has_float(self.id()) } } diff --git a/src/ir/var.rs b/src/ir/var.rs index c0ecf3e4..d66504f6 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -1,6 +1,6 @@ //! Intermediate representation of variables. -use super::context::{BindgenContext, ItemId}; +use super::context::{BindgenContext, TypeId}; use super::dot::DotAttributes; use super::function::cursor_mangling; use super::int::IntKind; @@ -35,7 +35,7 @@ pub struct Var { /// The mangled name of the variable. mangled_name: Option<String>, /// The type of the variable. - ty: ItemId, + ty: TypeId, /// The value of the variable, that needs to be suitable for `ty`. val: Option<VarType>, /// Whether this variable is const. @@ -47,7 +47,7 @@ impl Var { pub fn new( name: String, mangled: Option<String>, - ty: ItemId, + ty: TypeId, val: Option<VarType>, is_const: bool, ) -> Var { @@ -72,7 +72,7 @@ impl Var { } /// Get this variable's type. - pub fn ty(&self) -> ItemId { + pub fn ty(&self) -> TypeId { self.ty } @@ -203,7 +203,7 @@ impl ClangSubItemParser for Var { let ty = Item::builtin_type(type_kind, true, ctx); Ok(ParseResult::New( - Var::new(name, None, ty, Some(val), true), + Var::new(name, None, ty.as_type_id_unchecked(), Some(val), true), Some(cursor), )) } @@ -278,7 +278,7 @@ impl ClangSubItemParser for Var { }; let mangling = cursor_mangling(ctx, &cursor); - let var = Var::new(name, mangling, ty, value, is_const); + let var = Var::new(name, mangling, ty.as_type_id_unchecked(), value, is_const); Ok(ParseResult::New(var, Some(cursor))) } |