Skip to content

Commit

Permalink
Fix primitive type bugs around char16 naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Mar 24, 2024
1 parent 8096d60 commit a0732f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/WindowsMetadata/MidlNameMangling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum MidlNameMangling {
case .uint64: return "UINT64"
}
case .float(let double): return double ? "double" : "float"
case .char: return "WCHAR"
case .char16: return "WCHAR"
case .guid: return "GUID"
case .string: return "HSTRING"
}
Expand Down
15 changes: 12 additions & 3 deletions Sources/WindowsMetadata/WinRTPrimitiveType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum WinRTPrimitiveType: Hashable {
case boolean
case integer(WinRTIntegerType)
case float(double: Bool)
case char
case char16
case guid
case string
}
Expand All @@ -16,7 +16,7 @@ extension WinRTPrimitiveType: CustomStringConvertible {
case .boolean: return "Boolean"
case .integer(let type): return type.name
case .float(let double): return double ? "Double" : "Single"
case .char: return "Char16"
case .char16: return "Char16"
case .guid: return "Guid"
case .string: return "String"
}
Expand All @@ -38,10 +38,19 @@ extension WinRTPrimitiveType {
case "UInt64": self = .integer(.uint64)
case "Single": self = .float(double: false)
case "Double": self = .float(double: true)
case "Char16": self = .char
case "Char16": self = .char16
case "Guid": self = .guid
case "String": self = .string
default: return nil
}
}

public init?(fromSystemNamespaceType name: String) {
// System namespace names match WinRT names except for Char16
switch name {
case "Char": self = .char16
case "Char16": return nil
default: self.init(fromName: name)
}
}
}
2 changes: 1 addition & 1 deletion Sources/WindowsMetadata/WinRTTypeName+fromType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DotNetMetadata
extension WinRTTypeName {
public static func from(type: BoundType) throws -> WinRTTypeName {
if type.definition.namespace == "System" {
if let primitiveType = WinRTPrimitiveType(fromName: type.definition.name) {
if let primitiveType = WinRTPrimitiveType(fromSystemNamespaceType: type.definition.name) {
return .primitive(primitiveType)
} else if type.definition.name == "Object" {
return .object
Expand Down

0 comments on commit a0732f6

Please sign in to comment.