@@ -14,6 +14,7 @@ use crate::{
14
14
library:: * ,
15
15
nameutil:: * ,
16
16
traits:: * ,
17
+ update_cfgs,
17
18
} ;
18
19
19
20
pub fn generate ( env : & Env ) {
@@ -164,7 +165,8 @@ fn generate_aliases(w: &mut dyn Write, env: &Env, items: &[&Alias]) -> Result<()
164
165
writeln ! ( w, "// Aliases" ) ?;
165
166
}
166
167
for item in items {
167
- let full_name = format ! ( "{}.{}" , env. namespaces. main( ) . name, item. name) ;
168
+ let ns = env. namespaces . main ( ) ;
169
+ let full_name = format ! ( "{}.{}" , ns. name, item. name) ;
168
170
if !env. type_status_sys ( & full_name) . need_generate ( ) {
169
171
continue ;
170
172
}
@@ -176,8 +178,17 @@ fn generate_aliases(w: &mut dyn Write, env: &Env, items: &[&Alias]) -> Result<()
176
178
. config
177
179
. objects
178
180
. get ( & full_name)
179
- . and_then ( |obj| obj. cfg_condition . as_ref ( ) ) ;
180
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
181
+ . and_then ( |obj| {
182
+ update_cfgs:: get_object_cfg_condition (
183
+ & item. name ,
184
+ & obj. cfg_condition ,
185
+ & ns. identifier_prefixes ,
186
+ )
187
+ } )
188
+ . or_else ( || {
189
+ update_cfgs:: get_object_cfg_condition ( & item. name , & None , & ns. identifier_prefixes )
190
+ } ) ;
191
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
181
192
writeln ! ( w, "{}pub type {} = {};" , comment, item. c_identifier, c_type) ?;
182
193
}
183
194
if !items. is_empty ( ) {
@@ -224,13 +235,15 @@ fn generate_bitfields(w: &mut dyn Write, env: &Env, items: &[&Bitfield]) -> Resu
224
235
225
236
fn generate_constant_cfg_configure (
226
237
w : & mut dyn Write ,
238
+ constant : & Constant ,
227
239
configured_constants : & [ & constants:: Constant ] ,
228
240
commented : bool ,
229
241
) -> Result < ( ) > {
230
242
let cfg_condition_ = configured_constants
231
243
. iter ( )
232
- . find_map ( |f| f. cfg_condition . as_ref ( ) ) ;
233
- cfg_condition ( w, cfg_condition_, commented, 1 ) ?;
244
+ . find_map ( |f| update_cfgs:: get_constant_cfg_condition ( & constant. name , & f. cfg_condition ) )
245
+ . or_else ( || update_cfgs:: get_constant_cfg_condition ( & constant. name , & None ) ) ;
246
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , commented, 1 ) ?;
234
247
Ok ( ( ) )
235
248
}
236
249
@@ -270,7 +283,12 @@ fn generate_constants(w: &mut dyn Write, env: &Env, constants: &[Constant]) -> R
270
283
271
284
if let Some ( obj) = config {
272
285
let configured_constants = obj. constants . matched ( & full_name) ;
273
- generate_constant_cfg_configure ( w, & configured_constants, !comment. is_empty ( ) ) ?;
286
+ generate_constant_cfg_configure (
287
+ w,
288
+ constant,
289
+ & configured_constants,
290
+ !comment. is_empty ( ) ,
291
+ ) ?;
274
292
}
275
293
276
294
writeln ! (
@@ -291,7 +309,8 @@ fn generate_enums(w: &mut dyn Write, env: &Env, items: &[&Enumeration]) -> Resul
291
309
writeln ! ( w, "// Enums" ) ?;
292
310
}
293
311
for item in items {
294
- let full_name = format ! ( "{}.{}" , env. namespaces. main( ) . name, item. name) ;
312
+ let ns = env. namespaces . main ( ) ;
313
+ let full_name = format ! ( "{}.{}" , ns. name, item. name) ;
295
314
let config = env. config . objects . get ( & full_name) ;
296
315
if let Some ( false ) = config. map ( |c| c. status . need_generate ( ) ) {
297
316
continue ;
@@ -300,8 +319,17 @@ fn generate_enums(w: &mut dyn Write, env: &Env, items: &[&Enumeration]) -> Resul
300
319
. config
301
320
. objects
302
321
. get ( & full_name)
303
- . and_then ( |obj| obj. cfg_condition . as_ref ( ) ) ;
304
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
322
+ . and_then ( |obj| {
323
+ update_cfgs:: get_object_cfg_condition (
324
+ & item. name ,
325
+ & obj. cfg_condition ,
326
+ & ns. identifier_prefixes ,
327
+ )
328
+ } )
329
+ . or_else ( || {
330
+ update_cfgs:: get_object_cfg_condition ( & item. name , & None , & ns. identifier_prefixes )
331
+ } ) ;
332
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
305
333
writeln ! ( w, "pub type {} = c_int;" , item. c_type) ?;
306
334
for member in & item. members {
307
335
let member_config = config
@@ -317,7 +345,7 @@ fn generate_enums(w: &mut dyn Write, env: &Env, items: &[&Enumeration]) -> Resul
317
345
continue ;
318
346
}
319
347
320
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
348
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
321
349
version_condition ( w, env, None , version, false , 0 ) ?;
322
350
writeln ! (
323
351
w,
@@ -404,18 +432,32 @@ fn generate_interfaces_structs(
404
432
writeln ! ( w, "// Interfaces" ) ?;
405
433
}
406
434
for interface in interfaces {
407
- let full_name = format ! ( "{}.{}" , env. namespaces. main( ) . name, interface. name) ;
435
+ let ns = env. namespaces . main ( ) ;
436
+ let full_name = format ! ( "{}.{}" , ns. name, interface. name) ;
408
437
if !env. type_status_sys ( & full_name) . need_generate ( ) {
409
438
continue ;
410
439
}
411
440
let cfg_condition_ = env
412
441
. config
413
442
. objects
414
443
. get ( & full_name)
415
- . and_then ( |obj| obj. cfg_condition . as_ref ( ) ) ;
416
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
444
+ . and_then ( |obj| {
445
+ update_cfgs:: get_object_cfg_condition (
446
+ & interface. name ,
447
+ & obj. cfg_condition ,
448
+ & ns. identifier_prefixes ,
449
+ )
450
+ } )
451
+ . or_else ( || {
452
+ update_cfgs:: get_object_cfg_condition (
453
+ & interface. name ,
454
+ & None ,
455
+ & ns. identifier_prefixes ,
456
+ )
457
+ } ) ;
458
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
417
459
generate_opaque_type ( w, & interface. c_type ) ?;
418
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
460
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
419
461
generate_debug_impl (
420
462
w,
421
463
& interface. c_type ,
@@ -490,15 +532,25 @@ impl ::std::fmt::Debug for GHookList {
490
532
}
491
533
492
534
fn generate_disguised ( w : & mut dyn Write , env : & Env , record : & Record ) -> Result < ( ) > {
493
- let full_name = format ! ( "{}.{}" , env. namespaces. main( ) . name, record. name) ;
535
+ let ns = env. namespaces . main ( ) ;
536
+ let full_name = format ! ( "{}.{}" , ns. name, record. name) ;
494
537
let cfg_condition_ = env
495
538
. config
496
539
. objects
497
540
. get ( & full_name)
498
- . and_then ( |obj| obj. cfg_condition . as_ref ( ) ) ;
499
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
541
+ . and_then ( |obj| {
542
+ update_cfgs:: get_object_cfg_condition (
543
+ & record. name ,
544
+ & obj. cfg_condition ,
545
+ & ns. identifier_prefixes ,
546
+ )
547
+ } )
548
+ . or_else ( || {
549
+ update_cfgs:: get_object_cfg_condition ( & record. name , & None , & ns. identifier_prefixes )
550
+ } ) ;
551
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
500
552
generate_opaque_type ( w, & format ! ( "_{}" , record. c_type) ) ?;
501
- cfg_condition ( w, cfg_condition_, false , 0 ) ?;
553
+ cfg_condition ( w, cfg_condition_. as_ref ( ) , false , 0 ) ?;
502
554
if record. pointer {
503
555
writeln ! ( w, "pub type {name} = *mut _{name};" , name = record. c_type) ?;
504
556
} else {
0 commit comments