@@ -422,37 +422,36 @@ trait CodeGenerator {
422
422
/// Extra information from the caller.
423
423
type Extra ;
424
424
425
+ /// Extra information returned to the caller.
426
+ type Return ;
427
+
425
428
fn codegen < ' a > (
426
429
& self ,
427
430
ctx : & BindgenContext ,
428
431
result : & mut CodegenResult < ' a > ,
429
432
extra : & Self :: Extra ,
430
- ) ;
433
+ ) -> Self :: Return ;
431
434
}
432
435
433
- impl CodeGenerator for Item {
434
- type Extra = ( ) ;
435
-
436
- fn codegen < ' a > (
436
+ impl Item {
437
+ fn process_before_codegen (
437
438
& self ,
438
439
ctx : & BindgenContext ,
439
- result : & mut CodegenResult < ' a > ,
440
- _extra : & ( ) ,
441
- ) {
440
+ result : & mut CodegenResult ,
441
+ ) -> bool {
442
442
if !self . is_enabled_for_codegen ( ctx) {
443
- return ;
443
+ return false ;
444
444
}
445
445
446
446
if self . is_blocklisted ( ctx) || result. seen ( self . id ( ) ) {
447
447
debug ! (
448
- "<Item as CodeGenerator>::codegen : Ignoring hidden or seen: \
448
+ "<Item as CodeGenerator>::process_before_codegen : Ignoring hidden or seen: \
449
449
self = {:?}",
450
450
self
451
451
) ;
452
- return ;
452
+ return false ;
453
453
}
454
454
455
- debug ! ( "<Item as CodeGenerator>::codegen: self = {:?}" , self ) ;
456
455
if !ctx. codegen_items ( ) . contains ( & self . id ( ) ) {
457
456
// TODO(emilio, #453): Figure out what to do when this happens
458
457
// legitimately, we could track the opaque stuff and disable the
@@ -461,6 +460,24 @@ impl CodeGenerator for Item {
461
460
}
462
461
463
462
result. set_seen ( self . id ( ) ) ;
463
+ true
464
+ }
465
+ }
466
+
467
+ impl CodeGenerator for Item {
468
+ type Extra = ( ) ;
469
+ type Return = ( ) ;
470
+
471
+ fn codegen < ' a > (
472
+ & self ,
473
+ ctx : & BindgenContext ,
474
+ result : & mut CodegenResult < ' a > ,
475
+ _extra : & ( ) ,
476
+ ) {
477
+ debug ! ( "<Item as CodeGenerator>::codegen: self = {:?}" , self ) ;
478
+ if !self . process_before_codegen ( ctx, result) {
479
+ return ;
480
+ }
464
481
465
482
match * self . kind ( ) {
466
483
ItemKind :: Module ( ref module) => {
@@ -481,6 +498,7 @@ impl CodeGenerator for Item {
481
498
482
499
impl CodeGenerator for Module {
483
500
type Extra = Item ;
501
+ type Return = ( ) ;
484
502
485
503
fn codegen < ' a > (
486
504
& self ,
@@ -572,6 +590,8 @@ impl CodeGenerator for Module {
572
590
573
591
impl CodeGenerator for Var {
574
592
type Extra = Item ;
593
+ type Return = ( ) ;
594
+
575
595
fn codegen < ' a > (
576
596
& self ,
577
597
ctx : & BindgenContext ,
@@ -698,6 +718,7 @@ impl CodeGenerator for Var {
698
718
699
719
impl CodeGenerator for Type {
700
720
type Extra = Item ;
721
+ type Return = ( ) ;
701
722
702
723
fn codegen < ' a > (
703
724
& self ,
@@ -1004,6 +1025,7 @@ impl<'a> Vtable<'a> {
1004
1025
1005
1026
impl < ' a > CodeGenerator for Vtable < ' a > {
1006
1027
type Extra = Item ;
1028
+ type Return = ( ) ;
1007
1029
1008
1030
fn codegen < ' b > (
1009
1031
& self ,
@@ -1048,6 +1070,7 @@ impl<'a> TryToRustTy for Vtable<'a> {
1048
1070
1049
1071
impl CodeGenerator for TemplateInstantiation {
1050
1072
type Extra = Item ;
1073
+ type Return = ( ) ;
1051
1074
1052
1075
fn codegen < ' a > (
1053
1076
& self ,
@@ -1664,6 +1687,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1664
1687
1665
1688
impl CodeGenerator for CompInfo {
1666
1689
type Extra = Item ;
1690
+ type Return = ( ) ;
1667
1691
1668
1692
fn codegen < ' a > (
1669
1693
& self ,
@@ -2261,13 +2285,15 @@ impl MethodCodegen for Method {
2261
2285
2262
2286
// First of all, output the actual function.
2263
2287
let function_item = ctx. resolve_item ( self . signature ( ) ) ;
2264
- if function_item. is_blocklisted ( ctx) {
2265
- // We shouldn't emit a method declaration if the function is blocklisted
2288
+ if !function_item. process_before_codegen ( ctx, result) {
2266
2289
return ;
2267
2290
}
2268
- function_item. codegen ( ctx, result, & ( ) ) ;
2269
-
2270
2291
let function = function_item. expect_function ( ) ;
2292
+ let times_seen = function. codegen ( ctx, result, & function_item) ;
2293
+ let times_seen = match times_seen {
2294
+ Some ( seen) => seen,
2295
+ None => return ,
2296
+ } ;
2271
2297
let signature_item = ctx. resolve_item ( function. signature ( ) ) ;
2272
2298
let mut name = match self . kind ( ) {
2273
2299
MethodKind :: Constructor => "new" . into ( ) ,
@@ -2302,7 +2328,11 @@ impl MethodCodegen for Method {
2302
2328
name. push_str ( & count. to_string ( ) ) ;
2303
2329
}
2304
2330
2305
- let function_name = ctx. rust_ident ( function_item. canonical_name ( ctx) ) ;
2331
+ let mut function_name = function_item. canonical_name ( ctx) ;
2332
+ if times_seen > 0 {
2333
+ write ! ( & mut function_name, "{}" , times_seen) . unwrap ( ) ;
2334
+ }
2335
+ let function_name = ctx. rust_ident ( function_name) ;
2306
2336
let mut args = utils:: fnsig_arguments ( ctx, signature) ;
2307
2337
let mut ret = utils:: fnsig_return_ty ( ctx, signature) ;
2308
2338
@@ -2808,6 +2838,7 @@ impl<'a> EnumBuilder<'a> {
2808
2838
2809
2839
impl CodeGenerator for Enum {
2810
2840
type Extra = Item ;
2841
+ type Return = ( ) ;
2811
2842
2812
2843
fn codegen < ' a > (
2813
2844
& self ,
@@ -3731,19 +3762,23 @@ impl TryToRustTy for FunctionSig {
3731
3762
impl CodeGenerator for Function {
3732
3763
type Extra = Item ;
3733
3764
3765
+ /// If we've actually generated the symbol, the number of times we've seen
3766
+ /// it.
3767
+ type Return = Option < u32 > ;
3768
+
3734
3769
fn codegen < ' a > (
3735
3770
& self ,
3736
3771
ctx : & BindgenContext ,
3737
3772
result : & mut CodegenResult < ' a > ,
3738
3773
item : & Item ,
3739
- ) {
3774
+ ) -> Self :: Return {
3740
3775
debug ! ( "<Function as CodeGenerator>::codegen: item = {:?}" , item) ;
3741
3776
debug_assert ! ( item. is_enabled_for_codegen( ctx) ) ;
3742
3777
3743
3778
// We can't currently do anything with Internal functions so just
3744
3779
// avoid generating anything for them.
3745
3780
match self . linkage ( ) {
3746
- Linkage :: Internal => return ,
3781
+ Linkage :: Internal => return None ,
3747
3782
Linkage :: External => { }
3748
3783
}
3749
3784
@@ -3753,7 +3788,7 @@ impl CodeGenerator for Function {
3753
3788
FunctionKind :: Method ( ref method_kind)
3754
3789
if method_kind. is_pure_virtual ( ) =>
3755
3790
{
3756
- return ;
3791
+ return None ;
3757
3792
}
3758
3793
_ => { }
3759
3794
}
@@ -3763,7 +3798,7 @@ impl CodeGenerator for Function {
3763
3798
// instantiations is open ended and we have no way of knowing which
3764
3799
// monomorphizations actually exist.
3765
3800
if !item. all_template_params ( ctx) . is_empty ( ) {
3766
- return ;
3801
+ return None ;
3767
3802
}
3768
3803
3769
3804
let name = self . name ( ) ;
@@ -3776,7 +3811,7 @@ impl CodeGenerator for Function {
3776
3811
// TODO: Maybe warn here if there's a type/argument mismatch, or
3777
3812
// something?
3778
3813
if result. seen_function ( seen_symbol_name) {
3779
- return ;
3814
+ return None ;
3780
3815
}
3781
3816
result. saw_function ( seen_symbol_name) ;
3782
3817
}
@@ -3803,21 +3838,14 @@ impl CodeGenerator for Function {
3803
3838
attributes. push ( attributes:: doc ( comment) ) ;
3804
3839
}
3805
3840
3806
- // Handle overloaded functions by giving each overload its own unique
3807
- // suffix.
3808
- let times_seen = result. overload_number ( & canonical_name) ;
3809
- if times_seen > 0 {
3810
- write ! ( & mut canonical_name, "{}" , times_seen) . unwrap ( ) ;
3811
- }
3812
-
3813
3841
let abi = match signature. abi ( ) {
3814
3842
Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
3815
3843
warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
3816
- return ;
3844
+ return None ;
3817
3845
}
3818
3846
Abi :: Win64 if signature. is_variadic ( ) => {
3819
3847
warn ! ( "Skipping variadic function with Win64 ABI that isn't supported" ) ;
3820
- return ;
3848
+ return None ;
3821
3849
}
3822
3850
Abi :: Unknown ( unknown_abi) => {
3823
3851
panic ! (
@@ -3828,6 +3856,13 @@ impl CodeGenerator for Function {
3828
3856
abi => abi,
3829
3857
} ;
3830
3858
3859
+ // Handle overloaded functions by giving each overload its own unique
3860
+ // suffix.
3861
+ let times_seen = result. overload_number ( & canonical_name) ;
3862
+ if times_seen > 0 {
3863
+ write ! ( & mut canonical_name, "{}" , times_seen) . unwrap ( ) ;
3864
+ }
3865
+
3831
3866
let link_name = mangled_name. unwrap_or ( name) ;
3832
3867
if !utils:: names_will_be_identical_after_mangling (
3833
3868
& canonical_name,
@@ -3878,6 +3913,7 @@ impl CodeGenerator for Function {
3878
3913
} else {
3879
3914
result. push ( tokens) ;
3880
3915
}
3916
+ Some ( times_seen)
3881
3917
}
3882
3918
}
3883
3919
@@ -3933,6 +3969,7 @@ fn objc_method_codegen(
3933
3969
3934
3970
impl CodeGenerator for ObjCInterface {
3935
3971
type Extra = Item ;
3972
+ type Return = ( ) ;
3936
3973
3937
3974
fn codegen < ' a > (
3938
3975
& self ,
0 commit comments