File tree 11 files changed +40
-0
lines changed
src/bindgen/language_backend
11 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -912,9 +912,11 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
912
912
let ordered_fields = out. bindings ( ) . struct_field_names ( path) ;
913
913
for ( i, ordered_key) in ordered_fields. iter ( ) . enumerate ( ) {
914
914
if let Some ( lit) = fields. get ( ordered_key) {
915
+ let condition = lit. cfg . to_condition ( self . config ) ;
915
916
if is_constexpr {
916
917
out. new_line ( ) ;
917
918
919
+ condition. write_before ( self . config , out) ;
918
920
// TODO: Some C++ versions (c++20?) now support designated
919
921
// initializers, consider generating them.
920
922
write ! ( out, "/* .{} = */ " , ordered_key) ;
@@ -925,6 +927,7 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
925
927
write ! ( out, " " ) ;
926
928
}
927
929
}
930
+ condition. write_after ( self . config , out) ;
928
931
} else {
929
932
if i > 0 {
930
933
write ! ( out, ", " ) ;
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ typedef struct {
77
77
#endif
78
78
;
79
79
} ConditionalField ;
80
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
81
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
80
82
81
83
typedef struct {
82
84
int32_t x ;
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ typedef struct {
95
95
#endif
96
96
;
97
97
} ConditionalField ;
98
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
99
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
98
100
99
101
typedef struct {
100
102
int32_t x ;
Original file line number Diff line number Diff line change @@ -201,6 +201,16 @@ struct ConditionalField {
201
201
#endif
202
202
;
203
203
};
204
+ constexpr static const ConditionalField ConditionalField_ZERO = ConditionalField{
205
+ #if defined(X11)
206
+ /* .field = */ 0
207
+ #endif
208
+ };
209
+ constexpr static const ConditionalField ConditionalField_ONE = ConditionalField{
210
+ #if defined(X11)
211
+ /* .field = */ 1
212
+ #endif
213
+ };
204
214
205
215
struct Normal {
206
216
int32_t x;
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ cdef extern from *:
57
57
58
58
ctypedef struct ConditionalField:
59
59
int32_t field;
60
+ const ConditionalField ConditionalField_ZERO # = <ConditionalField>{ 0 }
61
+ const ConditionalField ConditionalField_ONE # = <ConditionalField>{ 1 }
60
62
61
63
ctypedef struct Normal:
62
64
int32_t x;
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ typedef struct ConditionalField {
77
77
#endif
78
78
;
79
79
} ConditionalField ;
80
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
81
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
80
82
81
83
typedef struct Normal {
82
84
int32_t x ;
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ typedef struct ConditionalField {
95
95
#endif
96
96
;
97
97
} ConditionalField ;
98
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
99
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
98
100
99
101
typedef struct Normal {
100
102
int32_t x ;
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ struct ConditionalField {
77
77
#endif
78
78
;
79
79
};
80
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
81
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
80
82
81
83
struct Normal {
82
84
int32_t x ;
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ struct ConditionalField {
95
95
#endif
96
96
;
97
97
};
98
+ #define ConditionalField_ZERO (ConditionalField){ .field = 0 }
99
+ #define ConditionalField_ONE (ConditionalField){ .field = 1 }
98
100
99
101
struct Normal {
100
102
int32_t x ;
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ cdef extern from *:
57
57
58
58
cdef struct ConditionalField:
59
59
int32_t field;
60
+ const ConditionalField ConditionalField_ZERO # = <ConditionalField>{ 0 }
61
+ const ConditionalField ConditionalField_ONE # = <ConditionalField>{ 1 }
60
62
61
63
cdef struct Normal:
62
64
int32_t x;
Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ struct ConditionalField {
49
49
field : i32 ,
50
50
}
51
51
52
+ impl ConditionalField {
53
+ pub const ZERO : Self = Self {
54
+ #[ cfg( x11) ]
55
+ field : 0 ,
56
+ } ;
57
+ pub const ONE : Self = Self {
58
+ #[ cfg( x11) ]
59
+ field : 1 ,
60
+ } ;
61
+ }
62
+
52
63
#[ cfg( all( unix, x11) ) ]
53
64
#[ no_mangle]
54
65
pub extern "C" fn root ( a : FooHandle , c : C )
You can’t perform that action at this time.
0 commit comments