mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<T>.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
78
objc/ObjectiveC.swift
Normal file
78
objc/ObjectiveC.swift
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ static bool IRGenImportedModules(TranslationUnit *TU,
|
||||
StringRef sharedLibName
|
||||
= llvm::StringSwitch<StringRef>(SubTU->Name.str())
|
||||
.Case("Foundation", "libswiftFoundation.dylib")
|
||||
.Case("ObjC", "libswiftObjC.dylib")
|
||||
.Case("ObjectiveC", "libswiftObjectiveC.dylib")
|
||||
.Default("");
|
||||
if (!sharedLibName.empty()) {
|
||||
loadRuntimeLib(sharedLibName);
|
||||
|
||||
Reference in New Issue
Block a user