@@ -102,6 +102,8 @@ pub struct Field {
102
102
bitfield : Option < u32 > ,
103
103
/// If the C++ field is marked as `mutable`
104
104
mutable : bool ,
105
+ /// The offset of the field (in bits)
106
+ offset : usize ,
105
107
}
106
108
107
109
impl Field {
@@ -111,7 +113,8 @@ impl Field {
111
113
comment : Option < String > ,
112
114
annotations : Option < Annotations > ,
113
115
bitfield : Option < u32 > ,
114
- mutable : bool )
116
+ mutable : bool ,
117
+ offset : usize )
115
118
-> Field {
116
119
Field {
117
120
name : name,
@@ -120,6 +123,7 @@ impl Field {
120
123
annotations : annotations. unwrap_or_default ( ) ,
121
124
bitfield : bitfield,
122
125
mutable : mutable,
126
+ offset : offset,
123
127
}
124
128
}
125
129
@@ -152,6 +156,11 @@ impl Field {
152
156
pub fn annotations ( & self ) -> & Annotations {
153
157
& self . annotations
154
158
}
159
+
160
+ /// The offset of the field (in bits)
161
+ pub fn offset ( & self ) -> usize {
162
+ self . offset
163
+ }
155
164
}
156
165
157
166
impl CanDeriveDebug for Field {
@@ -532,7 +541,7 @@ impl CompInfo {
532
541
cursor. visit ( |cur| {
533
542
if cur. kind ( ) != CXCursor_FieldDecl {
534
543
if let Some ( ( ty, _) ) = maybe_anonymous_struct_field {
535
- let field = Field :: new ( None , ty, None , None , None , false ) ;
544
+ let field = Field :: new ( None , ty, None , None , None , false , 0 ) ;
536
545
ci. fields . push ( field) ;
537
546
}
538
547
maybe_anonymous_struct_field = None ;
@@ -555,7 +564,8 @@ impl CompInfo {
555
564
None ,
556
565
None ,
557
566
None ,
558
- false ) ;
567
+ false ,
568
+ 0 ) ;
559
569
ci. fields . push ( field) ;
560
570
}
561
571
}
@@ -572,6 +582,7 @@ impl CompInfo {
572
582
let annotations = Annotations :: new ( & cur) ;
573
583
let name = cur. spelling ( ) ;
574
584
let is_mutable = cursor. is_mutable_field ( ) ;
585
+ let offset = cur. offset_of_field ( ) . unwrap ( ) ; // TODO
575
586
576
587
// Name can be empty if there are bitfields, for example,
577
588
// see tests/headers/struct_with_bitfields.h
@@ -585,7 +596,8 @@ impl CompInfo {
585
596
comment,
586
597
annotations,
587
598
bit_width,
588
- is_mutable) ;
599
+ is_mutable,
600
+ offset) ;
589
601
ci. fields . push ( field) ;
590
602
591
603
// No we look for things like attributes and stuff.
@@ -748,7 +760,7 @@ impl CompInfo {
748
760
} ) ;
749
761
750
762
if let Some ( ( ty, _) ) = maybe_anonymous_struct_field {
751
- let field = Field :: new ( None , ty, None , None , None , false ) ;
763
+ let field = Field :: new ( None , ty, None , None , None , false , 0 ) ;
752
764
ci. fields . push ( field) ;
753
765
}
754
766
0 commit comments