@@ -1465,7 +1465,7 @@ SLFunc MapFuncDeclToWrapperFunc (SwiftClassName className, SLImportModules modul
1465
1465
1466
1466
GatherFunctionDeclarationGenerics ( funcDecl , genericDeclaration ) ;
1467
1467
1468
- var instanceName = hasInstance ? new SLIdentifier ( GetUniqueNameForInstance ( parms ) ) : null ;
1468
+ var instanceName = hasInstance ? new SLIdentifier ( GetUniqueNameForInstance ( usedNames ) ) : null ;
1469
1469
bool instanceIsAPointer = false ;
1470
1470
if ( hasInstance )
1471
1471
usedNames . Add ( instanceName . Name ) ;
@@ -1506,7 +1506,8 @@ SLFunc MapFuncDeclToWrapperFunc (SwiftClassName className, SLImportModules modul
1506
1506
// To mitigate this, all wrapper functions that return type struct need to have an extra
1507
1507
// parameter which is a reference to a struct.
1508
1508
if ( makeInOut ) {
1509
- returnName = new SLIdentifier ( GetUniqueNameForReturn ( parms ) ) ;
1509
+ returnName = new SLIdentifier ( GetUniqueNameForReturn ( usedNames ) ) ;
1510
+ usedNames . Add ( returnName . Name ) ;
1510
1511
1511
1512
if ( funcDecl . HasThrows ) {
1512
1513
SLType slReturn = null ;
@@ -1645,14 +1646,16 @@ SLFunc MapFuncDeclToWrapperFunc (SwiftClassName className, SLImportModules modul
1645
1646
} else {
1646
1647
string exceptionCall = "setExceptionNotThrown" ;
1647
1648
1648
- var temp = new SLIdentifier ( GetUniqueNameForFoo ( "temp" , parms ) ) ;
1649
+ var temp = new SLIdentifier ( GetUniqueNameForFoo ( "temp" , usedNames ) ) ;
1650
+ usedNames . Add ( temp . Name ) ;
1649
1651
var tempDecl = new SLDeclaration ( true , new SLBinding ( temp , new SLTry ( callSite ) ) , Visibility . None ) ;
1650
1652
doBlock . Add ( new SLLine ( tempDecl ) ) ;
1651
1653
doBlock . Add ( SLFunctionCall . FunctionCallLine ( exceptionCall ,
1652
1654
new SLArgument ( new SLIdentifier ( "value" ) , temp , true ) ,
1653
1655
new SLArgument ( new SLIdentifier ( "retval" ) , returnName , true ) ) ) ;
1654
1656
}
1655
- var error = new SLIdentifier ( GetUniqueNameForFoo ( "error" , parms ) ) ;
1657
+ var error = new SLIdentifier ( GetUniqueNameForFoo ( "error" , usedNames ) ) ;
1658
+ usedNames . Add ( error . Name ) ;
1656
1659
var catcher = new SLCatch ( error . Name , null ) ;
1657
1660
catcher . Body . Add ( SLFunctionCall . FunctionCallLine ( "setExceptionThrown" ,
1658
1661
new SLArgument ( new SLIdentifier ( "err" ) , error , true ) ,
@@ -1826,7 +1829,7 @@ SLFunc MapTopLevelFuncToWrapperFunc (SLImportModules modules, FunctionDeclaratio
1826
1829
// To mitigate this, all wrapper functions that return type struct need to have an extra
1827
1830
// parameter which is a reference to a struct.
1828
1831
if ( makeInOut ) {
1829
- returnName = new SLIdentifier ( GetUniqueNameForReturn ( parms ) ) ;
1832
+ returnName = new SLIdentifier ( GetUniqueNameForReturn ( usedNames ) ) ;
1830
1833
usedNames . Add ( returnName . Name ) ;
1831
1834
1832
1835
if ( funcDecl . HasThrows ) {
@@ -1928,14 +1931,16 @@ SLFunc MapTopLevelFuncToWrapperFunc (SLImportModules modules, FunctionDeclaratio
1928
1931
} else {
1929
1932
string exceptionCall = "setExceptionNotThrown" ;
1930
1933
1931
- var temp = new SLIdentifier ( GetUniqueNameForFoo ( "temp" , parms ) ) ;
1934
+ var temp = new SLIdentifier ( GetUniqueNameForFoo ( "temp" , usedNames ) ) ;
1935
+ usedNames . Add ( temp . Name ) ;
1932
1936
var tempDecl = new SLDeclaration ( true , new SLBinding ( temp , new SLTry ( callSite ) ) , Visibility . None ) ;
1933
1937
doBlock . Add ( new SLLine ( tempDecl ) ) ;
1934
1938
doBlock . Add ( SLFunctionCall . FunctionCallLine ( exceptionCall ,
1935
1939
new SLArgument ( new SLIdentifier ( "value" ) , temp , true ) ,
1936
1940
new SLArgument ( new SLIdentifier ( "retval" ) , returnName , true ) ) ) ;
1937
1941
}
1938
- var error = new SLIdentifier ( GetUniqueNameForFoo ( "error" , parms ) ) ;
1942
+ var error = new SLIdentifier ( GetUniqueNameForFoo ( "error" , usedNames ) ) ;
1943
+ usedNames . Add ( error . Name ) ;
1939
1944
var catcher = new SLCatch ( error . Name , null ) ;
1940
1945
catcher . Body . Add ( SLFunctionCall . FunctionCallLine ( "setExceptionThrown" ,
1941
1946
new SLArgument ( new SLIdentifier ( "err" ) , error , true ) ,
@@ -2119,15 +2124,15 @@ DelegatedCommaListElemCollection<SLArgument> BuildArguments (BaseDeclaration con
2119
2124
SLImportModules modules , List < ICodeElement > preMarshalCode )
2120
2125
{
2121
2126
var retval = new DelegatedCommaListElemCollection < SLArgument > ( SLFunctionCall . WriteElement ) ;
2122
- var uniqueNames = new List < SLParameter > ( ) ;
2123
- uniqueNames . AddRange ( parms ) ;
2127
+ var usedNames = new List < string > ( ) ;
2128
+ usedNames . AddRange ( parms . Select ( p => p . PrivateName . Name ) ) ;
2124
2129
retval . AddRange ( parms . Select ( ( nt , i ) => {
2125
2130
bool parmNameIsRequired = original [ i ] . NameIsRequired ;
2126
2131
var originalTypeSpec = original [ i ] . TypeSpec . ReplaceName ( "Self" , substituteForSelf ) ;
2127
2132
if ( originalTypeSpec is ClosureTypeSpec ) {
2128
2133
var ct = ( ClosureTypeSpec ) originalTypeSpec ;
2129
- var closureName = new SLIdentifier ( GetUniqueNameForFoo ( "clos" , uniqueNames ) ) ;
2130
- uniqueNames . Add ( new SLParameter ( closureName , SLSimpleType . Bool ) ) ; // type doesn't matter here
2134
+ var closureName = new SLIdentifier ( GetUniqueNameForFoo ( "clos" , usedNames ) ) ;
2135
+ usedNames . Add ( closureName . Name ) ;
2131
2136
2132
2137
var origArgs = ct . Arguments as TupleTypeSpec ;
2133
2138
var ids = new List < SLNameTypePair > ( ) ;
@@ -2138,8 +2143,8 @@ DelegatedCommaListElemCollection<SLArgument> BuildArguments (BaseDeclaration con
2138
2143
}
2139
2144
var clargTypesAsTuple = ( SLTupleType ) clargTypes ;
2140
2145
for ( int j = 0 ; j < origArgsCount ; j ++ ) {
2141
- SLIdentifier id = new SLIdentifier ( GetUniqueNameForFoo ( "arg" , uniqueNames ) ) ;
2142
- uniqueNames . Add ( new SLParameter ( id , SLSimpleType . Bool ) ) ; // type doesn't matter
2146
+ var id = new SLIdentifier ( GetUniqueNameForFoo ( "arg" , usedNames ) ) ;
2147
+ usedNames . Add ( id . Name ) ;
2143
2148
ids . Add ( new SLNameTypePair ( id , clargTypesAsTuple . Elements [ j ] . TypeAnnotation ) ) ;
2144
2149
}
2145
2150
var clparms = new SLTupleType ( ids ) ;
@@ -2150,13 +2155,13 @@ DelegatedCommaListElemCollection<SLArgument> BuildArguments (BaseDeclaration con
2150
2155
bool hasArgs = ! ct . Arguments . IsEmptyTuple ;
2151
2156
2152
2157
2153
- var funcPtrId = new SLIdentifier ( GetUniqueNameForFoo ( nt . PrivateName . Name + "Ptr" , uniqueNames ) ) ;
2158
+ var funcPtrId = new SLIdentifier ( GetUniqueNameForFoo ( nt . PrivateName . Name + "Ptr" , usedNames ) ) ;
2154
2159
var wrappedClosType = nt . TypeAnnotation as SLFuncType ;
2155
2160
// this strips off the @escaping attribute, if any
2156
2161
var closTypeNoAttr = new SLFuncType ( wrappedClosType . ReturnType , wrappedClosType . Parameters ) ;
2157
2162
2158
2163
SLType funcPtrType = new SLBoundGenericType ( "UnsafeMutablePointer" , closTypeNoAttr ) ;
2159
- uniqueNames . Add ( new SLParameter ( funcPtrId , funcPtrType ) ) ;
2164
+ usedNames . Add ( funcPtrId . Name ) ;
2160
2165
var funcPtrBinding = new SLBinding ( funcPtrId ,
2161
2166
new SLFunctionCall ( $ "{ funcPtrType . ToString ( ) } .allocate",
2162
2167
false ,
@@ -2172,10 +2177,10 @@ DelegatedCommaListElemCollection<SLArgument> BuildArguments (BaseDeclaration con
2172
2177
SLIdentifier retvalId = null ;
2173
2178
2174
2179
if ( hasReturn ) {
2175
- retvalPtrId = new SLIdentifier ( GetUniqueNameForFoo ( "retvalPtr" , uniqueNames ) ) ;
2176
- uniqueNames . Add ( new SLParameter ( retvalPtrId , SLSimpleType . Bool ) ) ;
2177
- retvalId = new SLIdentifier ( GetUniqueNameForFoo ( "retval" , uniqueNames ) ) ;
2178
- uniqueNames . Add ( new SLParameter ( retvalId , SLSimpleType . Bool ) ) ;
2180
+ retvalPtrId = new SLIdentifier ( GetUniqueNameForFoo ( "retvalPtr" , usedNames ) ) ;
2181
+ usedNames . Add ( retvalPtrId . Name ) ;
2182
+ retvalId = new SLIdentifier ( GetUniqueNameForFoo ( "retval" , usedNames ) ) ;
2183
+ usedNames . Add ( retvalId . Name ) ;
2179
2184
var retvalBinding = new SLBinding ( retvalPtrId ,
2180
2185
new SLFunctionCall (
2181
2186
$ "UnsafeMutablePointer<{ clretType . ToString ( ) } >.allocate",
@@ -2184,8 +2189,8 @@ DelegatedCommaListElemCollection<SLArgument> BuildArguments (BaseDeclaration con
2184
2189
SLConstant . Val ( 1 ) , true ) ) ) ;
2185
2190
closureBody . Add ( new SLDeclaration ( true , retvalBinding , Visibility . None ) ) ;
2186
2191
}
2187
- var argsPtrId = new SLIdentifier ( GetUniqueNameForFoo ( "argsPtr" , uniqueNames ) ) ;
2188
- uniqueNames . Add ( new SLParameter ( argsPtrId , SLSimpleType . Bool ) ) ;
2192
+ var argsPtrId = new SLIdentifier ( GetUniqueNameForFoo ( "argsPtr" , usedNames ) ) ;
2193
+ usedNames . Add ( argsPtrId . Name ) ;
2189
2194
if ( hasArgs ) {
2190
2195
var argsBinding = new SLBinding ( argsPtrId ,
2191
2196
new SLFunctionCall (
@@ -2310,25 +2315,19 @@ public static SLBaseExpr BuildVariadicAdapter (SLBaseExpr callSite, FunctionDecl
2310
2315
}
2311
2316
2312
2317
2313
- static string GetUniqueNameForInstance ( List < SLParameter > parms )
2318
+ static string GetUniqueNameForInstance ( List < string > usedNames )
2314
2319
{
2315
- return GetUniqueNameForFoo ( "this" , parms ) ;
2320
+ return GetUniqueNameForFoo ( "this" , usedNames ) ;
2316
2321
}
2317
2322
2318
- static string GetUniqueNameForReturn ( List < SLParameter > parms )
2323
+ static string GetUniqueNameForReturn ( List < string > usedNames )
2319
2324
{
2320
- return GetUniqueNameForFoo ( "retval" , parms ) ;
2325
+ return GetUniqueNameForFoo ( "retval" , usedNames ) ;
2321
2326
}
2322
2327
2323
- static string GetUniqueNameForFoo ( string foo , List < SLParameter > parms )
2328
+ static string GetUniqueNameForFoo ( string foo , List < string > usedNames )
2324
2329
{
2325
- int i = 0 ;
2326
- string s = null ;
2327
- do {
2328
- s = String . Format ( "{0}{1}" , foo , i > 0 ? i . ToString ( ) : "" ) ;
2329
- i ++ ;
2330
- } while ( parms . Exists ( np => s == ( np . PublicName != null ? np . PublicName . Name : "" ) ) ) ;
2331
- return s ;
2330
+ return MarshalEngine . Uniqueify ( foo , usedNames ) ;
2332
2331
}
2333
2332
2334
2333
public static bool IsStructOrEnum ( TypeMapper t , ParameterItem item )
0 commit comments