Skip to content

[5.0] statically map CF types in the ClangImporter #20840

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

Merged
merged 1 commit into from
Dec 18, 2018
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
3 changes: 3 additions & 0 deletions lib/ClangImporter/MappedTypes.def
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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