@@ -459,48 +459,6 @@ pub enum Stmt {
459
459
} ,
460
460
}
461
461
462
- fn parse_struct (
463
- entity : & Entity < ' _ > ,
464
- context : & Context < ' _ > ,
465
- ) -> ( bool , Vec < ( String , Ty ) > , Option < bool > ) {
466
- let mut boxable = false ;
467
- let mut fields = Vec :: new ( ) ;
468
- let mut sendable = None ;
469
-
470
- immediate_children ( entity, |entity, span| match entity. get_kind ( ) {
471
- EntityKind :: UnexposedAttr => {
472
- if let Some ( attr) = UnexposedAttr :: parse ( & entity, context) {
473
- match attr {
474
- UnexposedAttr :: Sendable => sendable = Some ( true ) ,
475
- UnexposedAttr :: NonSendable => sendable = Some ( false ) ,
476
- attr => error ! ( ?attr, "unknown attribute" ) ,
477
- }
478
- }
479
- }
480
- EntityKind :: FieldDecl => {
481
- drop ( span) ;
482
- let name = entity. get_name ( ) . expect ( "struct field name" ) ;
483
- let _span = debug_span ! ( "field" , name) . entered ( ) ;
484
-
485
- let ty = entity. get_type ( ) . expect ( "struct field type" ) ;
486
- let ty = Ty :: parse_struct_field ( ty, context) ;
487
-
488
- if entity. is_bit_field ( ) {
489
- error ! ( "unsound struct bitfield" ) ;
490
- }
491
-
492
- fields. push ( ( name, ty) )
493
- }
494
- EntityKind :: ObjCBoxable => {
495
- boxable = true ;
496
- }
497
- EntityKind :: UnionDecl => error ! ( "can't handle unions in structs yet" ) ,
498
- _ => error ! ( "unknown" ) ,
499
- } ) ;
500
-
501
- ( boxable, fields, sendable)
502
- }
503
-
504
462
fn parse_fn_param_children ( entity : & Entity < ' _ > , context : & Context < ' _ > ) {
505
463
immediate_children ( entity, |entity, _span| match entity. get_kind ( ) {
506
464
EntityKind :: UnexposedAttr => {
@@ -890,9 +848,6 @@ impl Stmt {
890
848
EntityKind :: TypedefDecl => {
891
849
let id = ItemIdentifier :: new ( entity, context) ;
892
850
let availability = Availability :: parse ( entity, context) ;
893
- let mut struct_ = None ;
894
- let mut encoding_name = "?" . to_string ( ) ;
895
- let mut skip_struct = false ;
896
851
let mut kind = None ;
897
852
898
853
immediate_children ( entity, |entity, _span| match entity. get_kind ( ) {
@@ -908,55 +863,14 @@ impl Stmt {
908
863
}
909
864
}
910
865
}
911
- EntityKind :: StructDecl => {
912
- if context
913
- . struct_data
914
- . get ( & id. name )
915
- . map ( |data| data. skipped )
916
- . unwrap_or_default ( )
917
- {
918
- skip_struct = true ;
919
- return ;
920
- }
921
-
922
- if let Some ( name) = entity. get_name ( ) {
923
- // if the struct has a name use it
924
- // otherwise it will be the default "?"
925
- encoding_name = name;
926
- }
927
-
928
- if encoding_name == "?" || encoding_name. starts_with ( '_' ) {
929
- // If this struct doesn't have a name, or the
930
- // name is private, let's parse it with the
931
- // typedef name.
932
- struct_ = Some ( parse_struct ( & entity, context) )
933
- } else {
934
- skip_struct = true ;
935
- }
936
- }
937
- EntityKind :: ObjCClassRef
866
+ EntityKind :: StructDecl
867
+ | EntityKind :: ObjCClassRef
938
868
| EntityKind :: ObjCProtocolRef
939
869
| EntityKind :: TypeRef
940
870
| EntityKind :: ParmDecl => { }
941
871
_ => error ! ( "unknown" ) ,
942
872
} ) ;
943
873
944
- if let Some ( ( boxable, fields, sendable) ) = struct_ {
945
- assert_eq ! ( kind, None , "should not have parsed a kind" ) ;
946
- return vec ! [ Self :: StructDecl {
947
- id,
948
- encoding_name: Some ( encoding_name) ,
949
- availability,
950
- boxable,
951
- fields,
952
- sendable,
953
- } ] ;
954
- }
955
-
956
- if skip_struct {
957
- return vec ! [ ] ;
958
- }
959
-
960
874
if context
961
875
. typedef_data
962
876
. get ( & id. name )
@@ -981,37 +895,76 @@ impl Stmt {
981
895
}
982
896
}
983
897
EntityKind :: StructDecl => {
984
- if let Some ( name) = entity. get_name ( ) {
985
- let availability = Availability :: parse ( entity, context) ;
986
- let id = ItemIdentifier :: with_name ( name, entity, context) ;
987
-
988
- if context
989
- . struct_data
990
- . get ( & id. name )
991
- . map ( |data| data. skipped )
992
- . unwrap_or_default ( )
993
- {
994
- return vec ! [ ] ;
995
- }
898
+ let id = ItemIdentifier :: new ( entity, context) ;
996
899
997
- // See https://github.com/rust-lang/rust-bindgen/blob/95fd17b874910184cc0fcd33b287fa4e205d9d7a/bindgen/ir/comp.rs#L1392-L1408
998
- if !entity. is_definition ( ) {
999
- return vec ! [ ] ;
900
+ let availability = Availability :: parse ( entity, context) ;
901
+
902
+ if context
903
+ . struct_data
904
+ . get ( & id. name )
905
+ . map ( |data| data. skipped )
906
+ . unwrap_or_default ( )
907
+ {
908
+ return vec ! [ ] ;
909
+ }
910
+
911
+ // See https://github.com/rust-lang/rust-bindgen/blob/95fd17b874910184cc0fcd33b287fa4e205d9d7a/bindgen/ir/comp.rs#L1392-L1408
912
+ if !entity. is_definition ( ) {
913
+ return vec ! [ ] ;
914
+ }
915
+
916
+ let ty = entity. get_type ( ) . unwrap ( ) ;
917
+ let enc = ty. get_objc_encoding ( ) . unwrap ( ) ;
918
+ let encoding_name = enc. strip_prefix ( '{' ) . unwrap ( ) . split_once ( '=' ) . unwrap ( ) . 0 ;
919
+ let encoding_name = if encoding_name == id. name {
920
+ None
921
+ } else {
922
+ Some ( encoding_name. to_string ( ) )
923
+ } ;
924
+
925
+ let mut boxable = false ;
926
+ let mut fields = Vec :: new ( ) ;
927
+ let mut sendable = None ;
928
+
929
+ immediate_children ( entity, |entity, span| match entity. get_kind ( ) {
930
+ EntityKind :: UnexposedAttr => {
931
+ if let Some ( attr) = UnexposedAttr :: parse ( & entity, context) {
932
+ match attr {
933
+ UnexposedAttr :: Sendable => sendable = Some ( true ) ,
934
+ UnexposedAttr :: NonSendable => sendable = Some ( false ) ,
935
+ attr => error ! ( ?attr, "unknown attribute" ) ,
936
+ }
937
+ }
1000
938
}
939
+ EntityKind :: FieldDecl => {
940
+ drop ( span) ;
941
+ let name = entity. get_name ( ) . expect ( "struct field name" ) ;
942
+ let _span = debug_span ! ( "field" , name) . entered ( ) ;
1001
943
1002
- if !id. name . starts_with ( '_' ) {
1003
- let ( boxable, fields, sendable) = parse_struct ( entity, context) ;
1004
- return vec ! [ Self :: StructDecl {
1005
- id,
1006
- encoding_name: None ,
1007
- availability,
1008
- boxable,
1009
- fields,
1010
- sendable,
1011
- } ] ;
944
+ let ty = entity. get_type ( ) . expect ( "struct field type" ) ;
945
+ let ty = Ty :: parse_struct_field ( ty, context) ;
946
+
947
+ if entity. is_bit_field ( ) {
948
+ error ! ( "unsound struct bitfield" ) ;
949
+ }
950
+
951
+ fields. push ( ( name, ty) )
1012
952
}
1013
- }
1014
- vec ! [ ]
953
+ EntityKind :: ObjCBoxable => {
954
+ boxable = true ;
955
+ }
956
+ EntityKind :: UnionDecl => error ! ( "can't handle unions in structs yet" ) ,
957
+ _ => error ! ( "unknown" ) ,
958
+ } ) ;
959
+
960
+ return vec ! [ Self :: StructDecl {
961
+ id,
962
+ encoding_name,
963
+ availability,
964
+ boxable,
965
+ fields,
966
+ sendable,
967
+ } ] ;
1015
968
}
1016
969
EntityKind :: EnumDecl => {
1017
970
// Enum declarations show up twice for some reason, but
@@ -1020,7 +973,16 @@ impl Stmt {
1020
973
return vec ! [ ] ;
1021
974
}
1022
975
1023
- let id = ItemIdentifier :: new_optional ( entity, context) ;
976
+ let mut id = ItemIdentifier :: new_optional ( entity, context) ;
977
+
978
+ if id
979
+ . name
980
+ . as_deref ( )
981
+ . map ( |name| name. starts_with ( "enum (unnamed at" ) )
982
+ . unwrap_or ( false )
983
+ {
984
+ id. name = None ;
985
+ }
1024
986
1025
987
let data = context
1026
988
. enum_data
0 commit comments