diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-10 23:09:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 23:09:08 -0800 |
commit | df043bf3dcc11bfd5c22cee5d3c6ba04d41c5f00 (patch) | |
tree | 7fd7ba8d7882a5d68215602d3eba5425600b2efc /libbindgen/src/codegen | |
parent | c77e76c4326b3069963bf292c98eeb99f6364fa2 (diff) | |
parent | 12fd256b082f6e269700b043726f9b8494aba269 (diff) |
Auto merge of #383 - emilio:virtual-base, r=fitzgen
Tidy up and test virtual inheritance handling.
Done while investigating #380.
r? @fitzgen
Diffstat (limited to 'libbindgen/src/codegen')
-rw-r--r-- | libbindgen/src/codegen/mod.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index 24b862be..c6d5fd39 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -4,7 +4,7 @@ mod helpers; use aster; use ir::annotations::FieldAccessorKind; -use ir::comp::{CompInfo, CompKind, Field, Method, MethodKind}; +use ir::comp::{Base, CompInfo, CompKind, Field, Method, MethodKind}; use ir::context::{BindgenContext, ItemId}; use ir::derive::{CanDeriveCopy, CanDeriveDebug}; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; @@ -556,13 +556,13 @@ struct Vtable<'a> { #[allow(dead_code)] methods: &'a [Method], #[allow(dead_code)] - base_classes: &'a [ItemId], + base_classes: &'a [Base], } impl<'a> Vtable<'a> { fn new(item_id: ItemId, methods: &'a [Method], - base_classes: &'a [ItemId]) + base_classes: &'a [Base]) -> Self { Vtable { item_id: item_id, @@ -835,14 +835,18 @@ impl CodeGenerator for CompInfo { } for (i, base) in self.base_members().iter().enumerate() { - let base_ty = ctx.resolve_type(*base); + // 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. - // - // NB: Canonical type is here because it could be inheriting from a - // typedef, for example, and the lack of `unwrap()` is because we - // can inherit from a template parameter, yes. if base_ty.is_unsized(ctx) { continue; } @@ -854,7 +858,7 @@ impl CodeGenerator for CompInfo { } } - let inner = base.to_rust_ty(ctx); + let inner = base.ty.to_rust_ty(ctx); let field_name = if i == 0 { "_base".into() } else { |