13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import Foundation
16
+ import JavaTypes
16
17
17
18
/// Represents a value of a `java.lang.foreign.Self` that we want to render in generated Java code.
18
19
///
19
20
/// This type may gain further methods for adjusting target layout, byte order, names etc.
20
- public struct ForeignValueLayout : CustomStringConvertible {
21
+ public struct ForeignValueLayout : CustomStringConvertible , Equatable {
21
22
var inlineComment : String ?
22
23
var value : String
23
24
@@ -35,6 +36,20 @@ public struct ForeignValueLayout: CustomStringConvertible {
35
36
self . needsMemoryLayoutCall = true
36
37
}
37
38
39
+ public init ? ( javaType: JavaType ) {
40
+ switch javaType {
41
+ case . boolean: self = . SwiftBool
42
+ case . byte: self = . SwiftInt8
43
+ case . char: self = . SwiftUInt16
44
+ case . short: self = . SwiftInt16
45
+ case . int: self = . SwiftInt32
46
+ case . long: self = . SwiftInt64
47
+ case . float: self = . SwiftFloat
48
+ case . double: self = . SwiftDouble
49
+ case . array, . class, . void: return nil
50
+ }
51
+ }
52
+
38
53
public var description : String {
39
54
var result = " "
40
55
@@ -68,4 +83,9 @@ extension ForeignValueLayout {
68
83
69
84
public static let SwiftFloat = Self ( javaConstant: " SWIFT_FLOAT " )
70
85
public static let SwiftDouble = Self ( javaConstant: " SWIFT_DOUBLE " )
86
+
87
+ var isPrimitive : Bool {
88
+ // FIXME: This is a hack, we need an enum to better describe this!
89
+ value != " SWIFT_POINTER "
90
+ }
71
91
}
0 commit comments