summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-01-06 10:38:03 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-01-06 10:38:03 +0100
commit9798d92212a590fff0d6f5a55d582e1b45781172 (patch)
tree39983ad5ee939905ab4d615101fb1f8716a047f9
parent6720a9930a28d5daf8303d5cf6a957f86765b988 (diff)
codegen: Properly handle virtual bases.
-rw-r--r--libbindgen/src/codegen/mod.rs12
-rw-r--r--libbindgen/src/ir/comp.rs9
2 files changed, 16 insertions, 5 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index c4dc9644..c6d5fd39 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -835,14 +835,18 @@ impl CodeGenerator for CompInfo {
}
for (i, base) in self.base_members().iter().enumerate() {
+ // 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;
}
diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs
index 2740fe8f..70dfd4a6 100644
--- a/libbindgen/src/ir/comp.rs
+++ b/libbindgen/src/ir/comp.rs
@@ -176,7 +176,7 @@ impl<'a> CanDeriveCopy<'a> for Field {
/// The kind of inheritance a base class is using.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BaseKind {
/// Normal inheritance, like:
///
@@ -201,6 +201,13 @@ pub struct Base {
pub kind: BaseKind,
}
+impl Base {
+ /// Whether this base class is inheriting virtually.
+ pub fn is_virtual(&self) -> bool {
+ self.kind == BaseKind::Virtual
+ }
+}
+
/// A compound type.
///
/// Either a struct or union, a compound type is built up from the combination