Skip to content

Commit cb4fa3d

Browse files
authored
Merge pull request #210 from DougGregor/cdecl-lowering
Initial implementation of a new lowering from a Swift func to `@_cdecl` func
2 parents 9c96f65 + 4f6f7b5 commit cb4fa3d

17 files changed

+1641
-22
lines changed

Sources/JExtractSwift/JavaConstants/ForeignValueLayouts.swift

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import 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
}

Sources/JExtractSwift/NominalTypeResolution.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public class NominalTypeResolution {
2525

2626
/// Mapping from extension declarations to the type declaration that they
2727
/// extend.
28-
private var resolvedExtensions: [ExtensionDeclSyntax: NominalTypeDeclSyntaxNode] = [:]
28+
var resolvedExtensions: [ExtensionDeclSyntax: NominalTypeDeclSyntaxNode] = [:]
2929

3030
/// Extensions that have been encountered but not yet resolved to
3131
private var unresolvedExtensions: [ExtensionDeclSyntax] = []
3232

3333
/// Mapping from qualified nominal type names to their syntax nodes.
34-
private var topLevelNominalTypes: [String: NominalTypeDeclSyntaxNode] = [:]
34+
var topLevelNominalTypes: [String: NominalTypeDeclSyntaxNode] = [:]
3535

3636
@_spi(Testing) public init() { }
3737
}

0 commit comments

Comments
 (0)