Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of a new lowering from a Swift func to @_cdecl func #210

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading