@@ -44,18 +44,19 @@ public struct ImportedNominalType: ImportedDecl {
44
44
TranslatedType (
45
45
cCompatibleConvention: . direct,
46
46
originalSwiftType: " \( raw: swiftTypeName) " ,
47
+ originalSwiftTypeKind: self . kind,
47
48
cCompatibleSwiftType: " UnsafeRawPointer " ,
48
49
cCompatibleJavaMemoryLayout: . heapObject,
49
50
javaType: javaType
50
51
)
51
52
}
52
-
53
+
53
54
public var isReferenceType : Bool {
54
55
switch self . kind {
55
56
case . class, . actor :
56
- return true
57
- case . enum , . struct :
58
- return false
57
+ true
58
+ default :
59
+ false
59
60
}
60
61
}
61
62
@@ -68,11 +69,40 @@ public struct ImportedNominalType: ImportedDecl {
68
69
}
69
70
}
70
71
72
+ // TODO: replace this with `SwiftNominalTypeDeclaration.Kind`
71
73
public enum NominalTypeKind {
72
74
case `actor`
73
75
case `class`
74
76
case `enum`
75
77
case `struct`
78
+ case `void` // TODO: NOT NOMINAL, BUT...
79
+ case function // TODO: NOT NOMINAL, BUT...
80
+ case primitive // TODO: NOT NOMINAL, BUT...
81
+
82
+ var isReferenceType : Bool {
83
+ switch self {
84
+ case . actor , . class: true
85
+ case . enum, . struct: false
86
+ case . void, . function, . primitive: false
87
+ }
88
+ }
89
+
90
+ var isValueType : Bool {
91
+ switch self {
92
+ case . actor , . class: false
93
+ case . enum, . struct: true
94
+ case . void, . function, . primitive: false
95
+ }
96
+ }
97
+
98
+ var isVoid : Bool {
99
+ switch self {
100
+ case . actor , . class: false
101
+ case . enum, . struct: false
102
+ case . void: true
103
+ case . function, . primitive: false
104
+ }
105
+ }
76
106
}
77
107
78
108
public struct ImportedParam {
@@ -99,7 +129,7 @@ public struct ImportedParam {
99
129
var effectiveName : String ? {
100
130
firstName ?? secondName
101
131
}
102
-
132
+
103
133
var effectiveValueName : String {
104
134
secondName ?? firstName ?? " _ "
105
135
}
@@ -199,13 +229,13 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible {
199
229
case nil , . wrapper:
200
230
break
201
231
202
- case . pointer:
232
+ case . pointer where !isInit :
203
233
let selfParam : FunctionParameterSyntax = " self$: $swift_pointer "
204
234
params. append (
205
235
ImportedParam ( syntax: selfParam, type: parent)
206
236
)
207
237
208
- case . memorySegment:
238
+ case . memorySegment where !isInit :
209
239
let selfParam : FunctionParameterSyntax = " self$: $java_lang_foreign_MemorySegment "
210
240
var parentForSelf = parent
211
241
parentForSelf. javaType = . javaForeignMemorySegment
@@ -215,6 +245,9 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible {
215
245
216
246
case . swiftThunkSelf:
217
247
break
248
+
249
+ default :
250
+ break
218
251
}
219
252
220
253
// TODO: add any metadata for generics and other things we may need to add here
@@ -233,6 +266,11 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible {
233
266
234
267
public var isInit : Bool = false
235
268
269
+ public var isIndirectReturn : Bool {
270
+ returnType. isValueType ||
271
+ ( isInit && ( parent? . isValueType ?? false ) )
272
+ }
273
+
236
274
public init (
237
275
module: String ,
238
276
decl: any DeclSyntaxProtocol ,
@@ -269,9 +307,9 @@ extension ImportedFunc: Hashable {
269
307
self . swiftDecl. id. hash ( into: & hasher)
270
308
}
271
309
272
- public static func == ( lhs: ImportedFunc , rhs: ImportedFunc ) -> Swift . Bool {
273
- lhs. parent? . originalSwiftType. id == rhs. parent? . originalSwiftType. id &&
274
- lhs. swiftDecl. id == rhs. swiftDecl. id
310
+ public static func == ( lhs: ImportedFunc , rhs: ImportedFunc ) -> Swift . Bool {
311
+ lhs. parent? . originalSwiftType. id == rhs. parent? . originalSwiftType. id
312
+ && lhs. swiftDecl. id == rhs. swiftDecl. id
275
313
}
276
314
}
277
315
@@ -394,8 +432,8 @@ public struct ImportedVariable: ImportedDecl, CustomStringConvertible {
394
432
)
395
433
396
434
case nil ,
397
- . wrapper,
398
- . swiftThunkSelf:
435
+ . wrapper,
436
+ . swiftThunkSelf:
399
437
break
400
438
}
401
439
}
0 commit comments