@@ -51,9 +51,29 @@ final class FunctionDescriptorTests {
51
51
output,
52
52
expected:
53
53
"""
54
- public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
55
- /* i: */SwiftValueLayout.SWIFT_INT
56
- );
54
+ /**
55
+ * {@snippet lang=c :
56
+ * void swiftjava_SwiftModule_globalTakeInt_i(ptrdiff_t i)
57
+ * }
58
+ */
59
+ private static class swiftjava_SwiftModule_globalTakeInt_i {
60
+ public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
61
+ /* i: */SwiftValueLayout.SWIFT_INT
62
+ );
63
+ public static final MemorySegment ADDR =
64
+ SwiftModule.findOrThrow( " swiftjava_SwiftModule_globalTakeInt_i " );
65
+ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
66
+ public static void call(long i) {
67
+ try {
68
+ if (SwiftKit.TRACE_DOWNCALLS) {
69
+ SwiftKit.traceDowncall(i);
70
+ }
71
+ HANDLE.invokeExact(i);
72
+ } catch (Throwable ex$) {
73
+ throw new AssertionError( " should not reach here " , ex$);
74
+ }
75
+ }
76
+ }
57
77
"""
58
78
)
59
79
}
@@ -66,10 +86,30 @@ final class FunctionDescriptorTests {
66
86
output,
67
87
expected:
68
88
"""
69
- public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
70
- /* l: */SwiftValueLayout.SWIFT_INT64,
71
- /* i32: */SwiftValueLayout.SWIFT_INT32
72
- );
89
+ /**
90
+ * {@snippet lang=c :
91
+ * void swiftjava_SwiftModule_globalTakeLongInt_l_i32(int64_t l, int32_t i32)
92
+ * }
93
+ */
94
+ private static class swiftjava_SwiftModule_globalTakeLongInt_l_i32 {
95
+ public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
96
+ /* l: */SwiftValueLayout.SWIFT_INT64,
97
+ /* i32: */SwiftValueLayout.SWIFT_INT32
98
+ );
99
+ public static final MemorySegment ADDR =
100
+ SwiftModule.findOrThrow( " swiftjava_SwiftModule_globalTakeLongInt_l_i32 " );
101
+ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
102
+ public static void call(long l, int i32) {
103
+ try {
104
+ if (SwiftKit.TRACE_DOWNCALLS) {
105
+ SwiftKit.traceDowncall(l, i32);
106
+ }
107
+ HANDLE.invokeExact(l, i32);
108
+ } catch (Throwable ex$) {
109
+ throw new AssertionError( " should not reach here " , ex$);
110
+ }
111
+ }
112
+ }
73
113
"""
74
114
)
75
115
}
@@ -82,10 +122,30 @@ final class FunctionDescriptorTests {
82
122
output,
83
123
expected:
84
124
"""
85
- public static final FunctionDescriptor DESC = FunctionDescriptor.of(
86
- /* -> */SwiftValueLayout.SWIFT_INT,
87
- /* i: */SwiftValueLayout.SWIFT_INT
88
- );
125
+ /**
126
+ * {@snippet lang=c :
127
+ * ptrdiff_t swiftjava_SwiftModule_echoInt_i(ptrdiff_t i)
128
+ * }
129
+ */
130
+ private static class swiftjava_SwiftModule_echoInt_i {
131
+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(
132
+ /* -> */SwiftValueLayout.SWIFT_INT,
133
+ /* i: */SwiftValueLayout.SWIFT_INT
134
+ );
135
+ public static final MemorySegment ADDR =
136
+ SwiftModule.findOrThrow( " swiftjava_SwiftModule_echoInt_i " );
137
+ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
138
+ public static long call(long i) {
139
+ try {
140
+ if (SwiftKit.TRACE_DOWNCALLS) {
141
+ SwiftKit.traceDowncall(i);
142
+ }
143
+ return (long) HANDLE.invokeExact(i);
144
+ } catch (Throwable ex$) {
145
+ throw new AssertionError( " should not reach here " , ex$);
146
+ }
147
+ }
148
+ }
89
149
"""
90
150
)
91
151
}
@@ -98,10 +158,30 @@ final class FunctionDescriptorTests {
98
158
output,
99
159
expected:
100
160
"""
101
- public static final FunctionDescriptor DESC = FunctionDescriptor.of(
102
- /* -> */SwiftValueLayout.SWIFT_INT32,
103
- /* self: */SwiftValueLayout.SWIFT_POINTER
104
- );
161
+ /**
162
+ * {@snippet lang=c :
163
+ * int32_t swiftjava_SwiftModule_MySwiftClass_counter$get(const void *self)
164
+ * }
165
+ */
166
+ private static class swiftjava_SwiftModule_MySwiftClass_counter$get {
167
+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(
168
+ /* -> */SwiftValueLayout.SWIFT_INT32,
169
+ /* self: */SwiftValueLayout.SWIFT_POINTER
170
+ );
171
+ public static final MemorySegment ADDR =
172
+ SwiftModule.findOrThrow( " swiftjava_SwiftModule_MySwiftClass_counter$get " );
173
+ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
174
+ public static int call(java.lang.foreign.MemorySegment self) {
175
+ try {
176
+ if (SwiftKit.TRACE_DOWNCALLS) {
177
+ SwiftKit.traceDowncall(self);
178
+ }
179
+ return (int) HANDLE.invokeExact(self);
180
+ } catch (Throwable ex$) {
181
+ throw new AssertionError( " should not reach here " , ex$);
182
+ }
183
+ }
184
+ }
105
185
"""
106
186
)
107
187
}
@@ -113,10 +193,30 @@ final class FunctionDescriptorTests {
113
193
output,
114
194
expected:
115
195
"""
116
- public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
117
- /* newValue: */SwiftValueLayout.SWIFT_INT32,
118
- /* self: */SwiftValueLayout.SWIFT_POINTER
119
- );
196
+ /**
197
+ * {@snippet lang=c :
198
+ * void swiftjava_SwiftModule_MySwiftClass_counter$set(int32_t newValue, const void *self)
199
+ * }
200
+ */
201
+ private static class swiftjava_SwiftModule_MySwiftClass_counter$set {
202
+ public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(
203
+ /* newValue: */SwiftValueLayout.SWIFT_INT32,
204
+ /* self: */SwiftValueLayout.SWIFT_POINTER
205
+ );
206
+ public static final MemorySegment ADDR =
207
+ SwiftModule.findOrThrow( " swiftjava_SwiftModule_MySwiftClass_counter$set " );
208
+ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
209
+ public static void call(int newValue, java.lang.foreign.MemorySegment self) {
210
+ try {
211
+ if (SwiftKit.TRACE_DOWNCALLS) {
212
+ SwiftKit.traceDowncall(newValue, self);
213
+ }
214
+ HANDLE.invokeExact(newValue, self);
215
+ } catch (Throwable ex$) {
216
+ throw new AssertionError( " should not reach here " , ex$);
217
+ }
218
+ }
219
+ }
120
220
"""
121
221
)
122
222
}
@@ -145,10 +245,8 @@ extension FunctionDescriptorTests {
145
245
$0. name == methodIdentifier
146
246
} !
147
247
148
- let thunkName = st. thunkNameRegistry. functionThunkName ( decl: funcDecl)
149
- let cFunc = funcDecl. cFunctionDecl ( cName: thunkName)
150
248
let output = CodePrinter . toString { printer in
151
- st. printFunctionDescriptorValue ( & printer, cFunc )
249
+ st. printJavaBindingDescriptorClass ( & printer, funcDecl )
152
250
}
153
251
154
252
try body ( output)
@@ -180,10 +278,8 @@ extension FunctionDescriptorTests {
180
278
fatalError ( " Cannot find descriptor of: \( identifier) " )
181
279
}
182
280
183
- let thunkName = st. thunkNameRegistry. functionThunkName ( decl: accessorDecl)
184
- let cFunc = accessorDecl. cFunctionDecl ( cName: thunkName)
185
281
let getOutput = CodePrinter . toString { printer in
186
- st. printFunctionDescriptorValue ( & printer, cFunc )
282
+ st. printJavaBindingDescriptorClass ( & printer, accessorDecl )
187
283
}
188
284
189
285
try body ( getOutput)
0 commit comments