1313//===----------------------------------------------------------------------===//
1414
1515import Foundation
16+ import JavaTypes
1617
1718/// Represents a value of a `java.lang.foreign.Self` that we want to render in generated Java code.
1819///
1920/// 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 {
2122 var inlineComment : String ?
2223 var value : String
2324
@@ -35,6 +36,20 @@ public struct ForeignValueLayout: CustomStringConvertible {
3536 self . needsMemoryLayoutCall = true
3637 }
3738
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+
3853 public var description : String {
3954 var result = " "
4055
@@ -68,4 +83,9 @@ extension ForeignValueLayout {
6883
6984 public static let SwiftFloat = Self ( javaConstant: " SWIFT_FLOAT " )
7085 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+ }
7191}
0 commit comments