Skip to content

Commit

Permalink
Merge pull request #210 from DougGregor/cdecl-lowering
Browse files Browse the repository at this point in the history
Initial implementation of a new lowering from a Swift func to `@_cdecl` func
  • Loading branch information
DougGregor authored Jan 23, 2025
2 parents 9c96f65 + 4f6f7b5 commit cb4fa3d
Show file tree
Hide file tree
Showing 17 changed files with 1,641 additions and 22 deletions.
22 changes: 21 additions & 1 deletion Sources/JExtractSwift/JavaConstants/ForeignValueLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
//===----------------------------------------------------------------------===//

import Foundation
import JavaTypes

/// Represents a value of a `java.lang.foreign.Self` that we want to render in generated Java code.
///
/// This type may gain further methods for adjusting target layout, byte order, names etc.
public struct ForeignValueLayout: CustomStringConvertible {
public struct ForeignValueLayout: CustomStringConvertible, Equatable {
var inlineComment: String?
var value: String

Expand All @@ -35,6 +36,20 @@ public struct ForeignValueLayout: CustomStringConvertible {
self.needsMemoryLayoutCall = true
}

public init?(javaType: JavaType) {
switch javaType {
case .boolean: self = .SwiftBool
case .byte: self = .SwiftInt8
case .char: self = .SwiftUInt16
case .short: self = .SwiftInt16
case .int: self = .SwiftInt32
case .long: self = .SwiftInt64
case .float: self = .SwiftFloat
case .double: self = .SwiftDouble
case .array, .class, .void: return nil
}
}

public var description: String {
var result = ""

Expand Down Expand Up @@ -68,4 +83,9 @@ extension ForeignValueLayout {

public static let SwiftFloat = Self(javaConstant: "SWIFT_FLOAT")
public static let SwiftDouble = Self(javaConstant: "SWIFT_DOUBLE")

var isPrimitive: Bool {
// FIXME: This is a hack, we need an enum to better describe this!
value != "SWIFT_POINTER"
}
}
4 changes: 2 additions & 2 deletions Sources/JExtractSwift/NominalTypeResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class NominalTypeResolution {

/// Mapping from extension declarations to the type declaration that they
/// extend.
private var resolvedExtensions: [ExtensionDeclSyntax: NominalTypeDeclSyntaxNode] = [:]
var resolvedExtensions: [ExtensionDeclSyntax: NominalTypeDeclSyntaxNode] = [:]

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

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

@_spi(Testing) public init() { }
}
Expand Down
Loading

0 comments on commit cb4fa3d

Please sign in to comment.