mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The rule changes are as follows: * All functions (introduced with the 'func' keyword) have argument labels for arguments beyond the first, by default. Methods are no longer special in this regard. * The presence of a default argument no longer implies an argument label. The actual changes to the parser and printer are fairly simple; the rest of the noise is updating the standard library, overlays, tests, etc. With the standard library, this change is intended to be API neutral: I've added/removed #'s and _'s as appropriate to keep the user interface the same. If we want to separately consider using argument labels for more free functions now that the defaults in the language have shifted, we can tackle that separately. Fixes rdar://problem/17218256. Swift SVN r27704
64 lines
1.7 KiB
Swift
64 lines
1.7 KiB
Swift
// RUN: %target-jit-run -parse-stdlib %s | FileCheck %s
|
|
|
|
// REQUIRES: swift_interpreter
|
|
// XFAIL: linux
|
|
|
|
// FIXME: iOS fails: target-run-stdlib-swift gets 'unknown identifier VarArgs'
|
|
|
|
import Swift
|
|
|
|
@asmname("vprintf")
|
|
func c_vprintf(format: UnsafePointer<Int8>, _ args: CVaListPointer)
|
|
|
|
func printf(format: String, _ arguments: CVarArgType...) {
|
|
withVaList(arguments) {
|
|
c_vprintf(format, $0)
|
|
}
|
|
}
|
|
|
|
func test_varArgs0() {
|
|
// CHECK: The answer to life and everything is 42, 42, -42, 3.14
|
|
VarArgs.printf(
|
|
"The answer to life and everything is %ld, %u, %d, %f\n",
|
|
42, UInt32(42), Int16(-42), 3.14159279)
|
|
}
|
|
test_varArgs0()
|
|
|
|
func test_varArgs1() {
|
|
var args = [CVarArgType]()
|
|
|
|
var format = "dig it: "
|
|
for i in 0..<12 {
|
|
args.append(Int16(-i))
|
|
args.append(Float(i))
|
|
format += "%d %2g "
|
|
}
|
|
|
|
// CHECK: dig it: 0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 9 -10 10 -11 11
|
|
withVaList(args) {
|
|
c_vprintf(format + "\n", $0)
|
|
}
|
|
}
|
|
test_varArgs1()
|
|
|
|
func test_varArgs3() {
|
|
var args = [CVarArgType]()
|
|
|
|
let format = "pointers: '%p' '%p' '%p' '%p' '%p'\n"
|
|
args.append(COpaquePointer(bitPattern: 0x1234_5670))
|
|
args.append(CFunctionPointer<() -> ()>(COpaquePointer(bitPattern: 0x1234_5671)))
|
|
args.append(UnsafePointer<Int>(bitPattern: 0x1234_5672))
|
|
args.append(UnsafeMutablePointer<Float>(bitPattern: 0x1234_5673))
|
|
args.append(AutoreleasingUnsafeMutablePointer<AnyObject>(
|
|
UnsafeMutablePointer<AnyObject>(bitPattern: 0x1234_5674)))
|
|
|
|
// CHECK: {{pointers: '(0x)?0*12345670' '(0x)?0*12345671' '(0x)?0*12345672' '(0x)?0*12345673' '(0x)?0*12345674'}}
|
|
withVaList(args) {
|
|
c_vprintf(format, $0)
|
|
}
|
|
}
|
|
test_varArgs3()
|
|
|
|
// CHECK: done.
|
|
println("done.")
|