@@ -45,11 +45,19 @@ protocol ParamInfo: CustomStringConvertible {
45
45
) -> BoundsCheckedThunkBuilder
46
46
}
47
47
48
+ func getParamName( _ param: FunctionParameterSyntax , _ paramIndex: Int ) -> TokenSyntax {
49
+ let name = param. secondName ?? param. firstName
50
+ if name. trimmed. text == " _ " {
51
+ return " _param \( raw: paramIndex) "
52
+ }
53
+ return name
54
+ }
55
+
48
56
func tryGetParamName( _ funcDecl: FunctionDeclSyntax , _ expr: SwiftifyExpr ) -> TokenSyntax ? {
49
57
switch expr {
50
58
case . param( let i) :
51
59
let funcParam = getParam ( funcDecl, i - 1 )
52
- return funcParam. secondName ?? funcParam . firstName
60
+ return getParamName ( funcParam, i - 1 )
53
61
case . `self`:
54
62
return . keyword( . self )
55
63
default : return nil
@@ -419,7 +427,12 @@ struct FunctionCallBuilder: BoundsCheckedThunkBuilder {
419
427
// filter out deleted parameters, i.e. ones where argTypes[i] _contains_ nil
420
428
return type == nil || type! != nil
421
429
} . map { ( i: Int , e: FunctionParameterSyntax ) in
422
- e. with ( \. type, ( argTypes [ i] ?? e. type) !)
430
+ let param = e. with ( \. type, ( argTypes [ i] ?? e. type) !)
431
+ let name = param. secondName ?? param. firstName
432
+ if name. trimmed. text == " _ " {
433
+ return param. with ( \. secondName, getParamName ( param, i) )
434
+ }
435
+ return param
423
436
}
424
437
if let last = newParams. popLast ( ) {
425
438
newParams. append ( last. with ( \. trailingComma, nil ) )
@@ -437,7 +450,7 @@ struct FunctionCallBuilder: BoundsCheckedThunkBuilder {
437
450
let functionRef = DeclReferenceExprSyntax ( baseName: base. name)
438
451
let args : [ ExprSyntax ] = base. signature. parameterClause. parameters. enumerated ( )
439
452
. map { ( i: Int , param: FunctionParameterSyntax ) in
440
- let name = param. secondName ?? param . firstName
453
+ let name = getParamName ( param, i )
441
454
let declref = DeclReferenceExprSyntax ( baseName: name)
442
455
return pointerArgs [ i] ?? ExprSyntax ( declref)
443
456
}
@@ -647,7 +660,7 @@ extension ParamBoundsThunkBuilder {
647
660
}
648
661
649
662
var name : TokenSyntax {
650
- return param. secondName ?? param . firstName
663
+ getParamName ( param, index )
651
664
}
652
665
}
653
666
@@ -828,8 +841,7 @@ struct CountedOrSizedPointerThunkBuilder: ParamBoundsThunkBuilder, PointerBounds
828
841
}
829
842
830
843
func castPointerToOpaquePointer( _ baseAddress: ExprSyntax ) throws -> ExprSyntax {
831
- let i = try getParameterIndexForParamName ( signature. parameterClause. parameters, name)
832
- let type = peelOptionalType ( getParam ( signature, i) . type)
844
+ let type = peelOptionalType ( getParam ( signature, index) . type)
833
845
if type. canRepresentBasicType ( type: OpaquePointer . self) {
834
846
return ExprSyntax ( " OpaquePointer( \( baseAddress) ) " )
835
847
}
0 commit comments