|
1 |
| -//===----------------------------------------------------------------------===// |
2 |
| -// |
3 |
| -// This source file is part of the Swift.org open source project |
4 |
| -// |
5 |
| -// Copyright (c) 2024 Apple Inc. and the Swift.org project authors |
6 |
| -// Licensed under Apache License v2.0 |
7 |
| -// |
8 |
| -// See LICENSE.txt for license information |
9 |
| -// See CONTRIBUTORS.txt for the list of Swift.org project authors |
10 |
| -// |
11 |
| -// SPDX-License-Identifier: Apache-2.0 |
12 |
| -// |
13 |
| -//===----------------------------------------------------------------------===// |
14 |
| - |
15 |
| -// This is a "plain Swift" file containing various types of declarations, |
16 |
| -// that is exported to Java by using the `jextract-swift` tool. |
17 |
| -// |
18 |
| -// No annotations are necessary on the Swift side to perform the export. |
19 |
| - |
20 |
| -#if os(Linux) |
21 |
| -import Glibc |
22 |
| -#elseif os(Windows) |
23 |
| -import CRT |
24 |
| -#elseif canImport(Darwin) |
25 |
| -import Darwin.C |
26 |
| -#endif |
27 |
| - |
28 |
| -public func helloWorld() { |
29 |
| - p("\(#function)") |
30 |
| -} |
31 |
| - |
32 |
| -public func globalTakeInt(i: Int) { |
33 |
| - p("i:\(i)") |
34 |
| -} |
35 |
| - |
36 |
| -public func globalTakeIntInt(i: Int, j: Int) { |
37 |
| - p("i:\(i), j:\(j)") |
38 |
| -} |
39 |
| - |
40 |
| -public func globalCallMeRunnable(run: () -> ()) { |
41 |
| - run() |
42 |
| -} |
43 |
| - |
44 |
| -public class MySwiftClass { |
45 |
| - |
46 |
| - public var len: Int |
47 |
| - public var cap: Int |
48 |
| - |
49 |
| - public init(len: Int, cap: Int) { |
50 |
| - self.len = len |
51 |
| - self.cap = cap |
52 |
| - |
53 |
| - p("\(MySwiftClass.self).len = \(self.len)") |
54 |
| - p("\(MySwiftClass.self).cap = \(self.cap)") |
55 |
| - let addr = unsafeBitCast(self, to: UInt64.self) |
56 |
| - p("initializer done, self = 0x\(String(addr, radix: 16, uppercase: true))") |
57 |
| - } |
58 |
| - |
59 |
| - deinit { |
60 |
| - let addr = unsafeBitCast(self, to: UInt64.self) |
61 |
| - p("Deinit, self = 0x\(String(addr, radix: 16, uppercase: true))") |
62 |
| - } |
63 |
| - |
64 |
| - public var counter: Int32 = 0 |
65 |
| - |
66 |
| - public func voidMethod() { |
67 |
| - p("") |
68 |
| - } |
69 |
| - |
70 |
| - public func takeIntMethod(i: Int) { |
71 |
| - p("i:\(i)") |
72 |
| - } |
73 |
| - |
74 |
| - public func echoIntMethod(i: Int) -> Int { |
75 |
| - p("i:\(i)") |
76 |
| - return i |
77 |
| - } |
78 |
| - |
79 |
| - public func makeIntMethod() -> Int { |
80 |
| - p("make int -> 12") |
81 |
| - return 12 |
82 |
| - } |
83 |
| - |
84 |
| - public func makeRandomIntMethod() -> Int { |
85 |
| - return Int.random(in: 1..<256) |
86 |
| - } |
87 |
| -} |
88 |
| - |
89 |
| -@_silgen_name("swift_getTypeByMangledNameInEnvironment") |
90 |
| -public func _getTypeByMangledNameInEnvironment( |
91 |
| - _ name: UnsafePointer<UInt8>, |
92 |
| - _ nameLength: UInt, |
93 |
| - genericEnvironment: UnsafeRawPointer?, |
94 |
| - genericArguments: UnsafeRawPointer?) |
95 |
| - -> Any.Type? |
96 |
| - |
97 |
| - |
98 |
| -// ==== Internal helpers |
99 |
| - |
100 |
| -private func p(_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function) { |
101 |
| - print("[swift][\(file):\(line)](\(function)) \(msg)") |
102 |
| - fflush(stdout) |
103 |
| -} |
104 |
| - |
105 |
| -#if os(Linux) |
106 |
| -// FIXME: why do we need this workaround? |
107 |
| -@_silgen_name("_objc_autoreleaseReturnValue") |
108 |
| -public func _objc_autoreleaseReturnValue(a: Any) {} |
109 |
| - |
110 |
| -@_silgen_name("objc_autoreleaseReturnValue") |
111 |
| -public func objc_autoreleaseReturnValue(a: Any) {} |
112 |
| -#endif |
| 1 | +////===----------------------------------------------------------------------===// |
| 2 | +//// |
| 3 | +//// This source file is part of the Swift.org open source project |
| 4 | +//// |
| 5 | +//// Copyright (c) 2024 Apple Inc. and the Swift.org project authors |
| 6 | +//// Licensed under Apache License v2.0 |
| 7 | +//// |
| 8 | +//// See LICENSE.txt for license information |
| 9 | +//// See CONTRIBUTORS.txt for the list of Swift.org project authors |
| 10 | +//// |
| 11 | +//// SPDX-License-Identifier: Apache-2.0 |
| 12 | +//// |
| 13 | +////===----------------------------------------------------------------------===// |
| 14 | +// |
| 15 | +//// This is a "plain Swift" file containing various types of declarations, |
| 16 | +//// that is exported to Java by using the `jextract-swift` tool. |
| 17 | +//// |
| 18 | +//// No annotations are necessary on the Swift side to perform the export. |
| 19 | +// |
| 20 | +//#if os(Linux) |
| 21 | +//import Glibc |
| 22 | +//#elseif os(Windows) |
| 23 | +//import CRT |
| 24 | +//#elseif canImport(Darwin) |
| 25 | +//import Darwin.C |
| 26 | +//#endif |
| 27 | +// |
| 28 | +//public func helloWorld() { |
| 29 | +// p("\(#function)") |
| 30 | +//} |
| 31 | +// |
| 32 | +//public func globalTakeInt(i: Int) { |
| 33 | +// p("i:\(i)") |
| 34 | +//} |
| 35 | +// |
| 36 | +//public func globalTakeIntInt(i: Int, j: Int) { |
| 37 | +// p("i:\(i), j:\(j)") |
| 38 | +//} |
| 39 | +// |
| 40 | +//public func globalCallMeRunnable(run: () -> ()) { |
| 41 | +// run() |
| 42 | +//} |
| 43 | +// |
| 44 | +//public class MySwiftClass { |
| 45 | +// |
| 46 | +// public var len: Int |
| 47 | +// public var cap: Int |
| 48 | +// |
| 49 | +// public init(len: Int, cap: Int) { |
| 50 | +// self.len = len |
| 51 | +// self.cap = cap |
| 52 | +// |
| 53 | +// p("\(MySwiftClass.self).len = \(self.len)") |
| 54 | +// p("\(MySwiftClass.self).cap = \(self.cap)") |
| 55 | +// let addr = unsafeBitCast(self, to: UInt64.self) |
| 56 | +// p("initializer done, self = 0x\(String(addr, radix: 16, uppercase: true))") |
| 57 | +// } |
| 58 | +// |
| 59 | +// deinit { |
| 60 | +// let addr = unsafeBitCast(self, to: UInt64.self) |
| 61 | +// p("Deinit, self = 0x\(String(addr, radix: 16, uppercase: true))") |
| 62 | +// } |
| 63 | +// |
| 64 | +// public var counter: Int32 = 0 |
| 65 | +// |
| 66 | +// public func voidMethod() { |
| 67 | +// p("") |
| 68 | +// } |
| 69 | +// |
| 70 | +// public func takeIntMethod(i: Int) { |
| 71 | +// p("i:\(i)") |
| 72 | +// } |
| 73 | +// |
| 74 | +// public func echoIntMethod(i: Int) -> Int { |
| 75 | +// p("i:\(i)") |
| 76 | +// return i |
| 77 | +// } |
| 78 | +// |
| 79 | +// public func makeIntMethod() -> Int { |
| 80 | +// p("make int -> 12") |
| 81 | +// return 12 |
| 82 | +// } |
| 83 | +// |
| 84 | +// public func makeRandomIntMethod() -> Int { |
| 85 | +// return Int.random(in: 1..<256) |
| 86 | +// } |
| 87 | +//} |
| 88 | +// |
| 89 | +//@_silgen_name("swift_getTypeByMangledNameInEnvironment") |
| 90 | +//public func _getTypeByMangledNameInEnvironment( |
| 91 | +// _ name: UnsafePointer<UInt8>, |
| 92 | +// _ nameLength: UInt, |
| 93 | +// genericEnvironment: UnsafeRawPointer?, |
| 94 | +// genericArguments: UnsafeRawPointer?) |
| 95 | +// -> Any.Type? |
| 96 | +// |
| 97 | +// |
| 98 | +//// ==== Internal helpers |
| 99 | +// |
| 100 | +//private func p(_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function) { |
| 101 | +// print("[swift][\(file):\(line)](\(function)) \(msg)") |
| 102 | +// fflush(stdout) |
| 103 | +//} |
| 104 | +// |
| 105 | +//#if os(Linux) |
| 106 | +//// FIXME: why do we need this workaround? |
| 107 | +//@_silgen_name("_objc_autoreleaseReturnValue") |
| 108 | +//public func _objc_autoreleaseReturnValue(a: Any) {} |
| 109 | +// |
| 110 | +//@_silgen_name("objc_autoreleaseReturnValue") |
| 111 | +//public func objc_autoreleaseReturnValue(a: Any) {} |
| 112 | +//#endif |
0 commit comments