File: expose-swift-decls-to-cxx.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (125 lines) | stat: -rw-r--r-- 4,937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -module-name Expose -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr -emit-clang-header-path %t/expose.h
// RUN: %FileCheck %s < %t/expose.h

// RUN: %check-interop-cxx-header-in-clang(%t/expose.h -Wno-error=unused-function)

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -emit-module -module-name Expose -o %t
// RUN: %target-swift-frontend -parse-as-library %t/Expose.swiftmodule -typecheck -module-name Expose -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr -emit-clang-header-path %t/expose.h
// RUN: %FileCheck %s < %t/expose.h

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -enable-library-evolution -typecheck -emit-module-interface-path %t/Expose.swiftinterface -module-name Expose
// RUN: %target-swift-frontend -parse-as-library %t/Expose.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Expose -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr -emit-clang-header-path %t/expose.h
// RUN: %FileCheck %s < %t/expose.h

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -enable-library-evolution -typecheck -emit-module-interface-path %t/Expose.swiftinterface -module-name Expose
// RUN: %target-swift-frontend -parse-as-library %t/Expose.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Expose -clang-header-expose-decls=has-expose-attr-or-stdlib -emit-clang-header-path %t/expose.h
// RUN: %FileCheck %s < %t/expose.h

@_expose(Cxx)
public func exposed1() {
}

public func exposed2NotExposed() {
}

@_expose(Cxx)
public func exposed3() {
}

@_expose(Cxx, "exposed4")
public func exposed4Renamed() {
}

@_expose(Cxx)
public struct ExposedStruct {
    public var x: Int

    public func method() {}
}

public struct NotExposedStruct {
    public var x: Int
}

@_expose(Cxx, "ExposedStruct2")
public struct ExposedStructRenamed {
    public var y: Int

    @_expose(Cxx)
    public init() { y = 42; prop = 0; prop2 = 0; }

    @_expose(Cxx, "initWithValue")
    public init(why x: Int) { y = x; prop = 0; prop2 = 0; }

    @_expose(Cxx, "renamedProp")
    public var prop: Int

    @_expose(Cxx, "prop3")
    public let prop2: Int

    @_expose(Cxx, "renamedMethod")
    public func method() {}

    public func getNonExposedStruct() -> NotExposedStruct {
        return NotExposedStruct(x: 2)
    }
    // FIXME: if 'getNonExposedStruct' has explicit @_expose we should error in Sema.

    public func passNonExposedStruct(_ x: NotExposedStruct) {
    }
    // FIXME: if 'passNonExposedStruct' has explicit @_expose we should error in Sema.
}

@_expose(Cxx)
public final class ExposedClass {
    public func method() {}
}

// CHECK: class SWIFT_SYMBOL("{{.*}}") ExposedClass final
// CHECK: class SWIFT_SYMBOL("{{.*}}") ExposedStruct final {
// CHECK: class SWIFT_SYMBOL("{{.*}}") ExposedStruct2 final {
// CHECK: ExposedStruct2(ExposedStruct2 &&)
// CHECK: }
// CHECK-NEXT: swift::Int getY() const SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: void setY(swift::Int value) SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: static SWIFT_INLINE_THUNK ExposedStruct2 init() SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: static SWIFT_INLINE_THUNK ExposedStruct2 initWithValue(swift::Int x) SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: swift::Int getRenamedProp() const SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: void setRenamedProp(swift::Int value) SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: swift::Int getProp3() const SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: void renamedMethod() const SWIFT_SYMBOL("{{.*}}");
// CHECK-NEXT: private:

// CHECK: SWIFT_INLINE_THUNK void exposed1() noexcept SWIFT_SYMBOL("{{.*}}") {
// CHECK-NEXT:   _impl::$s6Expose8exposed1yyF();
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK void exposed3() noexcept SWIFT_SYMBOL("{{.*}}") {
// CHECK-NEXT:   _impl::$s6Expose8exposed3yyF();
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK void exposed4() noexcept SWIFT_SYMBOL("{{.*}}") {
// CHECK-NEXT:   _impl::$s6Expose15exposed4RenamedyyF();
// CHECK-NEXT: }

// CHECK: void ExposedClass::method()
// CHECK: swift::Int ExposedStruct::getX() const {
// CHECK: void ExposedStruct::setX(swift::Int value) {
// CHECK: void ExposedStruct::method() const {
// CHECK: swift::Int ExposedStruct2::getY() const {
// CHECK: void ExposedStruct2::setY(swift::Int value) {
// CHECK: ExposedStruct2 ExposedStruct2::init() {
// CHECK: ExposedStruct2 ExposedStruct2::initWithValue(swift::Int x) {
// CHECK: swift::Int ExposedStruct2::getRenamedProp() const {
// CHECK: void ExposedStruct2::setRenamedProp(swift::Int value) {
// CHECK: swift::Int ExposedStruct2::getProp3() const {
// CHECK: void ExposedStruct2::renamedMethod() const {

// CHECK-NOT: NonExposedStruct