Skip to content

Commit b74e510

Browse files
Import as CoreFoundation.CGFloat if possible
1 parent 3b144fe commit b74e510

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,29 @@ getSwiftStdlibType(const clang::TypedefNameDecl *D,
250250
}
251251
#include "MappedTypes.def"
252252

253+
if (Name.str() == "CGFloat") {
254+
SwiftModuleName = StringRef("CoreGraphics");
255+
256+
ModuleDecl *M = Impl.getNamedModule(StringRef("CoreFoundation"));
257+
if (M) {
258+
Type SwiftType = Impl.getNamedSwiftType(M, "CGFloat");
259+
if (SwiftType) {
260+
SwiftModuleName = StringRef("CoreFoundation");
261+
}
262+
}
263+
264+
CTypeKind = MappedCTypeKind::CGFloat;
265+
Bitwidth = 0;
266+
IsSwiftModule = false;
267+
SwiftTypeName = "CGFloat";
268+
CanBeMissing = false;
269+
NameMapping = MappedTypeNameKind::DoNothing;
270+
assert(verifyNameMapping(MappedTypeNameKind::DoNothing,
271+
"CGFloat", "CGFloat") &&
272+
"MappedTypes.def: Identical names must use DoNothing");
273+
break;
274+
}
275+
253276
// We handle `BOOL` as a special case because the selection here is more
254277
// complicated as the type alias exists on multiple platforms as different
255278
// types. It appears in an Objective-C context where it is a `signed char`

lib/ClangImporter/MappedTypes.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ MAP_STDLIB_TYPE(
155155
Impl.SwiftContext.getSwiftName(KnownFoundationEntity::NSUInteger),
156156
UnsignedWord, 0, "Int", false, DoNothing)
157157

158-
// CoreGraphics types.
159-
MAP_TYPE("CGFloat", CGFloat, 0, "CoreGraphics", "CGFloat", false, DoNothing)
160-
161158
// CoreFoundation types.
162159
// Note that we're preserving the typealias for CFIndex.
163160
MAP_STDLIB_TYPE("CFTypeID", UnsignedWord, 0, "UInt", false, DefineAndUse)

0 commit comments

Comments
 (0)