@@ -835,6 +835,8 @@ CSClass CompileEnumClass (EnumDeclaration enumDecl, string enumCaseName, CSEnum
835
835
pinvokes . Add ( enumPI ) ;
836
836
var usedPinvokeNames = new List < string > ( ) ;
837
837
838
+ use . AddIfNotPresent ( typeof ( SwiftNativeValueType ) ) ;
839
+ enumClass . Inheritance . Add ( typeof ( SwiftNativeValueType ) ) ;
838
840
use . AddIfNotPresent ( typeof ( ISwiftEnum ) ) ;
839
841
enumClass . Inheritance . Add ( typeof ( ISwiftEnum ) ) ;
840
842
var enumContents = moduleInventory . FindClass ( enumDecl . ToFullyQualifiedName ( true ) ) ;
@@ -843,7 +845,6 @@ CSClass CompileEnumClass (EnumDeclaration enumDecl, string enumCaseName, CSEnum
843
845
}
844
846
AddGenerics ( enumClass , enumDecl , enumContents , use ) ;
845
847
846
- ReserveFieldSpace ( enumClass ) ;
847
848
string witName = enumContents . WitnessTable . ValueWitnessTable != null ? enumContents . WitnessTable . ValueWitnessTable . MangledName . Substring ( 1 ) : "" ;
848
849
string nomSym = enumContents . TypeDescriptor . MangledName . Substring ( 1 ) ;
849
850
string metaDataSym = enumContents . DirectMetadata != null ? enumContents . DirectMetadata . MangledName . Substring ( 1 ) : "" ;
@@ -852,7 +853,7 @@ CSClass CompileEnumClass (EnumDeclaration enumDecl, string enumCaseName, CSEnum
852
853
853
854
string libPath = PInvokeName ( wrapper . ModuleLibPath , swiftLibPath ) ;
854
855
855
- ImplementNominalIDisposable ( enumClass , use ) ;
856
+ ImplementValueTypeIDisposable ( enumClass , use ) ;
856
857
AddInheritedProtocols ( enumDecl , enumClass , enumContents , PInvokeName ( swiftLibPath ) , use , errors ) ;
857
858
858
859
ImplementMethods ( enumClass , enumPI , usedPinvokeNames , swiftEnumName , classContents , enumDecl , use , wrapper , tlf => true , swiftLibPath , errors ) ;
@@ -944,7 +945,7 @@ CSClass CompileEnumClass (EnumDeclaration enumDecl, string enumCaseName, CSEnum
944
945
945
946
CompileInnerNominalsInto ( enumDecl , enumClass , moduleInventory , use , wrapper , swiftLibPath , pinvokes , errors ) ;
946
947
947
- TypeNameAttribute ( enumDecl ) . AttachBefore ( enumClass ) ;
948
+ TypeNameAttribute ( enumDecl , use ) . AttachBefore ( enumClass ) ;
948
949
return enumClass ;
949
950
}
950
951
@@ -1100,17 +1101,6 @@ void CompileEnumPayload(CSClass cl, EnumDeclaration enumDecl, EnumElement elemen
1100
1101
cl . Properties . Add ( payloadProperty ) ;
1101
1102
}
1102
1103
1103
-
1104
-
1105
- static void ReserveFieldSpace ( CSClass enumStruct )
1106
- {
1107
- // public byte[] SwiftData { get; set; }
1108
-
1109
- enumStruct . Properties . Add ( new CSProperty ( new CSSimpleType ( "byte" , true ) ,
1110
- CSMethodKind . None , new CSIdentifier ( "SwiftData" ) , CSVisibility . Public , new CSCodeBlock ( ) , CSVisibility . Public , new CSCodeBlock ( ) ) ) ;
1111
-
1112
- }
1113
-
1114
1104
static TLFunction FindEnumCaseFinderWrapper ( EnumDeclaration enumDecl , WrappingResult wrapper )
1115
1105
{
1116
1106
string caseFinderName = MethodWrapping . EnumCaseFinderWrapperName ( enumDecl ) ;
@@ -1401,7 +1391,8 @@ CSEnum CompileTrivialEnum (EnumDeclaration enumDecl, ModuleInventory module, CSU
1401
1391
currentRawValue ++ ;
1402
1392
csEnum . Values . Add ( enumBinding ) ;
1403
1393
}
1404
- TypeNameAttribute ( enumDecl ) . AttachBefore ( csEnum ) ;
1394
+
1395
+ TypeNameAttribute ( enumDecl , use ) . AttachBefore ( csEnum ) ;
1405
1396
return csEnum ;
1406
1397
}
1407
1398
@@ -1491,12 +1482,13 @@ CSClass CompileFinalStruct (StructDeclaration structDecl, ModuleInventory modInv
1491
1482
var picl = new CSClass ( CSVisibility . Internal , PIClassName ( swiftClassName ) ) ;
1492
1483
var usedPinvokeNames = new List < string > ( ) ;
1493
1484
1485
+ use . AddIfNotPresent ( typeof ( SwiftNativeValueType ) ) ;
1486
+ st . Inheritance . Add ( typeof ( SwiftNativeValueType ) ) ;
1494
1487
use . AddIfNotPresent ( typeof ( ISwiftStruct ) ) ;
1495
1488
st . Inheritance . Add ( typeof ( ISwiftStruct ) ) ;
1496
1489
pinvokes . Add ( picl ) ;
1497
1490
AddGenerics ( st , structDecl , classContents , use ) ;
1498
- ReserveFieldSpace ( st ) ;
1499
- ImplementNominalIDisposable ( st , use ) ;
1491
+ ImplementValueTypeIDisposable ( st , use ) ;
1500
1492
1501
1493
CompileInnerNominalsInto ( structDecl , st , modInventory , use , wrapper , swiftLibraryPath , pinvokes , errors ) ;
1502
1494
@@ -1509,7 +1501,7 @@ CSClass CompileFinalStruct (StructDeclaration structDecl, ModuleInventory modInv
1509
1501
classContents . WitnessTable . ValueWitnessTable . MangledName . Substring ( 1 ) :
1510
1502
"" ;
1511
1503
MakeSwiftStructTypeAttribute ( PInvokeName ( swiftLibraryPath ) ,
1512
- nomSym , metaDataSym , witSym ) . AttachBefore ( st ) ;
1504
+ nomSym , metaDataSym , witSym , use ) . AttachBefore ( st ) ;
1513
1505
1514
1506
var ctors = MakeStructConstructors ( st , picl , usedPinvokeNames , structDecl , classContents ,
1515
1507
use , st . ToCSType ( ) , wrapper , swiftLibraryPath , errors ) ;
@@ -1526,7 +1518,7 @@ CSClass CompileFinalStruct (StructDeclaration structDecl, ModuleInventory modInv
1526
1518
ImplementProperties ( st , picl , usedPinvokeNames , structDecl , classContents , null , use , wrapper , true , false , tlf => true , swiftLibraryPath , errors ) ;
1527
1519
ImplementSubscripts ( st , picl , usedPinvokeNames , structDecl . AllSubscripts ( ) , classContents , null , use , wrapper , true , tlf => true , swiftLibraryPath , errors ) ;
1528
1520
1529
- TypeNameAttribute ( structDecl ) . AttachBefore ( st ) ;
1521
+ TypeNameAttribute ( structDecl , use ) . AttachBefore ( st ) ;
1530
1522
return st ;
1531
1523
}
1532
1524
@@ -1846,7 +1838,7 @@ CSInterface CompileInterfaceAndProxy (ProtocolDeclaration protocolDecl, ModuleIn
1846
1838
ImplementProxyConstructorAndFields ( proxyClass , use , hasVtable , iface , false ) ;
1847
1839
}
1848
1840
1849
- TypeNameAttribute ( protocolDecl ) . AttachBefore ( iface ) ;
1841
+ TypeNameAttribute ( protocolDecl , use ) . AttachBefore ( iface ) ;
1850
1842
return iface ;
1851
1843
}
1852
1844
@@ -1987,7 +1979,7 @@ CSClass CompileVirtualClass (ClassDeclaration classDecl, ModuleInventory modInve
1987
1979
if ( wrapUse != null )
1988
1980
use . Remove ( wrapUse ) ;
1989
1981
1990
- TypeNameAttribute ( classDecl ) . AttachBefore ( cl ) ;
1982
+ TypeNameAttribute ( classDecl , use ) . AttachBefore ( cl ) ;
1991
1983
return cl ;
1992
1984
}
1993
1985
@@ -3099,7 +3091,7 @@ CSClass CompileFinalClass (ClassDeclaration classDecl, ModuleInventory modInvent
3099
3091
ImplementProperties ( cl , picl , usedPinvokeNames , classDecl , classContents , null , use , wrapper , false , false , tlf => true , swiftLibraryPath , errors ) ;
3100
3092
ImplementSubscripts ( cl , picl , usedPinvokeNames , classDecl . AllSubscripts ( ) , classContents , null , use , wrapper , true , tlf => true , swiftLibraryPath , errors ) ;
3101
3093
3102
- TypeNameAttribute ( classDecl ) . AttachBefore ( cl ) ;
3094
+ TypeNameAttribute ( classDecl , use ) . AttachBefore ( cl ) ;
3103
3095
return cl ;
3104
3096
}
3105
3097
@@ -3511,62 +3503,8 @@ void ImplementObjCClassField (CSClass cl)
3511
3503
cl . Properties . Add ( prop ) ;
3512
3504
}
3513
3505
3514
- void ImplementNominalIDisposable ( CSClass cl , CSUsingPackages use )
3506
+ void ImplementValueTypeIDisposable ( CSClass cl , CSUsingPackages use )
3515
3507
{
3516
- //public void Dispose()
3517
- //{
3518
- // Dispose(true);
3519
- // GC.SuppressFinalize(this);
3520
- //}
3521
- var disposeID = new CSIdentifier ( "Dispose" ) ;
3522
- var disp1Body = new CSCodeBlock ( ) ;
3523
- var disp1 = new CSMethod ( CSVisibility . Public , CSMethodKind . None , CSSimpleType . Void ,
3524
- disposeID , new CSParameterList ( ) , disp1Body ) ;
3525
- disp1Body . Add ( CSFunctionCall . FunctionCallLine ( disposeID , false , CSConstant . Val ( true ) ) ) ;
3526
- use . AddIfNotPresent ( typeof ( GC ) ) ;
3527
- disp1Body . Add ( CSFunctionCall . FunctionCallLine ( "GC.SuppressFinalize" , false , CSIdentifier . This ) ) ;
3528
- cl . Methods . Add ( disp1 ) ;
3529
-
3530
- //private void Dispose(bool disposing)
3531
- //{
3532
- // if (SwiftData != null)
3533
- // {
3534
- // unsafe
3535
- // {
3536
- // fixed (byte* p = SwiftData)
3537
- // {
3538
- // StructMarshal.Marshaler.NominalDestroy(typeof(this), p);
3539
- // }
3540
- // SwiftData = null;
3541
- // }
3542
- // }
3543
- //}
3544
- var swiftDataID = new CSIdentifier ( "SwiftData" ) ;
3545
- var nullID = new CSIdentifier ( "null" ) ;
3546
- var disp2body = new CSCodeBlock ( ) ;
3547
- var disposingID = new CSIdentifier ( "disposing" ) ;
3548
- var disp2 = new CSMethod ( CSVisibility . None , CSMethodKind . None , CSSimpleType . Void ,
3549
- disposeID , new CSParameterList ( new CSParameter ( CSSimpleType . Bool , disposingID ) ) ,
3550
- disp2body ) ;
3551
- var bytestarID = new CSIdentifier ( "p" ) ;
3552
- var fixedBody = new CSCodeBlock ( ) ;
3553
- var fixedBlock = new CSFixedCodeBlock ( CSSimpleType . ByteStar , bytestarID , swiftDataID , fixedBody ) ;
3554
- use . AddIfNotPresent ( typeof ( StructMarshal ) ) ;
3555
- fixedBlock . Add ( CSFunctionCall . FunctionCallLine ( "StructMarshal.Marshaler.NominalDestroy" , false ,
3556
- new CSFunctionCall ( "typeof" , false , new CSIdentifier ( cl . ToCSType ( ) . ToString ( ) ) ) ,
3557
- bytestarID ) ) ;
3558
-
3559
- var unsafeBlock = new CSUnsafeCodeBlock ( null ) ;
3560
- unsafeBlock . Add ( fixedBlock ) ;
3561
- unsafeBlock . Add ( CSAssignment . Assign ( swiftDataID , CSAssignmentOperator . Assign , nullID ) ) ;
3562
-
3563
- var ifBlock = new CSCodeBlock ( ) ;
3564
- var ifelse = new CSIfElse ( swiftDataID != nullID , ifBlock ) ;
3565
- ifBlock . Add ( unsafeBlock ) ;
3566
- disp2body . Add ( ifelse ) ;
3567
-
3568
- cl . Methods . Add ( disp2 ) ;
3569
-
3570
3508
ImplementFinalizer ( cl ) ;
3571
3509
}
3572
3510
@@ -3846,10 +3784,10 @@ IEnumerable<CSMethod> MakeStructConstructors (CSClass st, CSClass picl, List<str
3846
3784
foreach ( CSMethod m in StructConstructorToMethod ( structDecl , funcDecl , st , picl , usedPinvokeNames , csStructType , classContents , tlf , use , wrapper , swiftLibraryPath , errors ) )
3847
3785
yield return m ;
3848
3786
}
3849
- yield return NominalDefaultConstructor ( csStructType , classContents , use ) ;
3787
+ yield return ValueTypeDefaultConstructor ( csStructType , classContents , use ) ;
3850
3788
}
3851
3789
3852
- CSMethod NominalDefaultConstructor ( CSType structType , ClassContents classContents , CSUsingPackages use )
3790
+ CSMethod ValueTypeDefaultConstructor ( CSType structType , ClassContents classContents , CSUsingPackages use )
3853
3791
{
3854
3792
var parms = new CSParameterList ( ) ;
3855
3793
use . AddIfNotPresent ( typeof ( SwiftValueTypeCtorArgument ) ) ;
@@ -3858,8 +3796,7 @@ CSMethod NominalDefaultConstructor (CSType structType, ClassContents classConten
3858
3796
3859
3797
string consName = StubbedClassName ( classContents . Name ) ;
3860
3798
3861
- var ctor = new CSMethod ( CSVisibility . Internal , CSMethodKind . None , null , new CSIdentifier ( consName ) , parms , body ) ;
3862
- body . Add ( CSFunctionCall . FunctionCallLine ( "StructMarshal.Marshaler.PrepareValueType" , false , CSIdentifier . This ) ) ;
3799
+ var ctor = new CSMethod ( CSVisibility . Internal , CSMethodKind . None , null , new CSIdentifier ( consName ) , parms , new CSBaseExpression [ 0 ] , true , body ) ;
3863
3800
3864
3801
return ctor ;
3865
3802
}
@@ -6066,8 +6003,9 @@ static CSAttribute MakeNominalTypeAttribute (string library, string nominalSym,
6066
6003
return CSAttribute . FromAttr ( typeof ( SwiftValueTypeAttribute ) , al , true ) ;
6067
6004
}
6068
6005
6069
- static CSAttribute MakeSwiftStructTypeAttribute ( string library , string nominalSym , string metaSym , string witnessSym )
6006
+ static CSAttribute MakeSwiftStructTypeAttribute ( string library , string nominalSym , string metaSym , string witnessSym , CSUsingPackages use )
6070
6007
{
6008
+ use . AddIfNotPresent ( typeof ( SwiftStructAttribute ) ) ;
6071
6009
var al = new CSArgumentList ( ) ;
6072
6010
al . Add ( CSConstant . Val ( library ) ) ;
6073
6011
al . Add ( CSConstant . Val ( nominalSym ) ) ;
@@ -6297,8 +6235,9 @@ static bool JustTheTypeNamesMatch (SwiftType st, TypeSpec sp)
6297
6235
return ct . ClassName . ToFullyQualifiedName ( false ) == named . NameWithoutModule ;
6298
6236
}
6299
6237
6300
- static CSAttribute TypeNameAttribute ( BaseDeclaration decl )
6238
+ static CSAttribute TypeNameAttribute ( BaseDeclaration decl , CSUsingPackages use )
6301
6239
{
6240
+ use . AddIfNotPresent ( typeof ( SwiftTypeNameAttribute ) ) ;
6302
6241
var argList = new CSArgumentList ( ) ;
6303
6242
argList . Add ( new CSArgument ( CSConstant . Val ( decl . ToFullyQualifiedName ( ) ) ) ) ;
6304
6243
return CSAttribute . FromAttr ( typeof ( SwiftTypeNameAttribute ) , argList ) ;
0 commit comments