Skip to content

Commit

Permalink
Extract requires_storage into it's own function.
Browse files Browse the repository at this point in the history
  • Loading branch information
pepyakin committed Oct 2, 2017
1 parent d77d662 commit a095153
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
10 changes: 1 addition & 9 deletions src/codegen/impl_partialeq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ pub fn gen_partialeq_impl(
});
} else {
for base in comp_info.base_members().iter() {
if base.is_virtual() {
continue;
}

let base_ty = ctx.resolve_type(base.ty);
// NB: We won't include unsized types in our base chain because they
// would contribute to our size given the dummy field we insert for
// unsized types.
if base_ty.is_unsized(ctx, &base.ty) {
if !base.requires_storage(ctx) {
continue;
}

Expand Down
15 changes: 2 additions & 13 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,25 +1544,14 @@ impl CodeGenerator for CompInfo {
}

for base in self.base_members() {
// Virtual bases are already taken into account by the vtable
// pointer.
//
// FIXME(emilio): Is this always right?
if base.is_virtual() {
continue;
}

let base_ty = ctx.resolve_type(base.ty);
// NB: We won't include unsized types in our base chain because they
// would contribute to our size given the dummy field we insert for
// unsized types.
if base_ty.is_unsized(ctx, &base.ty) {
if !base.requires_storage(ctx) {
continue;
}

let inner = base.ty.to_rust_ty_or_opaque(ctx, &());
let field_name = ctx.rust_ident(&base.field_name);

let base_ty = ctx.resolve_type(base.ty);
struct_layout.saw_base(base_ty);

fields.push(quote! {
Expand Down
21 changes: 21 additions & 0 deletions src/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,27 @@ impl Base {
pub fn is_virtual(&self) -> bool {
self.kind == BaseKind::Virtual
}

/// Whether this base class should have it's own field for storage.
pub fn requires_storage(&self, ctx: &BindgenContext) -> bool {
// Virtual bases are already taken into account by the vtable
// pointer.
//
// FIXME(emilio): Is this always right?
if self.is_virtual() {
return false;
}

let base_ty = ctx.resolve_type(self.ty);
// NB: We won't include unsized types in our base chain because they
// would contribute to our size given the dummy field we insert for
// unsized types.
if base_ty.is_unsized(ctx, &self.ty) {
return false;
}

true
}
}

/// A compound type.
Expand Down

0 comments on commit a095153

Please sign in to comment.