@@ -174,6 +174,40 @@ impl<'a> CanDeriveCopy<'a> for Field {
174
174
}
175
175
}
176
176
177
+
178
+ /// The kind of inheritance a base class is using.
179
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
180
+ pub enum BaseKind {
181
+ /// Normal inheritance, like:
182
+ ///
183
+ /// ```cpp
184
+ /// class A : public B {};
185
+ /// ```
186
+ Normal ,
187
+ /// Virtual inheritance, like:
188
+ ///
189
+ /// ```cpp
190
+ /// class A: public virtual B {};
191
+ /// ```
192
+ Virtual ,
193
+ }
194
+
195
+ /// A base class.
196
+ #[ derive( Clone , Debug ) ]
197
+ pub struct Base {
198
+ /// The type of this base class.
199
+ pub ty : ItemId ,
200
+ /// The kind of inheritance we're doing.
201
+ pub kind : BaseKind ,
202
+ }
203
+
204
+ impl Base {
205
+ /// Whether this base class is inheriting virtually.
206
+ pub fn is_virtual ( & self ) -> bool {
207
+ self . kind == BaseKind :: Virtual
208
+ }
209
+ }
210
+
177
211
/// A compound type.
178
212
///
179
213
/// Either a struct or union, a compound type is built up from the combination
@@ -199,7 +233,7 @@ pub struct CompInfo {
199
233
constructors : Vec < ItemId > ,
200
234
201
235
/// Vector of classes this one inherits from.
202
- base_members : Vec < ItemId > ,
236
+ base_members : Vec < Base > ,
203
237
204
238
/// The parent reference template if any.
205
239
ref_template : Option < ItemId > ,
@@ -287,7 +321,7 @@ impl CompInfo {
287
321
pub fn is_unsized ( & self , ctx : & BindgenContext ) -> bool {
288
322
!self . has_vtable ( ctx) && self . fields . is_empty ( ) &&
289
323
self . base_members . iter ( ) . all ( |base| {
290
- ctx. resolve_type ( * base) . canonical_type ( ctx) . is_unsized ( ctx)
324
+ ctx. resolve_type ( base. ty ) . canonical_type ( ctx) . is_unsized ( ctx)
291
325
} ) &&
292
326
self . ref_template
293
327
. map_or ( true , |template| ctx. resolve_type ( template) . is_unsized ( ctx) )
@@ -314,12 +348,12 @@ impl CompInfo {
314
348
self . ref_template . as_ref ( ) . map_or ( false , |t| {
315
349
ctx. resolve_type ( * t) . has_destructor ( ctx)
316
350
} ) ||
317
- self . template_args
318
- . iter ( )
319
- . any ( |t| ctx . resolve_type ( * t ) . has_destructor ( ctx ) ) ||
320
- self . base_members
321
- . iter ( )
322
- . any ( |t| ctx . resolve_type ( * t ) . has_destructor ( ctx ) ) ||
351
+ self . template_args . iter ( ) . any ( |t| {
352
+ ctx . resolve_type ( * t ) . has_destructor ( ctx )
353
+ } ) ||
354
+ self . base_members . iter ( ) . any ( |base| {
355
+ ctx . resolve_type ( base . ty ) . has_destructor ( ctx )
356
+ } ) ||
323
357
self . fields . iter ( ) . any ( |field| {
324
358
ctx. resolve_type ( field. ty )
325
359
. has_destructor ( ctx)
@@ -394,7 +428,7 @@ impl CompInfo {
394
428
pub fn has_vtable ( & self , ctx : & BindgenContext ) -> bool {
395
429
self . has_vtable ||
396
430
self . base_members ( ) . iter ( ) . any ( |base| {
397
- ctx. resolve_type ( * base)
431
+ ctx. resolve_type ( base. ty )
398
432
. has_vtable ( ctx)
399
433
} ) ||
400
434
self . ref_template . map_or ( false , |template| {
@@ -418,7 +452,7 @@ impl CompInfo {
418
452
}
419
453
420
454
/// The set of types that this one inherits from.
421
- pub fn base_members ( & self ) -> & [ ItemId ] {
455
+ pub fn base_members ( & self ) -> & [ Base ] {
422
456
& self . base_members
423
457
}
424
458
@@ -590,14 +624,23 @@ impl CompInfo {
590
624
ci. template_args . push ( param) ;
591
625
}
592
626
CXCursor_CXXBaseSpecifier => {
593
- if !ci. has_vtable {
594
- ci. has_vtable = cur. is_virtual_base ( ) ;
595
- }
627
+ let is_virtual_base = cur. is_virtual_base ( ) ;
628
+ ci. has_vtable |= is_virtual_base;
629
+
630
+ let kind = if is_virtual_base {
631
+ BaseKind :: Virtual
632
+ } else {
633
+ BaseKind :: Normal
634
+ } ;
635
+
596
636
let type_id = Item :: from_ty_or_ref ( cur. cur_type ( ) ,
597
637
Some ( cur) ,
598
638
None ,
599
639
ctx) ;
600
- ci. base_members . push ( type_id) ;
640
+ ci. base_members . push ( Base {
641
+ ty : type_id,
642
+ kind : kind,
643
+ } ) ;
601
644
}
602
645
CXCursor_Constructor |
603
646
CXCursor_Destructor |
@@ -794,7 +837,7 @@ impl CompInfo {
794
837
// Unfortunately, given the way we implement --match-pat, and also
795
838
// that you can inherit from templated types, we need to handle
796
839
// other cases here too.
797
- ctx. resolve_type ( * base)
840
+ ctx. resolve_type ( base. ty )
798
841
. canonical_type ( ctx)
799
842
. as_comp ( )
800
843
. map_or ( false , |ci| ci. has_vtable ( ctx) )
@@ -835,7 +878,7 @@ impl CanDeriveDebug for CompInfo {
835
878
let can_derive_debug = {
836
879
self . base_members
837
880
. iter ( )
838
- . all ( |id| id . can_derive_debug ( ctx, ( ) ) ) &&
881
+ . all ( |base| base . ty . can_derive_debug ( ctx, ( ) ) ) &&
839
882
self . template_args
840
883
. iter ( )
841
884
. all ( |id| id. can_derive_debug ( ctx, ( ) ) ) &&
@@ -888,7 +931,7 @@ impl<'a> CanDeriveCopy<'a> for CompInfo {
888
931
. map_or ( true , |t| t. can_derive_copy ( ctx, ( ) ) ) &&
889
932
self . base_members
890
933
. iter ( )
891
- . all ( |t| t . can_derive_copy ( ctx, ( ) ) ) &&
934
+ . all ( |base| base . ty . can_derive_copy ( ctx, ( ) ) ) &&
892
935
self . fields . iter ( ) . all ( |field| field. can_derive_copy ( ctx, ( ) ) )
893
936
}
894
937
@@ -916,8 +959,8 @@ impl TypeCollector for CompInfo {
916
959
types. insert ( arg) ;
917
960
}
918
961
919
- for & base in self . base_members ( ) {
920
- types. insert ( base) ;
962
+ for base in self . base_members ( ) {
963
+ types. insert ( base. ty ) ;
921
964
}
922
965
923
966
for field in self . fields ( ) {
0 commit comments