Skip to content
Merged
8 changes: 5 additions & 3 deletions Sources/JExtractSwiftLib/Common/TypeAnnotations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import SwiftJavaJNICore
/// Determine if the given type needs any extra annotations that should be included
/// in Java sources when the corresponding Java type is rendered.
func getTypeAnnotations(swiftType: SwiftType, config: Configuration) -> [JavaAnnotation] {
switch swiftType {
case .array(let wrapped) where wrapped.isUnsignedInteger:
if swiftType.isUnsignedInteger {
return [JavaAnnotation.unsigned]
case _ where swiftType.isUnsignedInteger:
}

switch swiftType.asNominalType?.asKnownType {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKey yeah I think this is a nice improvement

case .array(let element) where element.isUnsignedInteger:
return [JavaAnnotation.unsigned]
default:
return []
Expand Down
23 changes: 11 additions & 12 deletions Sources/JExtractSwiftLib/FFM/CDeclLowering/CRepresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ extension CType {
init(cdeclType: SwiftType) throws {
switch cdeclType {
case .nominal(let nominalType):
if let knownType = nominalType.nominalTypeDecl.knownTypeKind {
if let primitiveCType = knownType.primitiveCType {
if let knownType = nominalType.asKnownType {
if let primitiveCType = knownType.kind.primitiveCType {
self = primitiveCType
return
}

switch knownType {
case .unsafePointer where nominalType.genericArguments?.count == 1:
case .optional(let wrapped) where wrapped.isPointer:
try self.init(cdeclType: wrapped)
return

case .unsafePointer(let pointee):
self = .pointer(
.qualified(const: true, volatile: false, type: try CType(cdeclType: nominalType.genericArguments![0]))
.qualified(const: true, volatile: false, type: try CType(cdeclType: pointee))
)
return
case .unsafeMutablePointer where nominalType.genericArguments?.count == 1:
self = .pointer(try CType(cdeclType: nominalType.genericArguments![0]))
case .unsafeMutablePointer(let pointee):
self = .pointer(try CType(cdeclType: pointee))
return
default:
break
Expand Down Expand Up @@ -67,10 +71,7 @@ extension CType {
case .tuple([]):
self = .void

case .optional(let wrapped) where wrapped.isPointer:
try self.init(cdeclType: wrapped)

case .genericParameter, .metatype, .optional, .tuple, .opaque, .existential, .composite, .array, .dictionary, .set:
case .genericParameter, .metatype, .tuple, .opaque, .existential, .composite:
throw CDeclToCLoweringError.invalidCDeclType(cdeclType)
}
}
Expand Down Expand Up @@ -127,8 +128,6 @@ extension SwiftKnownTypeDeclKind {
.pointer(
.qualified(const: true, volatile: false, type: .void)
)
case .array:
.pointer(.qualified(const: false, volatile: false, type: .void))
case .void: .void
default:
nil // Since we know the set of all primitives, we can safely assume all others are not primitive
Expand Down
Loading
Loading