Skip to content

Enable Enum Imports and Synchronize Paths #2513

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 2 commits into from
Jan 2, 2020
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
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
#endif

#define __CF_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && (__has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum)))
#define __CF_NAMED_ENUM(_type, _name) enum __CF_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
#define __CF_ANON_ENUM(_type) enum __CF_ENUM_ATTRIBUTES : _type
#define CF_CLOSED_ENUM(_type, _name) enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
Expand Down
7 changes: 6 additions & 1 deletion CoreFoundation/Locale.subproj/CFDateComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ CF_IMPLICIT_BRIDGING_ENABLED
CF_EXTERN_C_BEGIN
CF_ASSUME_NONNULL_BEGIN

// Must match NSDateComponentUndefined
CF_ENUM(CFIndex) {
CFDateComponentUndefined = __LONG_MAX__ // Must match NSDateComponentUndefined
#if TARGET_OS_WIN32
CFDateComponentUndefined = LLONG_MAX
#else
CFDateComponentUndefined = __LONG_MAX__
#endif
};

enum {
Expand Down
9 changes: 2 additions & 7 deletions Foundation/DateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ open class DateFormatter : Formatter {
private var __cfObject: CFType?
private var _cfObject: CFType {
guard let obj = __cfObject else {
#if os(macOS) || os(iOS)
let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))!
let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))!
#else
let dateStyle = CFDateFormatterStyle(self.dateStyle.rawValue)
let timeStyle = CFDateFormatterStyle(self.timeStyle.rawValue)
#endif
let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))!
let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))!

let obj = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale._cfObject, dateStyle, timeStyle)!
_setFormatterAttributes(obj)
Expand Down
2 changes: 0 additions & 2 deletions Foundation/DateIntervalFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import CoreFoundation

#if _runtime(_ObjC)
internal let kCFDateIntervalFormatterNoStyle = CFDateIntervalFormatterStyle.noStyle
internal let kCFDateIntervalFormatterShortStyle = CFDateIntervalFormatterStyle.shortStyle
internal let kCFDateIntervalFormatterMediumStyle = CFDateIntervalFormatterStyle.mediumStyle
Expand All @@ -20,7 +19,6 @@ internal let kCFDateIntervalFormatterBoundaryStyleDefault = _CFDateIntervalForma
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
internal let kCFDateIntervalFormatterBoundaryStyleMinimizeAdjacentMonths = _CFDateIntervalFormatterBoundaryStyle.cfDateIntervalFormatterBoundaryStyleMinimizeAdjacentMonths
#endif
#endif

extension DateIntervalFormatter {
// Keep these in sync with CFDateIntervalFormatterStyle.
Expand Down
15 changes: 2 additions & 13 deletions Foundation/ISO8601DateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ open class ISO8601DateFormatter : Formatter, NSSecureCoding {
private var __cfObject: CFType?
private var _cfObject: CFType {
guard let obj = __cfObject else {
#if os(macOS) || os(iOS)
let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue)
#else
let format = CFISO8601DateFormatOptions(self.formatOptions.rawValue)
#endif
let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue)
let obj = CFDateFormatterCreateISO8601Formatter(kCFAllocatorSystemDefault, format)!
CFDateFormatterSetProperty(obj, kCFDateFormatterTimeZone, timeZone._cfObject)
__cfObject = obj
Expand Down Expand Up @@ -137,17 +133,10 @@ open class ISO8601DateFormatter : Formatter, NSSecureCoding {
}

open class func string(from date: Date, timeZone: TimeZone, formatOptions: ISO8601DateFormatter.Options = []) -> String {

#if os(macOS) || os(iOS)
let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue)
#else
let format = CFISO8601DateFormatOptions(formatOptions.rawValue)
#endif

let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue)
let obj = CFDateFormatterCreateISO8601Formatter(kCFAllocatorSystemDefault, format)
CFDateFormatterSetProperty(obj, kCFDateFormatterTimeZone, timeZone._cfObject)
return CFDateFormatterCreateStringWithDate(kCFAllocatorSystemDefault, obj, date._cfObject)._swiftObject

}

private func _reset() {
Expand Down
25 changes: 0 additions & 25 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import CoreFoundation

#if canImport(ObjectiveC) // automatic CF_OPTIONS(…) OptionSet hoisting depends on the objc_fixed_enum attribute
internal let kCFCalendarUnitEra = CFCalendarUnit.era
internal let kCFCalendarUnitYear = CFCalendarUnit.year
internal let kCFCalendarUnitMonth = CFCalendarUnit.month
Expand All @@ -34,26 +33,6 @@ internal let kCFDateFormatterShortStyle = CFDateFormatterStyle.shortStyle
internal let kCFDateFormatterMediumStyle = CFDateFormatterStyle.mediumStyle
internal let kCFDateFormatterLongStyle = CFDateFormatterStyle.longStyle
internal let kCFDateFormatterFullStyle = CFDateFormatterStyle.fullStyle
#else
internal let kCFCalendarUnitEra = CFCalendarUnit(CoreFoundation.kCFCalendarUnitEra)
internal let kCFCalendarUnitYear = CFCalendarUnit(CoreFoundation.kCFCalendarUnitYear)
internal let kCFCalendarUnitMonth = CFCalendarUnit(CoreFoundation.kCFCalendarUnitMonth)
internal let kCFCalendarUnitDay = CFCalendarUnit(CoreFoundation.kCFCalendarUnitDay)
internal let kCFCalendarUnitHour = CFCalendarUnit(CoreFoundation.kCFCalendarUnitHour)
internal let kCFCalendarUnitMinute = CFCalendarUnit(CoreFoundation.kCFCalendarUnitMinute)
internal let kCFCalendarUnitSecond = CFCalendarUnit(CoreFoundation.kCFCalendarUnitSecond)
internal let kCFCalendarUnitWeekday = CFCalendarUnit(CoreFoundation.kCFCalendarUnitWeekday)
internal let kCFCalendarUnitWeekdayOrdinal = CFCalendarUnit(CoreFoundation.kCFCalendarUnitWeekdayOrdinal)
internal let kCFCalendarUnitQuarter = CFCalendarUnit(CoreFoundation.kCFCalendarUnitQuarter)
internal let kCFCalendarUnitWeekOfMonth = CFCalendarUnit(CoreFoundation.kCFCalendarUnitWeekOfMonth)
internal let kCFCalendarUnitWeekOfYear = CFCalendarUnit(CoreFoundation.kCFCalendarUnitWeekOfYear)
internal let kCFCalendarUnitYearForWeekOfYear = CFCalendarUnit(CoreFoundation.kCFCalendarUnitYearForWeekOfYear)
internal let kCFCalendarUnitNanosecond = CFCalendarUnit(CoreFoundation.kCFCalendarUnitNanosecond)

internal func _CFCalendarUnitRawValue(_ unit: CFCalendarUnit) -> CFOptionFlags {
return unit
}
#endif

extension NSCalendar {
public struct Identifier : RawRepresentable, Equatable, Hashable, Comparable {
Expand Down Expand Up @@ -109,11 +88,7 @@ extension NSCalendar {
public static let timeZone = Unit(rawValue: UInt(1 << 21))

internal var _cfValue: CFCalendarUnit {
#if os(macOS) || os(iOS)
return CFCalendarUnit(rawValue: self.rawValue)
#else
return CFCalendarUnit(self.rawValue)
#endif
}
}

Expand Down
11 changes: 0 additions & 11 deletions Foundation/NSCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import CoreFoundation

#if _runtime(_ObjC) // if objc_enum works, restore the old names:
let kCFCharacterSetControl = CFCharacterSetPredefinedSet.control
let kCFCharacterSetWhitespace = CFCharacterSetPredefinedSet.whitespace
let kCFCharacterSetWhitespaceAndNewline = CFCharacterSetPredefinedSet.whitespaceAndNewline
Expand All @@ -32,27 +31,18 @@ let kCFCharacterSetKeyedCodingTypeBuiltin = CFCharacterSetKeyedCodingType.builti
let kCFCharacterSetKeyedCodingTypeRange = CFCharacterSetKeyedCodingType.range
let kCFCharacterSetKeyedCodingTypeString = CFCharacterSetKeyedCodingType.string
let kCFCharacterSetKeyedCodingTypeBuiltinAndBitmap = CFCharacterSetKeyedCodingType.builtinAndBitmap
#endif

#if _runtime(_ObjC)
fileprivate let lastKnownPredefinedCharacterSetConstant = kCFCharacterSetNewline.rawValue

fileprivate extension Int {
init(_ predefinedSet: CFCharacterSetPredefinedSet) {
self = predefinedSet.rawValue
}
}
#else
fileprivate let lastKnownPredefinedCharacterSetConstant = kCFCharacterSetNewline
#endif

fileprivate func knownPredefinedCharacterSet(rawValue: Int) -> CFCharacterSetPredefinedSet? {
if rawValue > 0 && rawValue <= lastKnownPredefinedCharacterSetConstant {
#if _runtime(_ObjC)
return CFCharacterSetPredefinedSet(rawValue: rawValue)
#else
return CFCharacterSetPredefinedSet(rawValue)
#endif
} else {
return nil
}
Expand All @@ -70,7 +60,6 @@ fileprivate extension String {
static let characterSetNewIsInvertedKey = "NSIsInverted2"
}


open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
typealias CFType = CFCharacterSet
private var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,12 @@ extension NSLocale {

open class func characterDirection(forLanguage isoLangCode: String) -> NSLocale.LanguageDirection {
let dir = CFLocaleGetLanguageCharacterDirection(isoLangCode._cfObject)
#if os(macOS) || os(iOS)
return NSLocale.LanguageDirection(rawValue: UInt(dir.rawValue))!
#else
return NSLocale.LanguageDirection(rawValue: UInt(dir))!
#endif
}

open class func lineDirection(forLanguage isoLangCode: String) -> NSLocale.LanguageDirection {
let dir = CFLocaleGetLanguageLineDirection(isoLangCode._cfObject)
#if os(macOS) || os(iOS)
return NSLocale.LanguageDirection(rawValue: UInt(dir.rawValue))!
#else
return NSLocale.LanguageDirection(rawValue: UInt(dir))!
#endif
}
}

Expand Down
4 changes: 0 additions & 4 deletions Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import CoreFoundation

#if os(macOS) || os(iOS)
internal let kCFNumberSInt8Type = CFNumberType.sInt8Type
internal let kCFNumberSInt16Type = CFNumberType.sInt16Type
internal let kCFNumberSInt32Type = CFNumberType.sInt32Type
Expand All @@ -28,9 +27,6 @@ internal let kCFNumberCFIndexType = CFNumberType.cfIndexType
internal let kCFNumberNSIntegerType = CFNumberType.nsIntegerType
internal let kCFNumberCGFloatType = CFNumberType.cgFloatType
internal let kCFNumberSInt128Type = CFNumberType(rawValue: 17)!
#else
internal let kCFNumberSInt128Type: CFNumberType = 17
#endif

extension Int8 : _ObjectiveCBridgeable {
@available(swift, deprecated: 4, renamed: "init(truncating:)")
Expand Down
2 changes: 0 additions & 2 deletions Foundation/NSObjCRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

import CoreFoundation

#if os(macOS) || os(iOS)
internal let kCFCompareLessThan = CFComparisonResult.compareLessThan
internal let kCFCompareEqualTo = CFComparisonResult.compareEqualTo
internal let kCFCompareGreaterThan = CFComparisonResult.compareGreaterThan
#endif

internal enum _NSSimpleObjCType : UnicodeScalar {
case ID = "@"
Expand Down
16 changes: 0 additions & 16 deletions Foundation/NSRegularExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ open class NSRegularExpression: NSObject, NSCopying, NSSecureCoding {

public init(pattern: String, options: Options = []) throws {
var error: Unmanaged<CFError>?
#if os(macOS) || os(iOS)
let opt = _CFRegularExpressionOptions(rawValue: options.rawValue)
#else
let opt = _CFRegularExpressionOptions(options.rawValue)
#endif
if let regex = _CFRegularExpressionCreate(kCFAllocatorSystemDefault, pattern._cfObject, opt, &error) {
_internal = regex
} else {
Expand All @@ -97,11 +93,7 @@ open class NSRegularExpression: NSObject, NSCopying, NSSecureCoding {
}

open var options: Options {
#if os(macOS) || os(iOS)
let opt = _CFRegularExpressionGetOptions(_internal).rawValue
#else
let opt = _CFRegularExpressionGetOptions(_internal)
#endif

return Options(rawValue: opt)
}
Expand Down Expand Up @@ -158,11 +150,7 @@ internal class _NSRegularExpressionMatcher {

internal func _NSRegularExpressionMatch(_ context: UnsafeMutableRawPointer?, ranges: UnsafeMutablePointer<CFRange>?, count: CFIndex, flags: _CFRegularExpressionMatchingFlags, stop: UnsafeMutablePointer<_DarwinCompatibleBoolean>) -> Void {
let matcher = unsafeBitCast(context, to: _NSRegularExpressionMatcher.self)
#if os(macOS) || os(iOS)
let flags = NSRegularExpression.MatchingFlags(rawValue: flags.rawValue)
#else
let flags = NSRegularExpression.MatchingFlags(rawValue: flags)
#endif
let result = ranges?.withMemoryRebound(to: NSRange.self, capacity: count) { rangePtr in
NSTextCheckingResult.regularExpressionCheckingResult(ranges: rangePtr, count: count, regularExpression: matcher.regex)
}
Expand All @@ -179,11 +167,7 @@ extension NSRegularExpression {
public func enumerateMatches(in string: String, options: NSRegularExpression.MatchingOptions = [], range: NSRange, using block: @escaping (NSTextCheckingResult?, NSRegularExpression.MatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
let matcher = _NSRegularExpressionMatcher(regex: self, block: block)
withExtendedLifetime(matcher) { (m: _NSRegularExpressionMatcher) -> Void in
#if os(macOS) || os(iOS)
let opts = _CFRegularExpressionMatchingOptions(rawValue: options.rawValue)
#else
let opts = _CFRegularExpressionMatchingOptions(options.rawValue)
#endif
_CFRegularExpressionEnumerateMatchesInString(_internal, string._cfObject, opts, CFRange(range), unsafeBitCast(matcher, to: UnsafeMutableRawPointer.self), _NSRegularExpressionMatch)
}
}
Expand Down
7 changes: 0 additions & 7 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func NSLocalizedString(_ key: String,
return bundle.localizedString(forKey: key, value: value, table: tableName)
}

#if os(macOS) || os(iOS)
internal let kCFStringEncodingMacRoman = CFStringBuiltInEncodings.macRoman.rawValue
internal let kCFStringEncodingWindowsLatin1 = CFStringBuiltInEncodings.windowsLatin1.rawValue
internal let kCFStringEncodingISOLatin1 = CFStringBuiltInEncodings.isoLatin1.rawValue
Expand All @@ -53,8 +52,6 @@ internal let kCFStringNormalizationFormD = CFStringNormalizationForm.D
internal let kCFStringNormalizationFormKD = CFStringNormalizationForm.KD
internal let kCFStringNormalizationFormC = CFStringNormalizationForm.C
internal let kCFStringNormalizationFormKC = CFStringNormalizationForm.KC

#endif

extension NSString {

Expand Down Expand Up @@ -105,11 +102,7 @@ extension NSString {
public static let regularExpression = CompareOptions(rawValue: 1024)

internal func _cfValue(_ fixLiteral: Bool = false) -> CFStringCompareFlags {
#if os(macOS) || os(iOS)
return contains(.literal) || !fixLiteral ? CFStringCompareFlags(rawValue: rawValue) : CFStringCompareFlags(rawValue: rawValue).union(.compareNonliteral)
#else
return contains(.literal) || !fixLiteral ? CFStringCompareFlags(rawValue) : CFStringCompareFlags(rawValue) | UInt(kCFCompareNonliteral)
#endif
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions Foundation/NSTimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
}

open func localizedName(_ style: NameStyle, locale: Locale?) -> String? {
#if os(macOS) || os(iOS)
let cfStyle = CFTimeZoneNameStyle(rawValue: style.rawValue)!
#else
let cfStyle = CFTimeZoneNameStyle(style.rawValue)
#endif
let cfStyle = CFTimeZoneNameStyle(rawValue: style.rawValue)!
return CFTimeZoneCopyLocalizedName(self._cfObject, cfStyle, locale?._cfObject ?? CFLocaleCopyCurrent())._swiftObject
}

Expand Down
6 changes: 0 additions & 6 deletions Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

import CoreFoundation

#if os(macOS) || os(iOS)
internal let kCFURLPOSIXPathStyle = CFURLPathStyle.cfurlposixPathStyle
internal let kCFURLWindowsPathStyle = CFURLPathStyle.cfurlWindowsPathStyle
#endif

#if canImport(Darwin)
import Darwin
Expand Down Expand Up @@ -524,11 +522,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {

open var password: String? {
let absoluteURL = CFURLCopyAbsoluteURL(_cfObject)
#if os(Linux) || os(Android) || os(Windows)
let passwordRange = CFURLGetByteRangeForComponent(absoluteURL, kCFURLComponentPassword, nil)
#else
let passwordRange = CFURLGetByteRangeForComponent(absoluteURL, .password, nil)
#endif
guard passwordRange.location != kCFNotFound else {
return nil
}
Expand Down
13 changes: 2 additions & 11 deletions Foundation/NumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import CoreFoundation


extension NumberFormatter {
public enum Style : UInt {
case none = 0
Expand Down Expand Up @@ -50,11 +49,7 @@ open class NumberFormatter : Formatter {
if let obj = _currentCfFormatter {
return obj
} else {
#if os(macOS) || os(iOS)
let numberStyle = CFNumberFormatterStyle(rawValue: CFIndex(self.numberStyle.rawValue))!
#else
let numberStyle = CFNumberFormatterStyle(self.numberStyle.rawValue)
#endif
let numberStyle = CFNumberFormatterStyle(rawValue: CFIndex(self.numberStyle.rawValue))!

let obj = CFNumberFormatterCreate(kCFAllocatorSystemDefault, locale._cfObject, numberStyle)!
_setFormatterAttributes(obj)
Expand Down Expand Up @@ -98,11 +93,7 @@ open class NumberFormatter : Formatter {
var range = CFRange(location: 0, length: string.length)
let number = withUnsafeMutablePointer(to: &range) { (rangePointer: UnsafeMutablePointer<CFRange>) -> NSNumber? in

#if os(macOS) || os(iOS)
let parseOption = allowsFloats ? 0 : CFNumberFormatterOptionFlags.parseIntegersOnly.rawValue
#else
let parseOption = allowsFloats ? 0 : CFOptionFlags(kCFNumberFormatterParseIntegersOnly)
#endif
let parseOption = allowsFloats ? 0 : CFNumberFormatterOptionFlags.parseIntegersOnly.rawValue
let result = CFNumberFormatterCreateNumberFromString(kCFAllocatorSystemDefault, _cfFormatter, string._cfObject, rangePointer, parseOption)

return result?._nsObject
Expand Down
2 changes: 0 additions & 2 deletions Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private var managerThreadRunLoop : RunLoop? = nil
private var managerThreadRunLoopIsRunning = false
private var managerThreadRunLoopIsRunningCondition = NSCondition()

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
internal let kCFSocketNoCallBack: CFOptionFlags = 0 // .noCallBack cannot be used because empty option flags are imported as unavailable.
internal let kCFSocketAcceptCallBack = CFSocketCallBackType.acceptCallBack.rawValue
internal let kCFSocketDataCallBack = CFSocketCallBackType.dataCallBack.rawValue
Expand All @@ -54,7 +53,6 @@ extension CFSocketError {
self.init(rawValue: value)
}
}
#endif

private func emptyRunLoopCallback(_ context : UnsafeMutableRawPointer?) -> Void {}

Expand Down
Loading