@@ -753,6 +753,7 @@ impl<'a> Bitfield<'a> {
753
753
754
754
fn codegen_fields ( self ,
755
755
ctx : & BindgenContext ,
756
+ parent : & CompInfo ,
756
757
fields : & mut Vec < ast:: StructField > ,
757
758
methods : & mut Vec < ast:: ImplItem > )
758
759
-> Layout {
@@ -790,6 +791,7 @@ impl<'a> Bitfield<'a> {
790
791
// We've finished a physical field, so flush it and its bitfields.
791
792
field_size_in_bits = align_to ( field_size_in_bits, field_align) ;
792
793
fields. push ( flush_bitfields ( ctx,
794
+ parent,
793
795
field_size_in_bits,
794
796
last_field_align,
795
797
& last_field_name,
@@ -831,6 +833,7 @@ impl<'a> Bitfield<'a> {
831
833
if field_size_in_bits != 0 {
832
834
// Flush the last physical field and its bitfields.
833
835
fields. push ( flush_bitfields ( ctx,
836
+ parent,
834
837
field_size_in_bits,
835
838
last_field_align,
836
839
& last_field_name,
@@ -842,12 +845,59 @@ impl<'a> Bitfield<'a> {
842
845
}
843
846
}
844
847
848
+ fn parent_has_method ( ctx : & BindgenContext ,
849
+ parent : & CompInfo ,
850
+ name : & str )
851
+ -> bool {
852
+ parent. methods ( ) . iter ( ) . any ( |method| {
853
+ let method_name = match * ctx. resolve_item ( method. signature ( ) ) . kind ( ) {
854
+ ItemKind :: Function ( ref func) => func. name ( ) ,
855
+ ref otherwise => panic ! ( "a method's signature should always be a \
856
+ item of kind ItemKind::Function, found: \
857
+ {:?}",
858
+ otherwise) ,
859
+ } ;
860
+
861
+ method_name == name || ctx. rust_mangle ( & method_name) == name
862
+ } )
863
+ }
864
+
865
+ fn bitfield_getter_name ( ctx : & BindgenContext ,
866
+ parent : & CompInfo ,
867
+ bitfield_name : & str )
868
+ -> ast:: Ident {
869
+ let name = ctx. rust_mangle ( bitfield_name) ;
870
+
871
+ if parent_has_method ( ctx, parent, & name) {
872
+ let mut name = name. to_string ( ) ;
873
+ name. push_str ( "_bindgen_bitfield" ) ;
874
+ return ctx. ext_cx ( ) . ident_of ( & name) ;
875
+ }
876
+
877
+ ctx. ext_cx ( ) . ident_of ( & name)
878
+ }
879
+
880
+ fn bitfield_setter_name ( ctx : & BindgenContext ,
881
+ parent : & CompInfo ,
882
+ bitfield_name : & str )
883
+ -> ast:: Ident {
884
+ let setter = format ! ( "set_{}" , bitfield_name) ;
885
+ let mut setter = ctx. rust_mangle ( & setter) . to_string ( ) ;
886
+
887
+ if parent_has_method ( ctx, parent, & setter) {
888
+ setter. push_str ( "_bindgen_bitfield" ) ;
889
+ }
890
+
891
+ ctx. ext_cx ( ) . ident_of ( & setter)
892
+ }
893
+
845
894
/// A physical field (which is a word or byte or ...) has many logical bitfields
846
895
/// contained within it, but not all bitfields are in the same physical field of
847
896
/// a struct. This function creates a single physical field and flushes all the
848
897
/// accessors for the logical `bitfields` within that physical field to the
849
898
/// outgoing `methods`.
850
899
fn flush_bitfields < ' a , I > ( ctx : & BindgenContext ,
900
+ parent : & CompInfo ,
851
901
field_size_in_bits : usize ,
852
902
field_align : usize ,
853
903
field_name : & str ,
@@ -867,9 +917,8 @@ fn flush_bitfields<'a, I>(ctx: &BindgenContext,
867
917
868
918
for ( name, offset, width, bitfield_ty, bitfield_layout) in bitfields {
869
919
let prefix = ctx. trait_prefix ( ) ;
870
- let getter_name = ctx. rust_ident ( name) ;
871
- let setter_name = ctx. ext_cx ( )
872
- . ident_of ( & format ! ( "set_{}" , & name) ) ;
920
+ let getter_name = bitfield_getter_name ( ctx, parent, name) ;
921
+ let setter_name = bitfield_setter_name ( ctx, parent, name) ;
873
922
let field_ident = ctx. ext_cx ( ) . ident_of ( field_name) ;
874
923
875
924
let field_int_ty = match field_layout. size {
@@ -1184,7 +1233,7 @@ impl CodeGenerator for CompInfo {
1184
1233
mem:: replace ( & mut current_bitfield_fields, vec ! [ ] ) ;
1185
1234
let bitfield_layout = Bitfield :: new ( & mut bitfield_count,
1186
1235
bitfield_fields)
1187
- . codegen_fields ( ctx, & mut fields, & mut methods) ;
1236
+ . codegen_fields ( ctx, self , & mut fields, & mut methods) ;
1188
1237
struct_layout. saw_bitfield_batch ( bitfield_layout) ;
1189
1238
1190
1239
current_bitfield_width = None ;
@@ -1339,7 +1388,7 @@ impl CodeGenerator for CompInfo {
1339
1388
vec ! [ ] ) ;
1340
1389
let bitfield_layout = Bitfield :: new ( & mut bitfield_count,
1341
1390
bitfield_fields)
1342
- . codegen_fields ( ctx, & mut fields, & mut methods) ;
1391
+ . codegen_fields ( ctx, self , & mut fields, & mut methods) ;
1343
1392
struct_layout. saw_bitfield_batch ( bitfield_layout) ;
1344
1393
}
1345
1394
debug_assert ! ( current_bitfield_fields. is_empty( ) ) ;
0 commit comments