@@ -2265,7 +2265,7 @@ CSProperty ImplementProtocolSubscriptEtter (WrappingResult wrapper,
2265
2265
List < CSLine > vtableAssignments , CSUsingPackages use , bool isSetter , CSProperty wrapperProp , string swiftLibraryPath )
2266
2266
{
2267
2267
CSDelegateTypeDecl etterDelegateDecl = DefineDelegateAndAddToVtable ( vtable , etterFunc , use ,
2268
- OverrideBuilder . VTableEntryIdentifier ( vtableEntryIndex ) , true ) ;
2268
+ OverrideBuilder . VTableEntryIdentifier ( vtableEntryIndex ) , ! protocolDecl . HasAssociatedTypes ) ;
2269
2269
vtable . Delegates . Add ( etterDelegateDecl ) ;
2270
2270
2271
2271
var etterWrapperFunc = FindProtocolWrapperFunction ( etterFunc , wrapper ) ;
@@ -2524,7 +2524,7 @@ int ImplementPropertyVtableForVirtualProperties (WrappingResult wrapper,
2524
2524
}
2525
2525
var wrapperProp = ImplementPropertyEtter ( wrapper , classDecl , subclassDecl , classContents , cl , picl , usedPinvokeNames , virtFuncs ,
2526
2526
getterFunc , tlSetter , vtableEntryIndex , vtableName , vtable , vtableAssignments , use ,
2527
- false , null , swiftLibraryPath ) ;
2527
+ false , null , swiftLibraryPath , null ) ;
2528
2528
2529
2529
if ( hasSetter ) {
2530
2530
wrapperProp = ImplementPropertyEtter ( wrapper , classDecl , subclassDecl , classContents , cl , picl , usedPinvokeNames , virtFuncs ,
@@ -2544,7 +2544,7 @@ CSProperty ImplementProtocolPropertyEtter (WrappingResult wrapper,
2544
2544
List < CSLine > vtableAssignments , CSUsingPackages use , bool isSetter , bool isObjC , CSProperty wrapperProp , string swiftLibraryPath )
2545
2545
{
2546
2546
var etterDelegateDecl = DefineDelegateAndAddToVtable ( vtable , etterFunc , use ,
2547
- OverrideBuilder . VTableEntryIdentifier ( vtableEntryIndex ) , true ) ;
2547
+ OverrideBuilder . VTableEntryIdentifier ( vtableEntryIndex ) , ! protocolDecl . HasAssociatedTypes ) ;
2548
2548
vtable . Delegates . Add ( etterDelegateDecl ) ;
2549
2549
2550
2550
var etterWrapperFunc = FindProtocolWrapperFunction ( etterFunc , wrapper ) ;
@@ -2561,7 +2561,7 @@ CSProperty ImplementProtocolPropertyEtter (WrappingResult wrapper,
2561
2561
piEtterName = Uniqueify ( piEtterName , usedPinvokeNames ) ;
2562
2562
usedPinvokeNames . Add ( piEtterName ) ;
2563
2563
2564
- string piEtterRef = PIClassName ( TypeMapper . GetDotNetNameForSwiftClassName ( protocolContents . Name ) ) + "." + piEtterName ;
2564
+ string piEtterRef = picl . Name + "." + piEtterName ;
2565
2565
var piGetter = TLFCompiler . CompileMethod ( etterWrapperFunc , use ,
2566
2566
PInvokeName ( wrapper . ModuleLibPath , swiftLibraryPath ) ,
2567
2567
etterWrapper . MangledName , piEtterName , true , true , false ) ;
@@ -2570,6 +2570,9 @@ CSProperty ImplementProtocolPropertyEtter (WrappingResult wrapper,
2570
2570
2571
2571
if ( wrapperProp == null ) {
2572
2572
wrapperProp = TLFCompiler . CompileProperty ( use , propName , etterFunc , setter , CSMethodKind . None ) ;
2573
+ if ( protocolDecl . HasAssociatedTypes ) {
2574
+ SubstituteAssociatedTypeNamer ( protocolDecl , wrapperProp ) ;
2575
+ }
2573
2576
2574
2577
var ifaceProp = new CSProperty ( wrapperProp . PropType , CSMethodKind . None ,
2575
2578
new CSIdentifier ( propName ) ,
@@ -2580,6 +2583,8 @@ CSProperty ImplementProtocolPropertyEtter (WrappingResult wrapper,
2580
2583
2581
2584
var usedIds = new List < string > { propName } ;
2582
2585
var marshal = new MarshalEngine ( use , usedIds , TypeMapper , wrapper . Module . SwiftCompilerVersion ) ;
2586
+ if ( protocolDecl . HasAssociatedTypes )
2587
+ marshal . GenericReferenceNamer = MakeAssociatedTypeNamer ( protocolDecl ) ;
2583
2588
2584
2589
var ifTest = kInterfaceImpl != CSConstant . Null ;
2585
2590
var ifBlock = new CSCodeBlock ( ) ;
@@ -2600,12 +2605,16 @@ CSProperty ImplementProtocolPropertyEtter (WrappingResult wrapper,
2600
2605
etterFunc , etterFunc . ReturnTypeSpec , wrapperProp . PropType , etterFunc . ParameterLists [ 0 ] [ 0 ] . TypeSpec , new CSSimpleType ( iface . Name . Name ) , false , wrapper , etterFunc . HasThrows ) ) ;
2601
2606
}
2602
2607
2603
- var ifElse = new CSIfElse ( ifTest , ifBlock , elseBlock ) ;
2604
- target . Add ( ifElse ) ;
2608
+ if ( protocolDecl . HasAssociatedTypes ) {
2609
+ target . AddRange ( elseBlock ) ;
2610
+ } else {
2611
+ var ifElse = new CSIfElse ( ifTest , ifBlock , elseBlock ) ;
2612
+ target . Add ( ifElse ) ;
2613
+ }
2605
2614
2606
2615
var recvr = ImplementVirtualPropertyStaticReceiver ( new CSSimpleType ( iface . Name . Name ) ,
2607
- proxyClass . Name . Name , etterDelegateDecl , use ,
2608
- etterFunc , wrapperProp , null , vtable . Name , isObjC ) ;
2616
+ proxyClass . ToCSType ( ) . ToString ( ) , etterDelegateDecl , use ,
2617
+ etterFunc , wrapperProp , null , vtable . Name , isObjC , protocolDecl . HasAssociatedTypes ) ;
2609
2618
proxyClass . Methods . Add ( recvr ) ;
2610
2619
2611
2620
vtableAssignments . Add ( CSAssignment . Assign ( String . Format ( "{0}.{1}" ,
@@ -2617,7 +2626,8 @@ CSProperty ImplementPropertyEtter (WrappingResult wrapper,
2617
2626
ClassDeclaration classDecl , ClassDeclaration subclassDecl ,
2618
2627
ClassContents classContents , CSClass cl , CSClass picl , List < string > usedPinvokeNames , List < FunctionDeclaration > virtFuncs ,
2619
2628
FunctionDeclaration etterFunc , TLFunction tlSetter , int vtableEntryIndex , string vtableName , CSStruct vtable ,
2620
- List < CSLine > vtableAssignments , CSUsingPackages use , bool isSetter , CSProperty wrapperProp , string swiftLibraryPath )
2629
+ List < CSLine > vtableAssignments , CSUsingPackages use , bool isSetter , CSProperty wrapperProp , string swiftLibraryPath ,
2630
+ Func < int , int , string > genericRenamer = null )
2621
2631
{
2622
2632
var swiftClassName = XmlToTLFunctionMapper . ToSwiftClassName ( subclassDecl ) ;
2623
2633
var tlEtter = XmlToTLFunctionMapper . ToTLFunction ( etterFunc , classContents ) ;
@@ -2644,7 +2654,8 @@ CSProperty ImplementPropertyEtter (WrappingResult wrapper,
2644
2654
2645
2655
var piGetter = TLFCompiler . CompileMethod ( etterWrapperFunc , use ,
2646
2656
PInvokeName ( wrapper . ModuleLibPath , swiftLibraryPath ) ,
2647
- etterWrapper . MangledName , piEtterName , true , true , false ) ; picl . Methods . Add ( piGetter ) ;
2657
+ etterWrapper . MangledName , piEtterName , true , true , false ) ;
2658
+ picl . Methods . Add ( piGetter ) ;
2648
2659
2649
2660
var superEtterFunc = subclassDecl . AllMethodsNoCDTor ( ) . Where ( fn =>
2650
2661
fn . Access == Accessibility . Internal && fn . IsProperty &&
@@ -2685,7 +2696,8 @@ CSProperty ImplementPropertyEtter (WrappingResult wrapper,
2685
2696
}
2686
2697
}
2687
2698
2688
- ImplementOverloadFromKnownWrapper ( cl , picl , usedPinvokeNames , swiftClassName , superEtterTlf , superEtterFunc , use , true , wrapper , swiftLibraryPath , superEtterFuncWrapper , "" , true ) ;
2699
+ ImplementOverloadFromKnownWrapper ( cl , picl , usedPinvokeNames , swiftClassName , superEtterTlf , superEtterFunc , use , true , wrapper , swiftLibraryPath , superEtterFuncWrapper , "" , true ,
2700
+ genericRenamer : genericRenamer ) ;
2689
2701
var propertyImplMethod = cl . Methods . Last ( ) ;
2690
2702
CSMethod protoListMethod = null ;
2691
2703
if ( returnIsProtocolList ) {
@@ -2711,7 +2723,7 @@ CSProperty ImplementPropertyEtter (WrappingResult wrapper,
2711
2723
}
2712
2724
2713
2725
var recvr = ImplementVirtualPropertyStaticReceiver ( cl . ToCSType ( ) , null , etterDelegateDecl , use , etterFunc ,
2714
- wrapperProp , protoListMethod , vtable . Name , classDecl . IsObjC ) ;
2726
+ wrapperProp , protoListMethod , vtable . Name , classDecl . IsObjC , false ) ;
2715
2727
cl . Methods . Add ( recvr ) ;
2716
2728
2717
2729
vtableAssignments . Add ( CSAssignment . Assign ( String . Format ( "{0}.{1}" ,
@@ -2841,7 +2853,7 @@ CSMethod ImplementVirtualSubscriptStaticReceiver (CSType thisType, string csProx
2841
2853
2842
2854
CSMethod ImplementVirtualPropertyStaticReceiver ( CSType thisType , string csProxyName , CSDelegateTypeDecl delType ,
2843
2855
CSUsingPackages use , FunctionDeclaration funcDecl , CSProperty prop , CSMethod protoListMethod ,
2844
- CSIdentifier vtableName , bool isObjC )
2856
+ CSIdentifier vtableName , bool isObjC , bool hasAssociatedTypes )
2845
2857
{
2846
2858
var returnType = funcDecl . IsGetter ? delType . Type : CSSimpleType . Void ;
2847
2859
CSParameterList pl = delType . Parameters ;
@@ -2860,7 +2872,7 @@ CSMethod ImplementVirtualPropertyStaticReceiver (CSType thisType, string csProxy
2860
2872
2861
2873
var bodyContents = marshaler . MarshalFromLambdaReceiverToCSProp ( prop , thisType , csProxyName ,
2862
2874
delType . Parameters ,
2863
- funcDecl , prop . PropType , isObjC ) ;
2875
+ funcDecl , prop . PropType , isObjC , hasAssociatedTypes ) ;
2864
2876
body . AddRange ( bodyContents ) ;
2865
2877
recvrName = "xamVtable_recv_" + ( funcDecl . IsGetter ? "get_" : "set_" ) + prop . Name . Name ;
2866
2878
}
@@ -2895,7 +2907,7 @@ CSLambda ImplementVirtualPropertyReceiver (CSType thisType, string csProxyName,
2895
2907
var marshaler = new MarshalEngineCSafeSwiftToCSharp ( use , usedIDs , TypeMapper ) ;
2896
2908
2897
2909
var bodyContents = marshaler . MarshalFromLambdaReceiverToCSProp ( prop , thisType , csProxyName , delType . Parameters ,
2898
- funcDecl , prop . PropType , isObjC ) ;
2910
+ funcDecl , prop . PropType , isObjC , false ) ;
2899
2911
var body = new CSCodeBlock ( bodyContents ) ;
2900
2912
return new CSLambda ( pl , body ) ;
2901
2913
}
@@ -5122,7 +5134,8 @@ CSIfElse InterfaceMethodRedirect (CSMethod publicMethod, IEnumerable<ICodeElemen
5122
5134
CSMethod ImplementOverloadFromKnownWrapper ( CSClass cl , CSClass picl , List < string > usedPinvokeNames , SwiftClassName classForPI ,
5123
5135
TLFunction methodToWrap , FunctionDeclaration funcToWrap , CSUsingPackages use , bool isFinal ,
5124
5136
WrappingResult wrapper , string swiftLibraryPath , TLFunction wrapperFunction ,
5125
- string homonymSuffix , bool forcePrivate = false , string alternativeName = null )
5137
+ string homonymSuffix , bool forcePrivate = false , string alternativeName = null ,
5138
+ Func < int , int , string > genericRenamer = null )
5126
5139
{
5127
5140
var wrapperFuncDecl = FindEquivalentFunctionDeclarationForWrapperFunction ( wrapperFunction , TypeMapper , wrapper ) ;
5128
5141
var pinvokeMethodName = PIMethodName ( classForPI , wrapperFunction . Name ) + homonymSuffix ;
@@ -5190,6 +5203,7 @@ CSMethod ImplementOverloadFromKnownWrapper (CSClass cl, CSClass picl, List<strin
5190
5203
} ;
5191
5204
5192
5205
var marshaler = new MarshalEngine ( use , localIdentifiers , TypeMapper , wrapper . Module . SwiftCompilerVersion ) ;
5206
+ marshaler . GenericReferenceNamer = genericRenamer ;
5193
5207
5194
5208
publicMethod . Body . AddRange ( marshaler . MarshalFunctionCall ( wrapperFuncDecl , false , pinvokeMethodRef ,
5195
5209
publicMethod . Parameters , funcToWrap , funcToWrap . ReturnTypeSpec , publicMethod . Type , instanceTypeSpec , cl . ToCSType ( ) ,
@@ -6330,6 +6344,12 @@ void SubstituteAssociatedTypeNamer (ProtocolDeclaration protocolDecl, CSMethod p
6330
6344
SubstituteAssociatedTypeNamer ( namer , parm . CSType ) ;
6331
6345
}
6332
6346
6347
+ void SubstituteAssociatedTypeNamer ( ProtocolDeclaration protocolDecl , CSProperty publicProperty )
6348
+ {
6349
+ var namer = MakeAssociatedTypeNamer ( protocolDecl ) ;
6350
+ SubstituteAssociatedTypeNamer ( namer , publicProperty . PropType ) ;
6351
+ }
6352
+
6333
6353
void SubstituteAssociatedTypeNamer ( Func < int , int , string > namer , CSType ty )
6334
6354
{
6335
6355
if ( ty is CSGenericReferenceType genType ) {
0 commit comments