|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend %s -typecheck -module-name Properties -clang-header-expose-public-decls -emit-clang-header-path %t/properties.h |
| 3 | +// RUN: %FileCheck %s < %t/properties.h |
| 4 | + |
| 5 | +// RUN: %check-interop-cxx-header-in-clang(%t/properties.h) |
| 6 | + |
| 7 | +public struct FirstSmallStruct { |
| 8 | + public var x: UInt32 |
| 9 | +} |
| 10 | + |
| 11 | +// CHECK: class FirstSmallStruct final { |
| 12 | +// CHECK: public: |
| 13 | +// CHECK: inline FirstSmallStruct(FirstSmallStruct &&) = default; |
| 14 | +// CHECK-NEXT: inline uint32_t getX() const; |
| 15 | +// CHECK-NEXT: inline void setX(uint32_t value); |
| 16 | +// CHECK-NEXT: private: |
| 17 | + |
| 18 | +// CHECK: inline uint32_t FirstSmallStruct::getX() const { |
| 19 | +// CHECK-NEXT: return _impl::$s10Properties16FirstSmallStructV1xs6UInt32Vvg(_impl::swift_interop_passDirect_Properties_FirstSmallStruct(_getOpaquePointer())); |
| 20 | +// CHECK-NEXT: } |
| 21 | +// CHECK-NEXT: inline void FirstSmallStruct::setX(uint32_t value) { |
| 22 | +// CHECK-NEXT: return _impl::$s10Properties16FirstSmallStructV1xs6UInt32Vvs(value, _getOpaquePointer()); |
| 23 | +// CHECK-NEXT: } |
| 24 | + |
| 25 | +public struct LargeStruct { |
| 26 | + public var x1, x2, x3, x4, x5, x6: Int |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK: class LargeStruct final { |
| 30 | +// CHECK: public: |
| 31 | +// CHECK: inline LargeStruct(LargeStruct &&) = default; |
| 32 | +// CHECK-NEXT: inline swift::Int getX1() const; |
| 33 | +// CHECK-NEXT: inline void setX1(swift::Int value); |
| 34 | +// CHECK-NEXT: inline swift::Int getX2() const; |
| 35 | +// CHECK-NEXT: inline void setX2(swift::Int value); |
| 36 | +// CHECK-NEXT: inline swift::Int getX3() const; |
| 37 | +// CHECK-NEXT: inline void setX3(swift::Int value); |
| 38 | +// CHECK-NEXT: inline swift::Int getX4() const; |
| 39 | +// CHECK-NEXT: inline void setX4(swift::Int value); |
| 40 | +// CHECK-NEXT: inline swift::Int getX5() const; |
| 41 | +// CHECK-NEXT: inline void setX5(swift::Int value); |
| 42 | +// CHECK-NEXT: inline swift::Int getX6() const; |
| 43 | +// CHECK-NEXT: inline void setX6(swift::Int value); |
| 44 | +// CHECK-NEXT: private: |
| 45 | + |
| 46 | +// CHECK: inline swift::Int LargeStruct::getX1() const { |
| 47 | +// CHECK-NEXT: return _impl::$s10Properties11LargeStructV2x1Sivg(_getOpaquePointer()); |
| 48 | +// CHECK-NEXT: } |
| 49 | +// CHECK-NEXT: inline void LargeStruct::setX1(swift::Int value) { |
| 50 | +// CHECK-NEXT: return _impl::$s10Properties11LargeStructV2x1Sivs(value, _getOpaquePointer()); |
| 51 | +// CHECK-NEXT: } |
| 52 | + |
| 53 | +public struct LargeStructWithProps { |
| 54 | + public var storedLargeStruct: LargeStruct |
| 55 | + public var storedSmallStruct: FirstSmallStruct |
| 56 | +} |
| 57 | + |
| 58 | +// CHECK: class LargeStructWithProps final { |
| 59 | +// CHECK-NEXT: public: |
| 60 | +// CHECK: inline LargeStruct getStoredLargeStruct() const; |
| 61 | +// CHECK-NEXT: inline void setStoredLargeStruct(const LargeStruct& value); |
| 62 | +// CHECK-NEXT: inline FirstSmallStruct getStoredSmallStruct() const; |
| 63 | +// CHECK-NEXT: inline void setStoredSmallStruct(const FirstSmallStruct& value); |
| 64 | + |
| 65 | +// CHECK: inline LargeStruct LargeStructWithProps::getStoredLargeStruct() const { |
| 66 | +// CHECK-NEXT: return _impl::_impl_LargeStruct::returnNewValue([&](void * _Nonnull result) { |
| 67 | +// CHECK-NEXT: _impl::$s10Properties20LargeStructWithPropsV06storedbC0AA0bC0Vvg(result, _getOpaquePointer()); |
| 68 | +// CHECK-NEXT: }); |
| 69 | +// CHECK-NEXT: } |
| 70 | +// CHECK-NEXT: inline void LargeStructWithProps::setStoredLargeStruct(const LargeStruct& value) { |
| 71 | +// CHECK-NEXT: return _impl::$s10Properties20LargeStructWithPropsV06storedbC0AA0bC0Vvs(_impl::_impl_LargeStruct::getOpaquePointer(value), _getOpaquePointer()); |
| 72 | +// CHECK-NEXT: } |
| 73 | +// CHECK-NEXT: inline FirstSmallStruct LargeStructWithProps::getStoredSmallStruct() const { |
| 74 | +// CHECK-NEXT: return _impl::_impl_FirstSmallStruct::returnNewValue([&](char * _Nonnull result) { |
| 75 | +// CHECK-NEXT: _impl::swift_interop_returnDirect_Properties_FirstSmallStruct(result, _impl::$s10Properties20LargeStructWithPropsV011storedSmallC0AA05FirstgC0Vvg(_getOpaquePointer())); |
| 76 | +// CHECK-NEXT: }); |
| 77 | +// CHECK-NEXT: } |
| 78 | +// CHECK-NEXT: inline void LargeStructWithProps::setStoredSmallStruct(const FirstSmallStruct& value) { |
| 79 | +// CHECK-NEXT: return _impl::$s10Properties20LargeStructWithPropsV011storedSmallC0AA05FirstgC0Vvs(_impl::swift_interop_passDirect_Properties_FirstSmallStruct(_impl::_impl_FirstSmallStruct::getOpaquePointer(value)), _getOpaquePointer()); |
| 80 | +// CHECK-NEXT: } |
| 81 | + |
| 82 | +public struct SmallStructWithProps { |
| 83 | + public var storedInt: UInt32 |
| 84 | + public var computedInt: Int { |
| 85 | + get { |
| 86 | + return Int(storedInt) + 2 |
| 87 | + } set { |
| 88 | + storedInt = UInt32(newValue - 2) |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + public var largeStructWithProps: LargeStructWithProps { |
| 93 | + get { |
| 94 | + return LargeStructWithProps(storedLargeStruct: LargeStruct(x1: computedInt * 2, x2: 1, x3: 2, x4: 3, x5: 4, x6: 5), |
| 95 | + storedSmallStruct:FirstSmallStruct(x: 0xFAE)) |
| 96 | + } set { |
| 97 | + print("SET: \(newValue.storedLargeStruct), \(newValue.storedSmallStruct)") |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +// CHECK: class SmallStructWithProps final { |
| 103 | +// CHECK: public: |
| 104 | +// CHECK: inline SmallStructWithProps(SmallStructWithProps &&) = default; |
| 105 | +// CHECK-NEXT: inline uint32_t getStoredInt() const; |
| 106 | +// CHECK-NEXT: inline void setStoredInt(uint32_t value); |
| 107 | +// CHECK-NEXT: inline swift::Int getComputedInt() const; |
| 108 | +// CHECK-NEXT: inline void setComputedInt(swift::Int newValue); |
| 109 | +// CHECK-NEXT: inline LargeStructWithProps getLargeStructWithProps() const; |
| 110 | +// CHECK-NEXT: inline void setLargeStructWithProps(const LargeStructWithProps& newValue); |
| 111 | +// CHECK-NEXT: private: |
| 112 | + |
| 113 | +// CHECK: inline uint32_t SmallStructWithProps::getStoredInt() const { |
| 114 | +// CHECK-NEXT: return _impl::$s10Properties20SmallStructWithPropsV9storedInts6UInt32Vvg(_impl::swift_interop_passDirect_Properties_SmallStructWithProps(_getOpaquePointer())); |
| 115 | +// CHECK-NEXT: } |
| 116 | +// CHECK-NEXT: inline void SmallStructWithProps::setStoredInt(uint32_t value) { |
| 117 | +// CHECK-NEXT: return _impl::$s10Properties20SmallStructWithPropsV9storedInts6UInt32Vvs(value, _getOpaquePointer()); |
| 118 | +// CHECK-NEXT: } |
| 119 | +// CHECK-NEXT: inline swift::Int SmallStructWithProps::getComputedInt() const { |
| 120 | +// CHECK-NEXT: return _impl::$s10Properties20SmallStructWithPropsV11computedIntSivg(_impl::swift_interop_passDirect_Properties_SmallStructWithProps(_getOpaquePointer())); |
| 121 | +// CHECK-NEXT: } |
| 122 | +// CHECK-NEXT: inline void SmallStructWithProps::setComputedInt(swift::Int newValue) { |
| 123 | +// CHECK-NEXT: return _impl::$s10Properties20SmallStructWithPropsV11computedIntSivs(newValue, _getOpaquePointer()); |
| 124 | +// CHECK-NEXT: } |
| 125 | +// CHECK-NEXT: inline LargeStructWithProps SmallStructWithProps::getLargeStructWithProps() const { |
| 126 | +// CHECK-NEXT: return _impl::_impl_LargeStructWithProps::returnNewValue([&](void * _Nonnull result) { |
| 127 | +// CHECK-NEXT: _impl::$s10Properties20SmallStructWithPropsV05largecdE0AA05LargecdE0Vvg(result, _impl::swift_interop_passDirect_Properties_SmallStructWithProps(_getOpaquePointer())); |
| 128 | +// CHECK-NEXT: }); |
| 129 | +// CHECK-NEXT: } |
| 130 | +// CHECK-NEXT: inline void SmallStructWithProps::setLargeStructWithProps(const LargeStructWithProps& newValue) { |
| 131 | +// CHECK-NEXT: return _impl::$s10Properties20SmallStructWithPropsV05largecdE0AA05LargecdE0Vvs(_impl::_impl_LargeStructWithProps::getOpaquePointer(newValue), _getOpaquePointer()); |
| 132 | +// CHECK-NEXT: } |
| 133 | + |
| 134 | +public func createSmallStructWithProps() -> SmallStructWithProps { |
| 135 | + return SmallStructWithProps(storedInt: 21) |
| 136 | +} |
| 137 | + |
| 138 | +public func createFirstSmallStruct(_ x: UInt32) -> FirstSmallStruct { |
| 139 | + return FirstSmallStruct(x: x) |
| 140 | +} |
0 commit comments