@@ -51,9 +51,29 @@ final class FunctionDescriptorTests {
5151 output,
5252 expected:
5353 """
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+ }
5777 """
5878 )
5979 }
@@ -66,10 +86,30 @@ final class FunctionDescriptorTests {
6686 output,
6787 expected:
6888 """
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+ }
73113 """
74114 )
75115 }
@@ -82,10 +122,30 @@ final class FunctionDescriptorTests {
82122 output,
83123 expected:
84124 """
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+ }
89149 """
90150 )
91151 }
@@ -98,10 +158,30 @@ final class FunctionDescriptorTests {
98158 output,
99159 expected:
100160 """
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+ }
105185 """
106186 )
107187 }
@@ -113,10 +193,30 @@ final class FunctionDescriptorTests {
113193 output,
114194 expected:
115195 """
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+ }
120220 """
121221 )
122222 }
@@ -145,10 +245,8 @@ extension FunctionDescriptorTests {
145245 $0. name == methodIdentifier
146246 } !
147247
148- let thunkName = st. thunkNameRegistry. functionThunkName ( decl: funcDecl)
149- let cFunc = funcDecl. cFunctionDecl ( cName: thunkName)
150248 let output = CodePrinter . toString { printer in
151- st. printFunctionDescriptorValue ( & printer, cFunc )
249+ st. printJavaBindingDescriptorClass ( & printer, funcDecl )
152250 }
153251
154252 try body ( output)
@@ -180,10 +278,8 @@ extension FunctionDescriptorTests {
180278 fatalError ( " Cannot find descriptor of: \( identifier) " )
181279 }
182280
183- let thunkName = st. thunkNameRegistry. functionThunkName ( decl: accessorDecl)
184- let cFunc = accessorDecl. cFunctionDecl ( cName: thunkName)
185281 let getOutput = CodePrinter . toString { printer in
186- st. printFunctionDescriptorValue ( & printer, cFunc )
282+ st. printJavaBindingDescriptorClass ( & printer, accessorDecl )
187283 }
188284
189285 try body ( getOutput)
0 commit comments