Skip to content

Commit

Permalink
Define mappings for CF types on LLP64
Browse files Browse the repository at this point in the history
As per https://forums.swift.org/t/llp64-targets-and-integral-types/18253/15, define mappings for `CFTypeID`, `CFOptionFlags`, `CFHashCode`  to `UInt` for LLP64 support.
  • Loading branch information
troughton committed Nov 26, 2018
1 parent a820992 commit 89d6cdf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/ClangImporter/MappedTypes.def
Expand Up @@ -161,6 +161,9 @@ MAP_TYPE("CGFloat", CGFloat, 0, "CoreGraphics", "CGFloat", false, DoNothing)

// CoreFoundation types.
// Note that we're preserving the typealias for CFIndex.
MAP_STDLIB_TYPE("CFTypeID", UnsignedWord, 0, "UInt", false, DefineAndUse)
MAP_STDLIB_TYPE("CFOptionFlags", UnsignedWord, 0, "UInt", false, DefineAndUse)
MAP_STDLIB_TYPE("CFHashCode", UnsignedWord, 0, "UInt", false, DefineAndUse)
MAP_STDLIB_TYPE("CFIndex", SignedWord, 0, "Int", false, DefineAndUse)

// Foundation types.
Expand Down
13 changes: 11 additions & 2 deletions test/ClangImporter/ctypes_parse_objc.swift
Expand Up @@ -70,8 +70,17 @@ func testImportMacTypes() {
}

func testImportCFTypes() {
let t1_unqual: Int = CFIndex_test
_ = t1_unqual as CoreFoundation.CFIndex
let t1_unqual: UInt = CFTypeID_test
_ = t1_unqual as CoreFoundation.CFTypeID

let t2_unqual: UInt = CFOptionFlags_test
_ = t2_unqual as CoreFoundation.CFOptionFlags

let t3_unqual: UInt = CFHashCode_test
_ = t3_unqual as CoreFoundation.CFHashCode

let t4_unqual: Int = CFIndex_test
_ = t4_unqual as CoreFoundation.CFIndex
}

func testImportSEL() {
Expand Down
15 changes: 14 additions & 1 deletion test/Inputs/clang-importer-sdk/usr/include/CoreFoundation.h
Expand Up @@ -18,8 +18,21 @@ typedef struct __attribute__((objc_bridge(NSSet))) __CFSet const *CFSetRef;

typedef CFTypeRef CFAliasForTypeRef;


#if __LLP64__
typedef unsigned long long CFTypeID;
typedef unsigned long long CFOptionFlags;
typedef unsigned long long CFHashCode;
typedef signed long long CFIndex;
#else
typedef unsigned long CFTypeID;
typedef unsigned long CFOptionFlags;
typedef unsigned long CFHashCode;
typedef signed long CFIndex;
#endif

extern CFTypeID CFTypeID_test;
extern CFOptionFlags CFOptionFlags_test;
extern CFHashCode CFHashCode_test;
extern CFIndex CFIndex_test;

#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
Expand Down

0 comments on commit 89d6cdf

Please sign in to comment.