@@ -88,7 +88,11 @@ impl TestTemplate {
88
88
& mut self ,
89
89
helper : & TranslateHelper ,
90
90
) -> Result < ( ) , TranslationError > {
91
- for constant in helper. ffi_items . constants ( ) {
91
+ let should_skip = |map_input| helper. generator . skips . iter ( ) . any ( |f| f ( & map_input) ) ;
92
+
93
+ for constant in helper. ffi_items . constants ( ) . iter ( ) . filter ( |c| {
94
+ !( should_skip ( MapInput :: Const ( c) ) || helper. generator . skip_private && !c. public )
95
+ } ) {
92
96
if let syn:: Type :: Ptr ( ptr) = & constant. ty
93
97
&& let syn:: Type :: Path ( path) = & * ptr. elem
94
98
&& path. path . segments . last ( ) . unwrap ( ) . ident == "c_char"
@@ -126,7 +130,11 @@ impl TestTemplate {
126
130
& mut self ,
127
131
helper : & TranslateHelper ,
128
132
) -> Result < ( ) , TranslationError > {
129
- for alias in helper. ffi_items . aliases ( ) {
133
+ let should_skip = |map_input| helper. generator . skips . iter ( ) . any ( |f| f ( & map_input) ) ;
134
+
135
+ for alias in helper. ffi_items . aliases ( ) . iter ( ) . filter ( |a| {
136
+ !( should_skip ( MapInput :: Alias ( a) ) || helper. generator . skip_private && !a. public )
137
+ } ) {
130
138
let item = TestSizeAlign {
131
139
test_name : size_align_test_ident ( alias. ident ( ) ) ,
132
140
id : alias. ident ( ) . into ( ) ,
@@ -136,7 +144,9 @@ impl TestTemplate {
136
144
self . size_align_tests . push ( item. clone ( ) ) ;
137
145
self . test_idents . push ( item. test_name ) ;
138
146
}
139
- for struct_ in helper. ffi_items . structs ( ) {
147
+ for struct_ in helper. ffi_items . structs ( ) . iter ( ) . filter ( |s| {
148
+ !( should_skip ( MapInput :: Struct ( s) ) || helper. generator . skip_private && !s. public )
149
+ } ) {
140
150
let item = TestSizeAlign {
141
151
test_name : size_align_test_ident ( struct_. ident ( ) ) ,
142
152
id : struct_. ident ( ) . into ( ) ,
@@ -146,7 +156,9 @@ impl TestTemplate {
146
156
self . size_align_tests . push ( item. clone ( ) ) ;
147
157
self . test_idents . push ( item. test_name ) ;
148
158
}
149
- for union_ in helper. ffi_items . unions ( ) {
159
+ for union_ in helper. ffi_items . unions ( ) . iter ( ) . filter ( |u| {
160
+ !( should_skip ( MapInput :: Union ( u) ) || helper. generator . skip_private && !u. public )
161
+ } ) {
150
162
let item = TestSizeAlign {
151
163
test_name : size_align_test_ident ( union_. ident ( ) ) ,
152
164
id : union_. ident ( ) . into ( ) ,
@@ -167,7 +179,11 @@ impl TestTemplate {
167
179
& mut self ,
168
180
helper : & TranslateHelper ,
169
181
) -> Result < ( ) , TranslationError > {
170
- for alias in helper. ffi_items . aliases ( ) {
182
+ let should_skip = |map_input| helper. generator . skips . iter ( ) . any ( |f| f ( & map_input) ) ;
183
+
184
+ for alias in helper. ffi_items . aliases ( ) . iter ( ) . filter ( |a| {
185
+ !( should_skip ( MapInput :: Alias ( a) ) || helper. generator . skip_private && !a. public )
186
+ } ) {
171
187
let should_skip_signededness_test = helper
172
188
. generator
173
189
. skip_signededness
@@ -206,7 +222,10 @@ impl TestTemplate {
206
222
. iter ( )
207
223
. flat_map ( |struct_| struct_. fields . iter ( ) . map ( move |field| ( struct_, field) ) )
208
224
. filter ( |( struct_, field) | {
209
- !should_skip ( MapInput :: StructField ( struct_, field) ) && field. public
225
+ !( should_skip ( MapInput :: StructField ( struct_, field) )
226
+ || should_skip ( MapInput :: Struct ( struct_) )
227
+ || !field. public
228
+ || helper. generator . skip_private && !struct_. public )
210
229
} )
211
230
. map ( |( struct_, field) | {
212
231
(
@@ -222,7 +241,10 @@ impl TestTemplate {
222
241
. iter ( )
223
242
. flat_map ( |union_| union_. fields . iter ( ) . map ( move |field| ( union_, field) ) )
224
243
. filter ( |( union_, field) | {
225
- !should_skip ( MapInput :: UnionField ( union_, field) ) && field. public
244
+ !( should_skip ( MapInput :: UnionField ( union_, field) )
245
+ || should_skip ( MapInput :: Union ( union_) )
246
+ || !field. public
247
+ || helper. generator . skip_private && !union_. public )
226
248
} )
227
249
. map ( |( union_, field) | {
228
250
(
@@ -255,15 +277,23 @@ impl TestTemplate {
255
277
& mut self ,
256
278
helper : & TranslateHelper ,
257
279
) -> Result < ( ) , TranslationError > {
258
- for alias in helper. ffi_items . aliases ( ) {
280
+ let should_skip = |map_input| helper. generator . skips . iter ( ) . any ( |f| f ( & map_input) ) ;
281
+
282
+ for alias in helper. ffi_items . aliases ( ) . iter ( ) . filter ( |a| {
283
+ !( should_skip ( MapInput :: Alias ( a) ) || helper. generator . skip_private && !a. public )
284
+ } ) {
259
285
let c_ty = helper. c_type ( alias) ?;
260
286
self . add_roundtrip_test ( helper, alias. ident ( ) , & [ ] , & c_ty, true ) ;
261
287
}
262
- for struct_ in helper. ffi_items . structs ( ) {
288
+ for struct_ in helper. ffi_items . structs ( ) . iter ( ) . filter ( |s| {
289
+ !( should_skip ( MapInput :: Struct ( s) ) || helper. generator . skip_private && !s. public )
290
+ } ) {
263
291
let c_ty = helper. c_type ( struct_) ?;
264
292
self . add_roundtrip_test ( helper, struct_. ident ( ) , & struct_. fields , & c_ty, false ) ;
265
293
}
266
- for union_ in helper. ffi_items . unions ( ) {
294
+ for union_ in helper. ffi_items . unions ( ) . iter ( ) . filter ( |u| {
295
+ !( should_skip ( MapInput :: Union ( u) ) || helper. generator . skip_private && !u. public )
296
+ } ) {
267
297
let c_ty = helper. c_type ( union_) ?;
268
298
self . add_roundtrip_test ( helper, union_. ident ( ) , & union_. fields , & c_ty, false ) ;
269
299
}
@@ -312,9 +342,11 @@ impl TestTemplate {
312
342
. iter ( )
313
343
. flat_map ( |s| s. fields . iter ( ) . map ( move |f| ( s, f) ) )
314
344
. filter ( |( s, f) | {
315
- !should_skip ( MapInput :: StructField ( s, f) )
316
- && !should_skip ( MapInput :: StructFieldType ( s, f) )
317
- && f. public
345
+ !( should_skip ( MapInput :: StructField ( s, f) )
346
+ || should_skip ( MapInput :: StructFieldType ( s, f) )
347
+ || should_skip ( MapInput :: Struct ( s) )
348
+ || !f. public
349
+ || helper. generator . skip_private && !s. public )
318
350
} )
319
351
. map ( |( s, f) | {
320
352
(
@@ -341,9 +373,11 @@ impl TestTemplate {
341
373
. iter ( )
342
374
. flat_map ( |u| u. fields . iter ( ) . map ( move |f| ( u, f) ) )
343
375
. filter ( |( u, f) | {
344
- !should_skip ( MapInput :: UnionField ( u, f) )
345
- && !should_skip ( MapInput :: UnionFieldType ( u, f) )
346
- && f. public
376
+ !( should_skip ( MapInput :: UnionField ( u, f) )
377
+ || should_skip ( MapInput :: UnionFieldType ( u, f) )
378
+ || should_skip ( MapInput :: Union ( u) )
379
+ || !f. public
380
+ || helper. generator . skip_private && !u. public )
347
381
} )
348
382
. map ( |( u, f) | {
349
383
(
@@ -536,7 +570,7 @@ impl<'a> TranslateHelper<'a> {
536
570
MapInput :: Type ( _) => panic ! ( "MapInput::Type is not allowed!" ) ,
537
571
} ;
538
572
539
- let item = if self . ffi_items . contains_struct ( ident ) {
573
+ let item = if self . ffi_items . contains_struct ( & ty ) {
540
574
MapInput :: StructType ( & ty)
541
575
} else if self . ffi_items . contains_union ( ident) {
542
576
MapInput :: UnionType ( & ty)
@@ -554,21 +588,30 @@ impl<'a> TranslateHelper<'a> {
554
588
fn basic_c_type ( & self , ty : & syn:: Type ) -> Result < String , TranslationError > {
555
589
let type_name = match ty {
556
590
syn:: Type :: Path ( p) => p. path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ,
557
- syn:: Type :: Ptr ( p) => self . basic_c_type ( & p. elem ) ?,
558
- syn:: Type :: Reference ( r) => self . basic_c_type ( & r. elem ) ?,
591
+ // Using recursion here causes breakage.
592
+ // FIXME(ctest): Might be possible to extract this part into a function.
593
+ syn:: Type :: Ptr ( p) => match p. elem . deref ( ) {
594
+ syn:: Type :: Path ( p) => p. path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ,
595
+ _ => p. to_token_stream ( ) . to_string ( ) ,
596
+ } ,
597
+ syn:: Type :: Reference ( r) => match r. elem . deref ( ) {
598
+ syn:: Type :: Path ( p) => p. path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ,
599
+ _ => r. to_token_stream ( ) . to_string ( ) ,
600
+ } ,
559
601
_ => ty. to_token_stream ( ) . to_string ( ) ,
560
602
} ;
561
603
562
604
let unmapped_c_type = self . translator . translate_type ( ty) ?;
563
605
let item = if self . ffi_items . contains_struct ( & type_name) {
564
- MapInput :: StructType ( & unmapped_c_type )
606
+ MapInput :: StructType ( & type_name )
565
607
} else if self . ffi_items . contains_union ( & type_name) {
566
- MapInput :: UnionType ( & unmapped_c_type )
608
+ MapInput :: UnionType ( & type_name )
567
609
} else {
568
- MapInput :: Type ( & unmapped_c_type )
610
+ MapInput :: Type ( & type_name )
569
611
} ;
570
612
571
- Ok ( self . generator . rty_to_cty ( item) )
613
+ let mapped_type = self . generator . rty_to_cty ( item. clone ( ) ) ;
614
+ Ok ( unmapped_c_type. replace ( & type_name, & mapped_type) )
572
615
}
573
616
574
617
/// Partially translate a Rust bare function type into its equivalent C type.
0 commit comments