Skip to content

Commit 781ee82

Browse files
authored
Merge pull request #5085 from phausler/Foundation_cleanup
2 parents 0ce9aef + 2ffc3d5 commit 781ee82

21 files changed

+1864
-1634
lines changed

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,56 @@
11
add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2-
Foundation.swift.gyb
3-
Boxing.swift
4-
NSError.swift
5-
NSStringAPI.swift
6-
NSValue.swift.gyb
7-
ExtraStringAPIs.swift
8-
ReferenceConvertible.swift
92
AffineTransform.swift
3+
Boxing.swift
104
Calendar.swift
11-
TimeZone.swift
12-
Locale.swift
135
CharacterSet.swift
6+
Data.swift
7+
DataThunks.m
148
Date.swift
159
DateComponents.swift
1610
DateInterval.swift
17-
Data.swift
18-
DataThunks.m
1911
Decimal.swift
12+
ExtraStringAPIs.swift
2013
FileManager.swift
2114
FileManagerThunks.m
15+
Foundation.swift
16+
Hashing.m
17+
Hashing.swift
2218
IndexPath.swift
2319
IndexSet.swift
2420
IndexSetThunks.m
21+
Locale.swift
2522
Measurement.swift
2623
Notification.swift
24+
NSArray.swift
25+
NSCoder.swift
26+
NSDate.swift
27+
NSDictionary.swift
28+
NSError.swift
29+
NSExpression.swift
30+
NSFastEnumeration.swift
31+
NSGeometry.swift
32+
NSIndexSet.swift
33+
NSNumber.swift.gyb
34+
NSPredicate.swift
35+
NSRange.swift
36+
NSSet.swift
37+
NSString.swift
38+
NSStringAPI.swift
2739
NSStringEncodings.swift
40+
NSTextCheckingResult.swift
41+
NSUndoManager.swift
42+
NSURL.swift
43+
NSValue.swift.gyb
2844
PersonNameComponents.swift
45+
ReferenceConvertible.swift
46+
String.swift
47+
Thunks.mm
48+
TimeZone.swift
2949
TypePreservingNSNumber.mm
3050
URL.swift
3151
URLComponents.swift
3252
URLRequest.swift
3353
UUID.swift
34-
Hashing.swift
35-
Hashing.m
36-
Thunks.mm
3754

3855
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
3956
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import Foundation // Clang module
14+
import CoreFoundation
15+
import CoreGraphics
16+
17+
//===----------------------------------------------------------------------===//
18+
// NSObject
19+
//===----------------------------------------------------------------------===//
20+
21+
// These conformances should be located in the `ObjectiveC` module, but they can't
22+
// be placed there because string bridging is not available there.
23+
extension NSObject : CustomStringConvertible {}
24+
extension NSObject : CustomDebugStringConvertible {}
25+
26+
public let NSNotFound: Int = .max
27+
28+
//===----------------------------------------------------------------------===//
29+
// NSLocalizedString
30+
//===----------------------------------------------------------------------===//
31+
32+
/// Returns a localized string, using the main bundle if one is not specified.
33+
public
34+
func NSLocalizedString(_ key: String,
35+
tableName: String? = nil,
36+
bundle: Bundle = Bundle.main,
37+
value: String = "",
38+
comment: String) -> String {
39+
return bundle.localizedString(forKey: key, value:value, table:tableName)
40+
}
41+
42+
//===----------------------------------------------------------------------===//
43+
// NSLog
44+
//===----------------------------------------------------------------------===//
45+
46+
public func NSLog(_ format: String, _ args: CVarArg...) {
47+
withVaList(args) { NSLogv(format, $0) }
48+
}
49+
50+
//===----------------------------------------------------------------------===//
51+
// AnyHashable
52+
//===----------------------------------------------------------------------===//
53+
54+
extension AnyHashable : _ObjectiveCBridgeable {
55+
public func _bridgeToObjectiveC() -> NSObject {
56+
// This is unprincipled, but pretty much any object we'll encounter in
57+
// Swift is NSObject-conforming enough to have -hash and -isEqual:.
58+
return unsafeBitCast(base as AnyObject, to: NSObject.self)
59+
}
60+
61+
public static func _forceBridgeFromObjectiveC(
62+
_ x: NSObject,
63+
result: inout AnyHashable?
64+
) {
65+
result = AnyHashable(x)
66+
}
67+
68+
public static func _conditionallyBridgeFromObjectiveC(
69+
_ x: NSObject,
70+
result: inout AnyHashable?
71+
) -> Bool {
72+
self._forceBridgeFromObjectiveC(x, result: &result)
73+
return result != nil
74+
}
75+
76+
public static func _unconditionallyBridgeFromObjectiveC(
77+
_ source: NSObject?
78+
) -> AnyHashable {
79+
// `nil` has historically been used as a stand-in for an empty
80+
// string; map it to an empty string.
81+
if _slowPath(source == nil) { return AnyHashable(String()) }
82+
return AnyHashable(source!)
83+
}
84+
}
85+
86+
//===----------------------------------------------------------------------===//
87+
// CVarArg for bridged types
88+
//===----------------------------------------------------------------------===//
89+
90+
extension CVarArg where Self: _ObjectiveCBridgeable {
91+
/// Default implementation for bridgeable types.
92+
public var _cVarArgEncoding: [Int] {
93+
let object = self._bridgeToObjectiveC()
94+
_autorelease(object)
95+
return _encodeBitsAsWords(object)
96+
}
97+
}

0 commit comments

Comments
 (0)