Skip to content

Commit e44364a

Browse files
committed
undo the _ -> $ change, we'll do it separately
1 parent 772a6ae commit e44364a

File tree

6 files changed

+82
-46
lines changed

6 files changed

+82
-46
lines changed

Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ struct CdeclLowering {
208208
return LoweredParameter(
209209
cdeclParameters: [
210210
SwiftParameter(
211-
convention: .byValue, parameterName: "\(parameterName)$pointer",
211+
convention: .byValue, parameterName: "\(parameterName)_pointer",
212212
type: isMutable ? knownTypes.unsafeMutableRawPointer : knownTypes.unsafeRawPointer
213213
),
214214
SwiftParameter(
215-
convention: .byValue, parameterName: "\(parameterName)$count",
215+
convention: .byValue, parameterName: "\(parameterName)_count",
216216
type: knownTypes.int
217217
),
218218
], conversion: .initialize(
@@ -237,11 +237,11 @@ struct CdeclLowering {
237237
cdeclParameters: [
238238
SwiftParameter(
239239
convention: .byValue,
240-
parameterName: "\(parameterName)$pointer",
240+
parameterName: "\(parameterName)_pointer",
241241
type: .optional(isMutable ? knownTypes.unsafeMutableRawPointer : knownTypes.unsafeRawPointer)
242242
),
243243
SwiftParameter(
244-
convention: .byValue, parameterName: "\(parameterName)$count",
244+
convention: .byValue, parameterName: "\(parameterName)_count",
245245
type: knownTypes.int
246246
)
247247
],
@@ -348,26 +348,17 @@ struct CdeclLowering {
348348
case .composite:
349349
throw LoweringError.unhandledType(type)
350350

351-
case .array(.nominal(let nominal)):
351+
case .array(let wrapped) where wrapped == knownTypes.uint8:
352352
// Lower an array as 'address' raw pointer and 'count' integer
353-
var parameters: [SwiftParameter] = [
354-
355-
]
356-
357-
// Create parameter names with consistent naming convention
358-
let pointerParameterName = "\(parameterName)$pointer"
359-
let countParameterName = "\(parameterName)$count"
360-
361-
// Build C declaration parameters for pointer and count
362353
let cdeclParameters = [
363354
SwiftParameter(
364355
convention: .byValue,
365-
parameterName: pointerParameterName,
356+
parameterName: "\(parameterName)_pointer",
366357
type: knownTypes.unsafeRawPointer
367358
),
368359
SwiftParameter(
369360
convention: .byValue,
370-
parameterName: countParameterName,
361+
parameterName: "\(parameterName)_count",
371362
type: knownTypes.int
372363
),
373364
]
@@ -542,12 +533,12 @@ struct CdeclLowering {
542533
cdeclParameters: [
543534
SwiftParameter(
544535
convention: .byValue,
545-
parameterName: "\(parameterName)$pointer",
536+
parameterName: "\(parameterName)_pointer",
546537
type: .optional(isMutable ? knownTypes.unsafeMutableRawPointer : knownTypes.unsafeRawPointer)
547538
),
548539
SwiftParameter(
549540
convention: .byValue,
550-
parameterName: "\(parameterName)$count",
541+
parameterName: "\(parameterName)_count",
551542
type: knownTypes.int
552543
),
553544
],
@@ -632,24 +623,24 @@ struct CdeclLowering {
632623
cdeclOutParameters: [
633624
SwiftParameter(
634625
convention: .byValue,
635-
parameterName: "\(outParameterName)$pointer",
626+
parameterName: "\(outParameterName)_pointer",
636627
type: knownTypes.unsafeMutablePointer(
637628
.optional(isMutable ? knownTypes.unsafeMutableRawPointer : knownTypes.unsafeRawPointer)
638629
)
639630
),
640631
SwiftParameter(
641632
convention: .byValue,
642-
parameterName: "\(outParameterName)$count",
633+
parameterName: "\(outParameterName)_count",
643634
type: knownTypes.unsafeMutablePointer(knownTypes.int)
644635
),
645636
],
646637
conversion: .aggregate([
647638
.populatePointer(
648-
name: "\(outParameterName)$pointer",
639+
name: "\(outParameterName)_pointer",
649640
to: .member(.placeholder, member: "baseAddress")
650641
),
651642
.populatePointer(
652-
name: "\(outParameterName)$count",
643+
name: "\(outParameterName)_count",
653644
to: .member(.placeholder, member: "count")
654645
)
655646
], name: outParameterName)

Sources/JExtractSwiftLib/FFM/ConversionStep.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ enum ConversionStep: Equatable {
9999
return "\(raw: placeholder)"
100100

101101
case .explodedComponent(let step, component: let component):
102-
return step.asExprSyntax(placeholder: "\(placeholder)$\(component)", bodyItems: &bodyItems)
102+
return step.asExprSyntax(placeholder: "\(placeholder)_\(component)", bodyItems: &bodyItems)
103103

104104
case .unsafeCastPointer(let step, swiftType: let swiftType):
105105
let untypedExpr = step.asExprSyntax(placeholder: placeholder, bodyItems: &bodyItems)

Tests/JExtractSwiftTests/ByteArrayTests.swift

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ import SwiftJavaConfigurationShared
1717
import Testing
1818

1919
final class ByteArrayTests {
20-
let text =
21-
"""
22-
public func acceptArray(array: [UInt8])
23-
"""
24-
2520

2621
@Test(
2722
"Import: accept [UInt8] array",
@@ -34,13 +29,13 @@ final class ByteArrayTests {
3429
"""
3530
/**
3631
* {@snippet lang=c :
37-
* void swiftjava_SwiftModule_acceptArray_array(const void *array$pointer, ptrdiff_t array$count)
32+
* void swiftjava_SwiftModule_acceptArray_array(const void *array_pointer, ptrdiff_t array_count)
3833
* }
3934
*/
4035
private static class swiftjava_SwiftModule_acceptArray_array {
4136
private static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
42-
/* array$pointer: */SwiftValueLayout.SWIFT_POINTER,
43-
/* array$count: */SwiftValueLayout.SWIFT_INT
37+
/* array_pointer: */SwiftValueLayout.SWIFT_POINTER,
38+
/* array_count: */SwiftValueLayout.SWIFT_INT
4439
);
4540
""",
4641
"""
@@ -61,15 +56,20 @@ final class ByteArrayTests {
6156
[
6257
"""
6358
@_cdecl("swiftjava_SwiftModule_acceptArray_array")
64-
public func swiftjava_SwiftModule_acceptArray_array(_ array$pointer: UnsafeRawPointer, _ array$count: Int) {
65-
acceptArray(array: [UInt8](UnsafeRawBufferPointer(start: array$pointer, count: array$count)))
59+
public func swiftjava_SwiftModule_acceptArray_array(_ array_pointer: UnsafeRawPointer, _ array_count: Int) {
60+
acceptArray(array: [UInt8](UnsafeRawBufferPointer(start: array_pointer, count: array_count)))
6661
}
6762
"""
6863
]
6964
)
7065
]
7166
)
7267
func func_accept_array_uint8(mode: JExtractGenerationMode, expectedJavaChunks: [String], expectedSwiftChunks: [String]) throws {
68+
let text =
69+
"""
70+
public func acceptArray(array: [UInt8])
71+
"""
72+
7373
try assertOutput(
7474
input: text,
7575
mode, .java,
@@ -79,5 +79,50 @@ final class ByteArrayTests {
7979
input: text,
8080
mode, .swift,
8181
expectedChunks: expectedSwiftChunks)
82-
}
82+
}
83+
84+
// @Test(
85+
// "Import: return [UInt8] array",
86+
// arguments: [
87+
// // TODO: implement JNI mode here
88+
// (
89+
// JExtractGenerationMode.ffm,
90+
// /* expected Java chunks */
91+
// [
92+
// """
93+
// NEIN
94+
// NEIN
95+
// NEIN
96+
// NEIN
97+
// """
98+
// ],
99+
// /* expected Swift chunks */
100+
// [
101+
// """
102+
// NEIN
103+
// NEIN
104+
// NEIN
105+
// NEIN
106+
// NEIN
107+
// """
108+
// ]
109+
// )
110+
// ]
111+
// )
112+
// func func_return_array_uint8(mode: JExtractGenerationMode, expectedJavaChunks: [String], expectedSwiftChunks: [String]) throws {
113+
// let text =
114+
// """
115+
// public func acceptArray() -> [UInt8]
116+
// """
117+
118+
// try assertOutput(
119+
// input: text,
120+
// mode, .java,
121+
// expectedChunks: expectedJavaChunks)
122+
123+
// try assertOutput(
124+
// input: text,
125+
// mode, .swift,
126+
// expectedChunks: expectedSwiftChunks)
127+
// }
83128
}

Tests/JExtractSwiftTests/DataImportTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ final class DataImportTests {
345345
void apply(java.lang.foreign.MemorySegment _0);
346346
}
347347
private static MemorySegment $toUpcallStub(body fi, Arena arena) {
348-
return swiftjava_SwiftModule_Data_withUnsafeBytes__.$body.toUpcallStub((_0$pointer, _0$count) -> {
349-
fi.apply(_0$pointer.reinterpret(_0$count));
348+
return swiftjava_SwiftModule_Data_withUnsafeBytes__.$body.toUpcallStub((_0_pointer, _0_count) -> {
349+
fi.apply(_0_pointer.reinterpret(_0_count));
350350
}, arena);
351351
}
352352
}

Tests/JExtractSwiftTests/FuncCallbackImportTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ final class FuncCallbackImportTests {
318318
long apply(java.lang.foreign.MemorySegment _0);
319319
}
320320
private static MemorySegment $toUpcallStub(body fi, Arena arena) {
321-
return swiftjava___FakeModule_withBuffer_body.$body.toUpcallStub((_0$pointer, _0$count) -> {
322-
return fi.apply(_0$pointer.reinterpret(_0$count));
321+
return swiftjava___FakeModule_withBuffer_body.$body.toUpcallStub((_0_pointer, _0_count) -> {
322+
return fi.apply(_0_pointer.reinterpret(_0_count));
323323
}, arena);
324324
}
325325
}

Tests/JExtractSwiftTests/FunctionLoweringTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ final class FunctionLoweringTests {
2525
""",
2626
expectedCDecl: """
2727
@_cdecl("c_f")
28-
public func c_f(_ x: Int, _ y: Float, _ z$pointer: UnsafeRawPointer, _ z$count: Int) {
29-
f(x: x, y: y, z: UnsafeBufferPointer<Bool>(start: z$pointer.assumingMemoryBound(to: Bool.self), count: z$count))
28+
public func c_f(_ x: Int, _ y: Float, _ z_pointer: UnsafeRawPointer, _ z_count: Int) {
29+
f(x: x, y: y, z: UnsafeBufferPointer<Bool>(start: z_pointer.assumingMemoryBound(to: Bool.self), count: z_count))
3030
}
3131
""",
32-
expectedCFunction: "void c_f(ptrdiff_t x, float y, const void *z$pointer, ptrdiff_t z$count)"
32+
expectedCFunction: "void c_f(ptrdiff_t x, float y, const void *z_pointer, ptrdiff_t z_count)"
3333
)
3434
}
3535

@@ -323,13 +323,13 @@ final class FunctionLoweringTests {
323323
""",
324324
expectedCDecl: """
325325
@_cdecl("c_swapRawBufferPointer")
326-
public func c_swapRawBufferPointer(_ buffer$pointer: UnsafeRawPointer?, _ buffer$count: Int, _ _result$pointer: UnsafeMutablePointer<UnsafeMutableRawPointer?>, _ _result$count: UnsafeMutablePointer<Int>) {
327-
let _result = swapRawBufferPointer(buffer: UnsafeRawBufferPointer(start: buffer$pointer, count: buffer$count))
328-
_result$pointer.initialize(to: _result.baseAddress)
329-
_result$count.initialize(to: _result.count)
326+
public func c_swapRawBufferPointer(_ buffer_pointer: UnsafeRawPointer?, _ buffer_count: Int, _ _result_pointer: UnsafeMutablePointer<UnsafeMutableRawPointer?>, _ _result_count: UnsafeMutablePointer<Int>) {
327+
let _result = swapRawBufferPointer(buffer: UnsafeRawBufferPointer(start: buffer_pointer, count: buffer_count))
328+
_result_pointer.initialize(to: _result.baseAddress)
329+
_result_count.initialize(to: _result.count)
330330
}
331331
""",
332-
expectedCFunction: "void c_swapRawBufferPointer(const void *buffer$pointer, ptrdiff_t buffer$count, void **_result$pointer, ptrdiff_t *_result$count)"
332+
expectedCFunction: "void c_swapRawBufferPointer(const void *buffer_pointer, ptrdiff_t buffer_count, void **_result_pointer, ptrdiff_t *_result_count)"
333333
)
334334
}
335335

0 commit comments

Comments
 (0)