@@ -49,6 +49,7 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
49
49
bool returnIsProtocol = needsReturn && ( ( entity != null && entity . EntityType == EntityType . Protocol ) || entityType == EntityType . ProtocolList ) ;
50
50
bool returnIsTuple = needsReturn && entityType == EntityType . Tuple ;
51
51
bool returnIsClosure = needsReturn && entityType == EntityType . Closure ;
52
+ bool returnIsBool = needsReturn && entityType == EntityType . Scalar && funcDecl . ReturnTypeName == "Swift.Bool" ;
52
53
53
54
var callParams = new List < CSBaseExpression > ( ) ;
54
55
var preMarshalCode = new List < CSLine > ( ) ;
@@ -65,6 +66,7 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
65
66
entity = ! newValueIsGeneric ? typeMapper . GetEntityForTypeSpec ( swiftNewValue . TypeSpec ) : null ;
66
67
entityType = ! newValueIsGeneric ? typeMapper . GetEntityTypeForTypeSpec ( swiftNewValue . TypeSpec ) : EntityType . None ;
67
68
var isUnusualNewValue = IsUnusualParameter ( entity , delegateParams [ 1 ] ) ;
69
+ var newValueIsBool = entityType == EntityType . Scalar && swiftNewValue . TypeName == "Swift.Bool" ;
68
70
69
71
if ( entityType == EntityType . Class || entity != null && entity . IsObjCProtocol ) {
70
72
var csParmType = new CSSimpleType ( entity . SharpNamespace + "." + entity . SharpTypeName ) ;
@@ -120,6 +122,8 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
120
122
valueID , genRef . Typeof ( ) ) ) ) ;
121
123
preMarshalCode . Add ( valDecl ) ;
122
124
valueExpr = valMarshalId ;
125
+ } else if ( newValueIsBool ) {
126
+ valueExpr = NIntToBool ( valueExpr ) ;
123
127
}
124
128
}
125
129
@@ -132,6 +136,7 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
132
136
entityType = ! parmIsGeneric ? typeMapper . GetEntityTypeForTypeSpec ( swiftParm . TypeSpec ) : EntityType . None ;
133
137
var isUnusualParameter = IsUnusualParameter ( entity , delegateParams [ i ] ) ;
134
138
var csParm = methodParams [ j ] ;
139
+ var parmIsBool = entityType == EntityType . Scalar && swiftParm . TypeName == "Swift.Bool" ;
135
140
136
141
if ( entityType == EntityType . DynamicSelf ) {
137
142
var retrieveCallSite = isObjC ? $ "Runtime.GetNSObject<{ csProxyName } > " : $ "SwiftObjectRegistry.Registry.CSObjectForSwiftObject<{ csProxyName } > ";
@@ -260,7 +265,11 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
260
265
callParams . Add ( new CSIdentifier ( String . Format ( "{0} {1}" ,
261
266
csParm . ParameterKind == CSParameterKind . Out ? "out" : "ref" , delegateParams [ i ] . Name . Name ) ) ) ;
262
267
} else {
263
- callParams . Add ( delegateParams [ i ] . Name ) ;
268
+ CSBaseExpression parmExpr = delegateParams [ i ] . Name ;
269
+ if ( parmIsBool ) {
270
+ parmExpr = NIntToBool ( parmExpr ) ;
271
+ }
272
+ callParams . Add ( parmExpr ) ;
264
273
}
265
274
}
266
275
}
@@ -405,6 +414,8 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSFunc (CSType thisType, st
405
414
} else {
406
415
if ( returnIsClosure ) {
407
416
invoker = MarshalEngine . BuildBlindClosureCall ( invoker , methodType as CSSimpleType , use ) ;
417
+ } else if ( returnIsBool ) {
418
+ invoker = BoolToNint ( invoker ) ;
408
419
}
409
420
if ( postMarshalCode . Count > 0 ) {
410
421
string retvalName = MarshalEngine . Uniqueify ( "retval" , identifiersUsed ) ;
@@ -448,6 +459,7 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSProp (CSProperty prop, CS
448
459
bool returnIsTuple = needsReturn && entityType == EntityType . Tuple ;
449
460
bool returnIsClosure = needsReturn && entityType == EntityType . Closure ;
450
461
bool returnIsDynamicSelf = needsReturn && forProtocol && methodType . ToString ( ) == NewClassCompiler . kGenericSelfName ;
462
+ var returnIsBool = needsReturn && entityType == EntityType . Scalar && funcDecl . ReturnTypeName == "Swift.Bool" ;
451
463
452
464
string returnCsProxyName = returnIsProtocol ?
453
465
NewClassCompiler . CSProxyNameForProtocol ( entity . Type . ToFullyQualifiedName ( true ) , typeMapper ) : null ;
@@ -544,14 +556,21 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSProp (CSProperty prop, CS
544
556
if ( returnIsClosure ) {
545
557
body . Add ( CSReturn . ReturnLine ( MarshalEngine . BuildBlindClosureCall ( csharpCall , methodType as CSSimpleType , use ) ) ) ;
546
558
} else {
547
- body . Add ( CSReturn . ReturnLine ( csharpCall ) ) ;
559
+ if ( returnIsBool ) {
560
+ body . Add ( CSReturn . ReturnLine ( BoolToNint ( csharpCall ) ) ) ;
561
+ } else {
562
+ body . Add ( CSReturn . ReturnLine ( csharpCall ) ) ;
563
+ }
548
564
}
549
565
}
550
566
} else {
551
567
CSBaseExpression valueExpr = null ;
552
- bool valueIsGeneric = funcDecl . IsTypeSpecGeneric ( funcDecl . ParameterLists [ 1 ] [ 0 ] . TypeSpec ) ;
553
- entity = ! valueIsGeneric ? typeMapper . GetEntityForTypeSpec ( funcDecl . ParameterLists [ 1 ] [ 0 ] . TypeSpec ) : null ;
568
+ var valueTypeSpec = funcDecl . ParameterLists [ 1 ] [ 0 ] . TypeSpec ;
569
+ var valueTypeName = funcDecl . ParameterLists [ 1 ] [ 0 ] . TypeName ;
570
+ bool valueIsGeneric = funcDecl . IsTypeSpecGeneric ( valueTypeSpec ) ;
571
+ entity = ! valueIsGeneric ? typeMapper . GetEntityForTypeSpec ( valueTypeSpec ) : null ;
554
572
entityType = ! valueIsGeneric ? typeMapper . GetEntityTypeForTypeSpec ( funcDecl . ParameterLists [ 1 ] [ 0 ] . TypeSpec ) : EntityType . None ;
573
+ var isBoolNewValue = entityType == EntityType . Scalar && valueTypeName == "Swift.Bool" ;
555
574
var isUnusualNewValue = IsUnusualParameter ( entity , delegateParams [ 1 ] ) ;
556
575
557
576
if ( entityType == EntityType . Class || ( entity != null && entity . IsObjCProtocol ) ) {
@@ -615,6 +634,9 @@ public List<ICodeElement> MarshalFromLambdaReceiverToCSProp (CSProperty prop, CS
615
634
valueExpr = MarshalEngine . BuildWrappedClosureCall ( delegateParams [ 1 ] . Name , methodType as CSSimpleType , flags ) ;
616
635
} else {
617
636
valueExpr = delegateParams [ 1 ] . Name ;
637
+ if ( isBoolNewValue ) {
638
+ valueExpr = NIntToBool ( valueExpr ) ;
639
+ }
618
640
}
619
641
}
620
642
body . Add ( CSAssignment . Assign ( csharpCall , valueExpr ) ) ;
@@ -627,6 +649,18 @@ static bool IsUnusualParameter (Entity entity, CSParameter parameter)
627
649
// check to see if an entity is either an objc struct or enum
628
650
return entity != null && ( entity . IsObjCStruct || entity . IsObjCEnum ) && parameter . ParameterKind == CSParameterKind . Ref ;
629
651
}
652
+
653
+ static CSBaseExpression NIntToBool ( CSBaseExpression expr )
654
+ {
655
+ // converts expr to
656
+ // (expr & 1) != 0;
657
+ return new CSParenthesisExpression ( new CSBinaryExpression ( CSBinaryOperator . BitAnd , expr , CSConstant . Val ( 1 ) ) ) != CSConstant . Val ( 0 ) ;
658
+ }
659
+
660
+ static CSBaseExpression BoolToNint ( CSBaseExpression expr )
661
+ {
662
+ return new CSTernary ( expr , CSConstant . Val ( 1 ) , CSConstant . Val ( 0 ) , false ) ;
663
+ }
630
664
}
631
665
}
632
666
0 commit comments