Skip to content

Commit 99e9ba1

Browse files
committed
Make ImportedFunc's "identifier" always a full name like f(a:b:).
This makes function names consistent with initializer names. Switch a number of callers over to baseIdentifier when they only want to deal with the base name.
1 parent 90baedc commit 99e9ba1

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

Sources/JExtractSwift/Swift2JavaTranslator+Printing.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ extension Swift2JavaTranslator {
441441
public func printDowncallMethods(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
442442
printer.printSeparator(decl.identifier)
443443

444-
printer.printTypeDecl("private static class \(decl.identifier)") { printer in
444+
printer.printTypeDecl("private static class \(decl.baseIdentifier)") { printer in
445445
printFunctionDescriptorValue(&printer, decl);
446446
printFindMemorySegmentAddrByMangledName(&printer, decl)
447447
printMethodDowncallHandleForAddrDesc(&printer)
@@ -455,8 +455,8 @@ extension Swift2JavaTranslator {
455455
* \(/*TODO: make a printSnippet func*/decl.swiftDeclRaw ?? "")
456456
* }
457457
*/
458-
public static FunctionDescriptor \(decl.identifier)$descriptor() {
459-
return \(decl.identifier).DESC;
458+
public static FunctionDescriptor \(decl.baseIdentifier)$descriptor() {
459+
return \(decl.baseIdentifier).DESC;
460460
}
461461
"""
462462
)
@@ -469,8 +469,8 @@ extension Swift2JavaTranslator {
469469
* \(/*TODO: make a printSnippet func*/decl.swiftDeclRaw ?? "")
470470
* }
471471
*/
472-
public static MethodHandle \(decl.identifier)$handle() {
473-
return \(decl.identifier).HANDLE;
472+
public static MethodHandle \(decl.baseIdentifier)$handle() {
473+
return \(decl.baseIdentifier).HANDLE;
474474
}
475475
"""
476476
)
@@ -483,8 +483,8 @@ extension Swift2JavaTranslator {
483483
* \(/*TODO: make a printSnippet func*/decl.swiftDeclRaw ?? "")
484484
* }
485485
*/
486-
public static MemorySegment \(decl.identifier)$address() {
487-
return \(decl.identifier).ADDR;
486+
public static MemorySegment \(decl.baseIdentifier)$address() {
487+
return \(decl.baseIdentifier).ADDR;
488488
}
489489
"""
490490
)
@@ -542,8 +542,8 @@ extension Swift2JavaTranslator {
542542
* \(/*TODO: make a printSnippet func*/decl.swiftDeclRaw ?? "")
543543
* }
544544
*/
545-
public static \(returnTy) \(decl.identifier)(\(renderJavaParamDecls(decl, selfVariant: .wrapper))) {
546-
\(maybeReturnCast) \(decl.identifier)(\(renderForwardParams(decl, selfVariant: .memorySegment)));
545+
public static \(returnTy) \(decl.baseIdentifier)(\(renderJavaParamDecls(decl, selfVariant: .wrapper))) {
546+
\(maybeReturnCast) \(decl.baseIdentifier)(\(renderForwardParams(decl, selfVariant: .memorySegment)));
547547
}
548548
"""
549549
)
@@ -557,8 +557,8 @@ extension Swift2JavaTranslator {
557557
* \(/*TODO: make a printSnippet func*/decl.swiftDeclRaw ?? "")
558558
* }
559559
*/
560-
public static \(returnTy) \(decl.identifier)(\(renderJavaParamDecls(decl, selfVariant: selfVariant))) {
561-
var mh$ = \(decl.identifier).HANDLE;
560+
public static \(returnTy) \(decl.baseIdentifier)(\(renderJavaParamDecls(decl, selfVariant: selfVariant))) {
561+
var mh$ = \(decl.baseIdentifier).HANDLE;
562562
try {
563563
if (TRACE_DOWNCALLS) {
564564
traceDowncall(\(renderForwardParams(decl, selfVariant: .memorySegment)));

Sources/JExtractSwift/Swift2JavaVisitor.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,18 @@ final class Swift2JavaVisitor: SyntaxVisitor {
103103
return .skipChildren
104104
}
105105

106+
let argumentLabels = node.signature.parameterClause.parameters.map { param in
107+
param.firstName.identifier?.name ?? "_"
108+
}
109+
let argumentLabelsStr = String(argumentLabels.flatMap { label in
110+
label + ":"
111+
})
112+
113+
let fullName = "\(node.name.text)(\(argumentLabelsStr))"
114+
106115
var funcDecl = ImportedFunc(
107116
parentName: currentTypeDecl?.name,
108-
identifier: node.name.text,
117+
identifier: fullName,
109118
returnType: javaResultType,
110119
parameters: params
111120
)
@@ -156,7 +165,7 @@ final class Swift2JavaVisitor: SyntaxVisitor {
156165

157166
var funcDecl = ImportedFunc(
158167
parentName: currentTypeDecl.name,
159-
identifier: initIdentifier, // FIXME: what is the name of the inits?
168+
identifier: initIdentifier,
160169
returnType: currentTypeDecl.name,
161170
parameters: params
162171
)

Sources/JExtractSwift/SwiftDylib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ package struct SwiftDylib { // FIXME: remove this entire utility; replace with
5959
}
6060

6161
var decl = decl
62-
let names = try await nmSymbolNames(grepDemangled: [decl.identifier])
62+
let names = try await nmSymbolNames(grepDemangled: [decl.baseIdentifier])
6363
if let name = names.first {
6464
log.trace("Selected mangled name for '\(decl.identifier)': \(name)")
6565
decl.swiftMangledName = name.mangledName

Tests/JExtractSwiftTests/FuncImportTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class MethodImportTests: XCTestCase {
6060

6161
try await st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile)
6262

63-
let funcDecl = st.importedGlobalFuncs.first { $0.identifier == "helloWorld" }!
63+
let funcDecl = st.importedGlobalFuncs.first { $0.baseIdentifier == "helloWorld" }!
6464

6565
let output = CodePrinter.toString { printer in
6666
st.printFuncDowncallMethod(&printer, decl: funcDecl, selfVariant: nil)
@@ -100,7 +100,7 @@ final class MethodImportTests: XCTestCase {
100100
try await st.analyze(swiftInterfacePath: "/fake/__FakeModule/SwiftFile.swiftinterface", text: class_interfaceFile)
101101

102102
let funcDecl = st.importedGlobalFuncs.first {
103-
$0.identifier == "globalTakeInt"
103+
$0.baseIdentifier == "globalTakeInt"
104104
}!
105105

106106
let output = CodePrinter.toString { printer in
@@ -141,7 +141,7 @@ final class MethodImportTests: XCTestCase {
141141
try await st.analyze(swiftInterfacePath: "/fake/__FakeModule/SwiftFile.swiftinterface", text: class_interfaceFile)
142142

143143
let funcDecl = st.importedGlobalFuncs.first {
144-
$0.identifier == "globalTakeIntLongString"
144+
$0.baseIdentifier == "globalTakeIntLongString"
145145
}!
146146

147147
let output = CodePrinter.toString { printer in
@@ -184,7 +184,7 @@ final class MethodImportTests: XCTestCase {
184184
let funcDecl: ImportedFunc = st.importedTypes.first {
185185
$0.name.javaClassName == "MySwiftClass"
186186
}!.methods.first {
187-
$0.identifier == "helloMemberFunction"
187+
$0.baseIdentifier == "helloMemberFunction"
188188
}!
189189

190190
let output = CodePrinter.toString { printer in
@@ -227,7 +227,7 @@ final class MethodImportTests: XCTestCase {
227227
let funcDecl: ImportedFunc = st.importedTypes.first {
228228
$0.name.javaClassName == "MySwiftClass"
229229
}!.methods.first {
230-
$0.identifier == "helloMemberFunction"
230+
$0.baseIdentifier == "helloMemberFunction"
231231
}!
232232

233233
let output = CodePrinter.toString { printer in
@@ -270,7 +270,7 @@ final class MethodImportTests: XCTestCase {
270270
let funcDecl: ImportedFunc = st.importedTypes.first {
271271
$0.name.javaClassName == "MySwiftClass"
272272
}!.methods.first {
273-
$0.identifier == "helloMemberFunction"
273+
$0.baseIdentifier == "helloMemberFunction"
274274
}!
275275

276276
let output = CodePrinter.toString { printer in
@@ -305,7 +305,7 @@ final class MethodImportTests: XCTestCase {
305305
let funcDecl: ImportedFunc = st.importedTypes.first {
306306
$0.name.javaClassName == "MySwiftClass"
307307
}!.methods.first {
308-
$0.identifier == "makeInt"
308+
$0.baseIdentifier == "makeInt"
309309
}!
310310

311311
let output = CodePrinter.toString { printer in

Tests/JExtractSwiftTests/FunctionDescriptorImportTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class FunctionDescriptorTests: XCTestCase {
6363
try await st.analyze(swiftInterfacePath: "/fake/Sample.swiftinterface", text: interfaceFile)
6464

6565
let funcDecl = st.importedGlobalFuncs.first {
66-
$0.identifier == methodIdentifier
66+
$0.baseIdentifier == methodIdentifier
6767
}!
6868

6969
let output = CodePrinter.toString { printer in

0 commit comments

Comments
 (0)