mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The legacy `@_cdecl` remains unaffected.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/// @cdecl attribute
|
||||
/// @c attribute
|
||||
/// This test shouldn't require the objc runtime.
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s \
|
||||
@@ -6,104 +6,104 @@
|
||||
|
||||
// REQUIRES: swift_feature_CDecl
|
||||
|
||||
@cdecl(cdecl_foo) func foo(x: Int) -> Int { return x }
|
||||
@c(cdecl_foo) func foo(x: Int) -> Int { return x }
|
||||
|
||||
@cdecl(not an identifier) func invalidName() {}
|
||||
// expected-error @-1 {{expected ')' in 'cdecl' attribute}}
|
||||
@c(not an identifier) func invalidName() {}
|
||||
// expected-error @-1 {{expected ')' in 'c' attribute}}
|
||||
// expected-error @-2 {{expected declaration}}
|
||||
|
||||
@cdecl() func emptyParen() {}
|
||||
// expected-error @-1 {{expected C identifier in 'cdecl' attribute}}
|
||||
@c() func emptyParen() {}
|
||||
// expected-error @-1 {{expected C identifier in 'c' attribute}}
|
||||
// expected-error @-2 {{expected declaration}}
|
||||
|
||||
@cdecl(42) func aNumber() {}
|
||||
// expected-error @-1 {{expected C identifier in 'cdecl' attribute}}
|
||||
@c(42) func aNumber() {}
|
||||
// expected-error @-1 {{expected C identifier in 'c' attribute}}
|
||||
// expected-error @-2 {{expected declaration}}
|
||||
|
||||
@cdecl(a:selector:) func selectordName() {}
|
||||
// expected-error @-1 {{expected ')' in 'cdecl' attribute}}
|
||||
@c(a:selector:) func selectordName() {}
|
||||
// expected-error @-1 {{expected ')' in 'c' attribute}}
|
||||
// expected-error @-2 {{expected declaration}}
|
||||
|
||||
@cdecl func defaultName() {}
|
||||
@c func defaultName() {}
|
||||
|
||||
@cdecl("noBody")
|
||||
@c("noBody")
|
||||
func noBody(x: Int) -> Int // expected-error{{expected '{' in body of function}}
|
||||
|
||||
@cdecl("property") // expected-error{{'@cdecl' attribute cannot be applied to this declaration}}
|
||||
@c("property") // expected-error{{'@c' attribute cannot be applied to this declaration}}
|
||||
var property: Int
|
||||
|
||||
var computed: Int {
|
||||
@cdecl("get_computed") get { return 0 }
|
||||
@cdecl("set_computed") set { return }
|
||||
@c("get_computed") get { return 0 }
|
||||
@c("set_computed") set { return }
|
||||
}
|
||||
|
||||
@cdecl("inout")
|
||||
func noBody(x: inout Int) { } // expected-error{{global function cannot be marked '@cdecl' because inout parameters cannot be represented in C}}
|
||||
@c("inout")
|
||||
func noBody(x: inout Int) { } // expected-error{{global function cannot be marked '@c' because inout parameters cannot be represented in C}}
|
||||
|
||||
struct SwiftStruct { var x, y: Int }
|
||||
enum SwiftEnum { case A, B }
|
||||
|
||||
#if os(Windows) && (arch(x86_64) || arch(arm64))
|
||||
@cdecl("CEnum") enum CEnum: Int32 { case A, B }
|
||||
@c("CEnum") enum CEnum: Int32 { case A, B }
|
||||
#else
|
||||
@cdecl("CEnum") enum CEnum: Int { case A, B }
|
||||
@c("CEnum") enum CEnum: Int { case A, B }
|
||||
#endif
|
||||
|
||||
@cdecl enum CEnumDefaultName: CInt { case A, B }
|
||||
@c enum CEnumDefaultName: CInt { case A, B }
|
||||
|
||||
@cdecl("CEnumNoRawType") enum CEnumNoRawType { case A, B }
|
||||
// expected-error @-1 {{'@cdecl' enum must declare an integer raw type}}
|
||||
@c("CEnumNoRawType") enum CEnumNoRawType { case A, B }
|
||||
// expected-error @-1 {{'@c' enum must declare an integer raw type}}
|
||||
|
||||
@cdecl("CEnumStringRawType") enum CEnumStringRawType: String { case A, B }
|
||||
// expected-error @-1 {{'@cdecl' enum raw type 'String' is not an integer type}}
|
||||
@c("CEnumStringRawType") enum CEnumStringRawType: String { case A, B }
|
||||
// expected-error @-1 {{'@c' enum raw type 'String' is not an integer type}}
|
||||
|
||||
@cdecl("swiftStruct")
|
||||
@c("swiftStruct")
|
||||
func swiftStruct(x: SwiftStruct) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift structs cannot be represented in C}}
|
||||
|
||||
@cdecl("swiftEnum")
|
||||
@c("swiftEnum")
|
||||
func swiftEnum(x: SwiftEnum) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@cdecl' cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@c' cannot be represented in C}}
|
||||
|
||||
@cdecl("cEnum")
|
||||
@c("cEnum")
|
||||
func cEnum(x: CEnum) {}
|
||||
|
||||
@cdecl("CDeclAndObjC") // expected-error {{cannot apply both '@cdecl' and '@objc' to enum}}
|
||||
@c("CDeclAndObjC") // expected-error {{cannot apply both '@c' and '@objc' to enum}}
|
||||
@objc
|
||||
enum CDeclAndObjC: CInt { case A, B }
|
||||
|
||||
@cdecl("TwoCDecls") // expected-note {{attribute already specified here}}
|
||||
@c("TwoCDecls") // expected-note {{attribute already specified here}}
|
||||
@_cdecl("TwoCDecls") // expected-error {{duplicate attribute}}
|
||||
func TwoCDecls() {}
|
||||
|
||||
class Foo {
|
||||
@cdecl("Foo_foo") // expected-error{{@cdecl can only be applied to global functions}}
|
||||
@c("Foo_foo") // expected-error{{@c can only be applied to global functions}}
|
||||
func foo(x: Int) -> Int { return x }
|
||||
|
||||
@cdecl("Foo_foo_2") // expected-error{{@cdecl can only be applied to global functions}}
|
||||
@c("Foo_foo_2") // expected-error{{@c can only be applied to global functions}}
|
||||
static func foo(x: Int) -> Int { return x }
|
||||
|
||||
@cdecl("Foo_init") // expected-error{{'@cdecl' attribute cannot be applied to this declaration}}
|
||||
@c("Foo_init") // expected-error{{'@c' attribute cannot be applied to this declaration}}
|
||||
init() {}
|
||||
|
||||
@cdecl("Foo_deinit") // expected-error{{'@cdecl' attribute cannot be applied to this declaration}}
|
||||
@c("Foo_deinit") // expected-error{{'@c' attribute cannot be applied to this declaration}}
|
||||
deinit {}
|
||||
}
|
||||
|
||||
@cdecl("throwing") // expected-error{{raising errors from @cdecl functions is not supported}}
|
||||
@c("throwing") // expected-error{{raising errors from @c functions is not supported}}
|
||||
func throwing() throws { }
|
||||
|
||||
@cdecl("acceptedPointers")
|
||||
@c("acceptedPointers")
|
||||
func acceptedPointers(_ x: UnsafeMutablePointer<Int>,
|
||||
y: UnsafePointer<Int>,
|
||||
z: UnsafeMutableRawPointer,
|
||||
w: UnsafeRawPointer,
|
||||
u: OpaquePointer) {}
|
||||
|
||||
@cdecl("rejectedPointers")
|
||||
func rejectedPointers( // expected-error 6 {{global function cannot be marked '@cdecl' because the type of the parameter}}
|
||||
@c("rejectedPointers")
|
||||
func rejectedPointers( // expected-error 6 {{global function cannot be marked '@c' because the type of the parameter}}
|
||||
x: UnsafePointer<String>, // expected-note {{Swift structs cannot be represented in C}}
|
||||
y: CVaListPointer, // expected-note {{Swift structs cannot be represented in C}}
|
||||
z: UnsafeBufferPointer<Int>, // expected-note {{Swift structs cannot be represented in C}}
|
||||
@@ -111,93 +111,93 @@ func rejectedPointers( // expected-error 6 {{global function cannot be marked '@
|
||||
v: UnsafeRawBufferPointer, // expected-note {{Swift structs cannot be represented in C}}
|
||||
t: UnsafeMutableRawBufferPointer) {} // expected-note {{Swift structs cannot be represented in C}}
|
||||
|
||||
@cdecl("genericParam")
|
||||
@c("genericParam")
|
||||
func genericParam<I>(i: I) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because it has generic parameters}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because it has generic parameters}}
|
||||
|
||||
@cdecl("variadic")
|
||||
@c("variadic")
|
||||
func variadic(_: Int...) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because it has a variadic parameter}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because it has a variadic parameter}}
|
||||
|
||||
@cdecl("tupleParamEmpty")
|
||||
@c("tupleParamEmpty")
|
||||
func tupleParamEmpty(a: ()) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{empty tuple type cannot be represented in C}}
|
||||
|
||||
@cdecl("tupleParam")
|
||||
@c("tupleParam")
|
||||
func tupleParam(a: (Int, Float)) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{tuples cannot be represented in C}}
|
||||
|
||||
@cdecl("emptyTupleReturn")
|
||||
@c("emptyTupleReturn")
|
||||
func emptyTupleReturn() -> () {}
|
||||
|
||||
@cdecl("tupleReturn")
|
||||
@c("tupleReturn")
|
||||
func tupleReturn() -> (Int, Float) { (1, 2.0) }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because its result type cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because its result type cannot be represented in C}}
|
||||
// expected-note @-2 {{tuples cannot be represented in C}}
|
||||
|
||||
@cdecl("funcAcceptsThrowingFunc")
|
||||
@c("funcAcceptsThrowingFunc")
|
||||
func funcAcceptsThrowingFunc(fn: (String) throws -> Int) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{throwing function types cannot be represented in C}}
|
||||
|
||||
@cdecl("funcAcceptsThrowingFuncReturn")
|
||||
@c("funcAcceptsThrowingFuncReturn")
|
||||
func funcAcceptsThrowingFuncReturn() -> (String) throws -> Int { fatalError() }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because its result type cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because its result type cannot be represented in C}}
|
||||
// expected-note @-2 {{throwing function types cannot be represented in C}}
|
||||
|
||||
@cdecl("bar")
|
||||
@c("bar")
|
||||
func bar(f: (SwiftEnum) -> SwiftStruct) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{function types cannot be represented in C unless their parameters and returns can be}}
|
||||
|
||||
@cdecl("bas")
|
||||
@c("bas")
|
||||
func bas(f: (SwiftEnum) -> ()) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{function types cannot be represented in C unless their parameters and returns can be}}
|
||||
|
||||
@cdecl("zim")
|
||||
@c("zim")
|
||||
func zim(f: () -> SwiftStruct) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{function types cannot be represented in C unless their parameters and returns can be}}
|
||||
|
||||
@cdecl("zang")
|
||||
@c("zang")
|
||||
func zang(f: (SwiftEnum, SwiftStruct) -> ()) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{function types cannot be represented in C unless their parameters and returns can be}}
|
||||
|
||||
@cdecl("zang_zang")
|
||||
@c("zang_zang")
|
||||
func zangZang(f: (Int...) -> ()) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{function types cannot be represented in C unless their parameters and returns can be}}
|
||||
|
||||
@cdecl("array")
|
||||
@c("array")
|
||||
func array(i: [Int]) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift structs cannot be represented in C}}
|
||||
|
||||
class SwiftClass {}
|
||||
@cdecl("swiftClass")
|
||||
@c("swiftClass")
|
||||
func swiftClass(p: SwiftClass) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{classes cannot be represented in C}}
|
||||
|
||||
protocol SwiftProtocol {}
|
||||
@cdecl("swiftProtocol")
|
||||
@c("swiftProtocol")
|
||||
func swiftProtocol(p: SwiftProtocol) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{protocols cannot be represented in C}}
|
||||
|
||||
@cdecl("swiftErrorProtocol")
|
||||
@c("swiftErrorProtocol")
|
||||
func swiftErrorProtocol(e: Error) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{protocols cannot be represented in C}}
|
||||
|
||||
@cdecl("anyParam")
|
||||
@c("anyParam")
|
||||
func anyParam(e:Any) {}
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{protocols cannot be represented in C}}
|
||||
|
||||
@cdecl func swift_allocBox() {} // expected-warning {{symbol name 'swift_allocBox' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}
|
||||
@cdecl(swift_allocObject) func swift_allocObject_renamed() {} // expected-warning {{symbol name 'swift_allocObject' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}
|
||||
@c func swift_allocBox() {} // expected-warning {{symbol name 'swift_allocBox' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}
|
||||
@c(swift_allocObject) func swift_allocObject_renamed() {} // expected-warning {{symbol name 'swift_allocObject' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
@_cdecl("async") // expected-error{{@_cdecl global function cannot be asynchronous}}
|
||||
func asynchronous() async { }
|
||||
|
||||
@cdecl("async2") // expected-error{{@cdecl global function cannot be asynchronous}}
|
||||
@c("async2") // expected-error{{@c global function cannot be asynchronous}}
|
||||
func asynchronous2() async { }
|
||||
|
||||
@cdecl("asyncParam")
|
||||
@c("asyncParam")
|
||||
func asynchronousParam(fn: (String) async -> Int) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{'async' function types cannot be represented in C}}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
// REQUIRES: swift_feature_CDecl
|
||||
|
||||
@cdecl("cdecl_foo") func foo() { } // expected-error {{'@cdecl' requires '-enable-experimental-feature CDecl'}}
|
||||
@c("cdecl_foo") func foo() { } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
|
||||
var computed: Int {
|
||||
@cdecl("get_computed") get { return 0 } // expected-error {{'@cdecl' requires '-enable-experimental-feature CDecl'}}
|
||||
@cdecl("set_computed") set { } // expected-error {{'@cdecl' requires '-enable-experimental-feature CDecl'}}
|
||||
@c("get_computed") get { return 0 } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
@c("set_computed") set { } // expected-error {{'@c' requires '-enable-experimental-feature CDecl'}}
|
||||
}
|
||||
|
||||
@@ -9,34 +9,34 @@ import Foundation
|
||||
@objc
|
||||
class ObjCClass: NSObject { }
|
||||
|
||||
@cdecl("objcClassReturn") func objcClassReturn() -> ObjCClass { fatalError() }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because its result type cannot be represented in C}}
|
||||
@c("objcClassReturn") func objcClassReturn() -> ObjCClass { fatalError() }
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because its result type cannot be represented in C}}
|
||||
// expected-note @-2 {{classes cannot be represented in C}}
|
||||
|
||||
@cdecl("objcClassParams") func objcClassParams(a: ObjCClass, b: ObjCClass) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter 1 cannot be represented in C}}
|
||||
// expected-error @-2 {{global function cannot be marked '@cdecl' because the type of the parameter 2 cannot be represented in C}}
|
||||
@c("objcClassParams") func objcClassParams(a: ObjCClass, b: ObjCClass) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter 1 cannot be represented in C}}
|
||||
// expected-error @-2 {{global function cannot be marked '@c' because the type of the parameter 2 cannot be represented in C}}
|
||||
// expected-note @-3 2 {{classes cannot be represented in C}}
|
||||
|
||||
@objc
|
||||
protocol ObjCProtocol {}
|
||||
|
||||
@cdecl("objcProtocol") func objcProtocol(a: ObjCProtocol) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
@c("objcProtocol") func objcProtocol(a: ObjCProtocol) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{protocols cannot be represented in C}}
|
||||
|
||||
@objc
|
||||
enum ObjCEnum: Int { case A, B }
|
||||
@cdecl("objcEnumUseInCDecl") func objcEnumUseInCDecl(a: ObjCEnum) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@cdecl' cannot be represented in C}}
|
||||
@c("objcEnumUseInCDecl") func objcEnumUseInCDecl(a: ObjCEnum) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@c' because the type of the parameter cannot be represented in C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@c' cannot be represented in C}}
|
||||
|
||||
/// Objective-C accepts @cdecl enums.
|
||||
@cdecl("CEnum")
|
||||
/// Objective-C accepts @c enums.
|
||||
@c("CEnum")
|
||||
enum CEnum: Int { case A, B }
|
||||
@_cdecl("cdeclEnumUseInObjc") func cdeclEnumUseInObjc(a: CEnum) { }
|
||||
|
||||
enum SwiftEnum { case A, B }
|
||||
@_cdecl("swiftEnumUseInObjc") func swiftEnumUseInObjc(a: SwiftEnum) { }
|
||||
// expected-error @-1 {{global function cannot be marked '@_cdecl' because the type of the parameter cannot be represented in Objective-C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@cdecl' or '@objc' cannot be represented in Objective-C}}
|
||||
// expected-note @-2 {{Swift enums not marked '@c' or '@objc' cannot be represented in Objective-C}}
|
||||
|
||||
Reference in New Issue
Block a user