From fa197bff3a006dedd648334d6f11a84ee03687a1 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 17 Jan 2013 19:46:39 +0000 Subject: [PATCH] The latest OSX 10.9 SDKs have changed name of the ObjC module to ObjectiveC. Update everywhere in Swift that refers to this module accordingly. This change is backwards-incompatible and will require rebuilding any Objective-C-based object files. I recommend a clean of swiftFoundation and NSStringDemo at the very least. The swiftObjC target is also being renamed to swiftObjectiveC for consistency. Swift SVN r3784 --- lib/ClangImporter/ImportDecl.cpp | 2 +- lib/ClangImporter/ImportType.cpp | 2 +- objc/CMakeLists.txt | 8 ++-- objc/Foundation/CMakeLists.txt | 2 +- objc/ObjC.swift | 41 ----------------- objc/ObjectiveC.swift | 78 ++++++++++++++++++++++++++++++++ tools/swift/Immediate.cpp | 2 +- 7 files changed, 86 insertions(+), 49 deletions(-) delete mode 100644 objc/ObjC.swift create mode 100644 objc/ObjectiveC.swift diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 427b26c4e9f..ea48c907156 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -90,7 +90,7 @@ namespace { name.str() == "BOOL" && clangContext.hasSameType(decl->getUnderlyingType(), clangContext.ObjCBuiltinBoolTy)) { - type = Impl.getNamedSwiftType(Impl.getNamedModule("ObjC"), "ObjCBool"); + type = Impl.getNamedSwiftType(Impl.getNamedModule("ObjectiveC"), "ObjCBool"); } else { type = Impl.importType(decl->getUnderlyingType()); } diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 791c5d87215..5db25f10d5d 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -169,7 +169,7 @@ namespace { // "builtin-SEL *" maps to Swift's ObjCSel. if (type->getPointeeType()->isSpecificBuiltinType( clang::BuiltinType::ObjCSel)) { - return Impl.getNamedSwiftType(Impl.getNamedModule("ObjC"), "ObjCSel"); + return Impl.getNamedSwiftType(Impl.getNamedModule("ObjectiveC"), "ObjCSel"); } // All other C pointers map to CPointer. diff --git a/objc/CMakeLists.txt b/objc/CMakeLists.txt index 647d4623c3d..485a6ec613a 100644 --- a/objc/CMakeLists.txt +++ b/objc/CMakeLists.txt @@ -14,15 +14,15 @@ endfunction() # Build the swiftObjC dylib. set(SHARED_LIBRARY ON) -add_swift_library(swiftObjC - ObjC.swift +add_swift_library(swiftObjectiveC + ObjectiveC.swift DEPENDS swift_stdlib) # Link against the system dylib. -target_link_libraries(swiftObjC +target_link_libraries(swiftObjectiveC "-lobjc") -install_swift_module(ObjC.swift) +install_swift_module(ObjectiveC.swift) add_subdirectory(Foundation) add_subdirectory(ScriptingBridge) diff --git a/objc/Foundation/CMakeLists.txt b/objc/Foundation/CMakeLists.txt index 328b5253516..9ebec1eeea3 100644 --- a/objc/Foundation/CMakeLists.txt +++ b/objc/Foundation/CMakeLists.txt @@ -2,7 +2,7 @@ set(SHARED_LIBRARY ON) add_swift_library(swiftFoundation Foundation.swift BridgeNSString.mm - DEPENDS swift_stdlib swiftObjC) + DEPENDS swift_stdlib swiftObjectiveC) if(SWIFT_OPTIMIZED) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386") diff --git a/objc/ObjC.swift b/objc/ObjC.swift deleted file mode 100644 index 51096ca30a6..00000000000 --- a/objc/ObjC.swift +++ /dev/null @@ -1,41 +0,0 @@ -import ObjC - -//===----------------------------------------------------------------------===// -// Objective-C Primitive Types -//===----------------------------------------------------------------------===// -// FIXME: Objective-C types belong in a layer below the Objective-C support -// libraries, not here. - -/// \brief The Objective-C BOOL type. -/// -/// The Objective-C BOOL type is typically a typedef of "signed char". However, -/// the Clang importer treats it as a distinct type. -/// -/// Note: When BOOL is a typedef of C's _Bool/C++'s bool, this struct goes away -/// and simply becomes a typealias for CBool. -struct ObjCBool { - var value : UInt8 - - /// \brief Allow use in a Boolean context. - func getLogicValue() -> Bool { - if value == 0 { return false } - return true - } - - /// \brief Implicit conversion from C Boolean type to Swift Boolean - /// type. - func [conversion] __conversion() -> Bool { - return this - } -} - -extension Bool { - /// \brief Implicit conversion from Swift Boolean type to - /// Objective-C Boolean type. - func [conversion] __conversion() -> ObjCBool { - var result : ObjCBool - if this { result.value = 1 } - else { result.value = 0 } - return result - } -} diff --git a/objc/ObjectiveC.swift b/objc/ObjectiveC.swift new file mode 100644 index 00000000000..8784c8e7758 --- /dev/null +++ b/objc/ObjectiveC.swift @@ -0,0 +1,78 @@ +import ObjectiveC + +//===----------------------------------------------------------------------===// +// Objective-C Primitive Types +//===----------------------------------------------------------------------===// +// FIXME: Objective-C types belong in a layer below the Objective-C support +// libraries, not here. + +/// \brief The Objective-C BOOL type. +/// +/// The Objective-C BOOL type is typically a typedef of "signed char". However, +/// the Clang importer treats it as a distinct type. +/// +/// Note: When BOOL is a typedef of C's _Bool/C++'s bool, this struct goes away +/// and simply becomes a typealias for CBool. +struct ObjCBool { + // FIXME: Ambiguity between ObjC and swift modules. Ugh. + var value : swift.UInt8 + + /// \brief Allow use in a Boolean context. + func getLogicValue() -> Bool { + if value == 0 { return false } + return true + } + + /// \brief Implicit conversion from C Boolean type to Swift Boolean + /// type. + func [conversion] __conversion() -> Bool { + return this + } +} + +extension Bool { + /// \brief Implicit conversion from Swift Boolean type to + /// Objective-C Boolean type. + func [conversion] __conversion() -> ObjCBool { + var result : ObjCBool + if this { result.value = 1 } + else { result.value = 0 } + return result + } +} + +/// \brief The Objective-C SEL type. +/// +/// The Objective-C SEL type is typically an opaque pointer. Swift +/// treats it as a distinct struct type, with operations to +/// convert between C strings and selectors. +struct ObjCSel { + var ptr : COpaquePointer + + /// \brief Create a selector from a string. + constructor(str : String) { + ptr = sel_registerName(CString(str)).ptr + } + + /// \brief Construct a selector from a string literal. + /// + /// FIXME: Fast-path this in the compiler, so we don't end up with + /// the sel_registerName call at compile time. + static func convertFromStringLiteral(str : CString) -> ObjCSel { + return sel_registerName(str) + } + + func replPrint() { + print(String(this)) + } +} + +extension String { + /// \brief Construct the C string representation of an Objective-C selector. + constructor(sel : ObjCSel) { + // FIXME: This is crazy. Adopting a C string as a Swift string should be + // simpler. This even misses the ASCII optimization. + var name = sel_getName(sel) + this = String.convertFromStringLiteral(name.cstr.value, strlen(name).value) + } +} diff --git a/tools/swift/Immediate.cpp b/tools/swift/Immediate.cpp index 21901c1c5b1..d27d2347d4d 100644 --- a/tools/swift/Immediate.cpp +++ b/tools/swift/Immediate.cpp @@ -127,7 +127,7 @@ static bool IRGenImportedModules(TranslationUnit *TU, StringRef sharedLibName = llvm::StringSwitch(SubTU->Name.str()) .Case("Foundation", "libswiftFoundation.dylib") - .Case("ObjC", "libswiftObjC.dylib") + .Case("ObjectiveC", "libswiftObjectiveC.dylib") .Default(""); if (!sharedLibName.empty()) { loadRuntimeLib(sharedLibName);