mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This is a squash of the following commits: * [SE-0054] Import function pointer arg, return types, typedefs as optional IUOs are only allowed on function decl arguments and return types, so don't import typedefs or function pointer args or return types as IUO. * [SE-0054] Only allow IUOs in function arg and result type. When validating a TypeRepr, raise a diagnostic if an IUO is found anywhere other thn the top level or as a function parameter or return tpye. * [SE-0054] Disable inference of IUOs by default When considering a constraint of the form '$T1 is convertible to T!', generate potential bindings 'T' and 'T?' for $T1, but not 'T!'. This prevents variables without explicit type information from ending up with IUO type. It also prevents implicit instantiation of functions and types with IUO type arguments. * [SE-0054] Remove the -disable-infer-iuos flag. * Add nonnull annotations to ObjectiveCTests.h in benchmark suite.
82 lines
2.2 KiB
Plaintext
82 lines
2.2 KiB
Plaintext
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import SwiftShims
|
|
|
|
%{
|
|
|
|
allFloatBits = [32, 64, 80]
|
|
|
|
def floatName(bits):
|
|
if bits == 32:
|
|
return 'Float'
|
|
if bits == 64:
|
|
return 'Double'
|
|
if bits == 80:
|
|
return 'Float80'
|
|
|
|
cFuncSuffix2 = {32: 'f', 64: 'd', 80: 'ld'}
|
|
|
|
}%
|
|
|
|
/// Returns `true` iff isspace(u) would return nonzero when the current
|
|
/// locale is the C locale.
|
|
@warn_unused_result
|
|
internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool {
|
|
return "\t\n\u{b}\u{c}\r ".utf16.contains(u)
|
|
}
|
|
|
|
% for bits in allFloatBits:
|
|
% Self = floatName(bits)
|
|
|
|
% if bits == 80:
|
|
#if !os(Windows) && (arch(i386) || arch(x86_64))
|
|
% end
|
|
|
|
//===--- Parsing ----------------------------------------------------------===//
|
|
extension ${Self} {
|
|
/// Construct from an ASCII representation.
|
|
///
|
|
/// Returns the result of calling the POSIX function
|
|
/// `strto${cFuncSuffix2[bits]}_l` using the "C" locale, unless
|
|
/// `text` contains non-ASCII text or whitespace, or is not
|
|
/// completely consumed by the call. Otherwise, returns `nil`.
|
|
///
|
|
/// See the `strto${cFuncSuffix2[bits]} (3)` man page for details of
|
|
/// the exact format accepted.
|
|
public init?(_ text: String) {
|
|
let u16 = text.utf16
|
|
func parseNTBS(_ chars: UnsafePointer<CChar>) -> (${Self}, Int) {
|
|
var result: ${Self} = 0
|
|
let endPtr = withUnsafeMutablePointer(&result) {
|
|
_swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(
|
|
chars, UnsafeMutablePointer($0))
|
|
}
|
|
return (result, endPtr == nil ? 0 : UnsafePointer(endPtr!) - chars)
|
|
}
|
|
|
|
let (result, n) = text.withCString(parseNTBS)
|
|
|
|
if n == 0 || n != u16.count
|
|
|| u16.contains({ $0 > 127 || _isspace_clocale($0) }) {
|
|
return nil
|
|
}
|
|
self = result
|
|
}
|
|
}
|
|
|
|
% if bits == 80:
|
|
#endif
|
|
% end
|
|
|
|
% end
|