mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
It is really involved to change how methods and classes are emitted into the header so this patch introduces the impression of nested structs through using statements and still emits the structs themselves as top level structs. It emits them in their own namespace to avoid name collisions. This patch also had to change some names to be fully qualified to avoid some name lookup errors in case of nested structs. Moreover, nesting level of 3 and above requires C++17 because it relies on nested namespaces. Only nested structs are supported, not nested classes. Since this patch is already started to grow quite big, I decided to put it out for reviews and plan to address some of the shortcomings in a follow-up PR. rdar://118793469
61 lines
2.6 KiB
Swift
61 lines
2.6 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend %s -typecheck -module-name Operators -clang-header-expose-decls=all-public -emit-clang-header-path %t/operators.h
|
|
// RUN: %FileCheck %s < %t/operators.h
|
|
|
|
// RUN: %check-interop-cxx-header-in-clang(%t/operators.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
|
|
// RUN: %check-interop-cxx-header-in-clang(%t/operators.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -std=c++23)
|
|
|
|
// CHECK-LABEL: namespace Operators SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Operators") {
|
|
|
|
// CHECK-LABEL: namespace _impl {
|
|
|
|
// CHECK: SWIFT_EXTERN bool $s9Operators2eeoiySbAA6IntBoxV_ADtF(struct swift_interop_passStub_Operators_uint32_t_0_4 lhs, struct swift_interop_passStub_Operators_uint32_t_0_4 rhs) SWIFT_NOEXCEPT SWIFT_CALL; // ==(_:_:)
|
|
|
|
// CHECK: }
|
|
|
|
public struct IntBox {
|
|
var x: CInt
|
|
|
|
public subscript(x: CInt) -> CInt {
|
|
return x
|
|
}
|
|
|
|
public subscript(x: CInt, _: CInt) -> CInt {
|
|
return x
|
|
}
|
|
}
|
|
|
|
public struct CustomArray<Element> where Element : ~Copyable {
|
|
private var buffer: UnsafeMutableBufferPointer<Element>
|
|
|
|
public subscript(index: Int) -> Element {
|
|
_read {
|
|
yield buffer[index]
|
|
}
|
|
nonmutating _modify {
|
|
yield &buffer[index]
|
|
}
|
|
}
|
|
}
|
|
|
|
// CHECK: #if __cplusplus >= 202302L
|
|
// CHECK-NEXT: SWIFT_INLINE_THUNK int operator [](int x, int _2) const SWIFT_SYMBOL("s:9Operators6IntBoxVys5Int32VAE_AEtcig");
|
|
// CHECK-NEXT: #endif // #if __cplusplus >= 202302L
|
|
|
|
public func -(lhs: IntBox, rhs: IntBox) -> CInt {
|
|
return lhs.x - rhs.x
|
|
}
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK int operator-(const IntBox& lhs, const IntBox& rhs) noexcept SWIFT_SYMBOL("s:9Operators1soiys5Int32VAA6IntBoxV_AFtF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK-NEXT: return Operators::_impl::$s9Operators1soiys5Int32VAA6IntBoxV_AFtF(Operators::_impl::swift_interop_passDirect_Operators_uint32_t_0_4(Operators::_impl::_impl_IntBox::getOpaquePointer(lhs)), Operators::_impl::swift_interop_passDirect_Operators_uint32_t_0_4(Operators::_impl::_impl_IntBox::getOpaquePointer(rhs)));
|
|
// CHECK-NEXT: }
|
|
|
|
public func ==(lhs: IntBox, rhs: IntBox) -> Bool {
|
|
return lhs.x == rhs.x
|
|
}
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK bool operator==(const IntBox& lhs, const IntBox& rhs) noexcept SWIFT_SYMBOL("s:9Operators2eeoiySbAA6IntBoxV_ADtF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK-NEXT: return Operators::_impl::$s9Operators2eeoiySbAA6IntBoxV_ADtF(Operators::_impl::swift_interop_passDirect_Operators_uint32_t_0_4(Operators::_impl::_impl_IntBox::getOpaquePointer(lhs)), Operators::_impl::swift_interop_passDirect_Operators_uint32_t_0_4(Operators::_impl::_impl_IntBox::getOpaquePointer(rhs)));
|
|
// CHECK-NEXT: }
|
|
|