|
| 1 | +//===--- Basic/SwiftBridging.h ----------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +/// |
| 13 | +/// This is a wrapper around `<swift/bridging>` that redefines `SWIFT_NAME` to |
| 14 | +/// accept a string literal, and some other macros in case the header is |
| 15 | +/// unavailable (e.g. during bootstrapping). String literals enable us to |
| 16 | +/// properly format the long Swift declaration names that many of our bridging |
| 17 | +/// functions have. |
| 18 | +/// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | + |
| 21 | +#ifndef SWIFT_BASIC_SWIFT_BRIDGING_H |
| 22 | +#define SWIFT_BASIC_SWIFT_BRIDGING_H |
| 23 | + |
| 24 | +#include "swift/Basic/Compiler.h" |
| 25 | +#if __has_include(<swift/bridging>) |
| 26 | +#include <swift/bridging> |
| 27 | +#else |
| 28 | + |
| 29 | +#if __has_attribute(swift_attr) |
| 30 | + |
| 31 | +/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of |
| 32 | +/// all of the objects it references. Such type should not reference any |
| 33 | +/// objects whose lifetime is controlled externally. This annotation allows |
| 34 | +/// Swift to import methods that return a `class` or `struct` type that is |
| 35 | +/// annotated with this macro. |
| 36 | +#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned"))) |
| 37 | + |
| 38 | +#else // #if __has_attribute(swift_attr) |
| 39 | + |
| 40 | +#define SWIFT_SELF_CONTAINED |
| 41 | +#define SWIFT_COMPUTED_PROPERTY |
| 42 | + |
| 43 | +#endif // #if __has_attribute(swift_attr) |
| 44 | + |
| 45 | +#endif // #if __has_include(<swift/bridging>) |
| 46 | + |
| 47 | +// Redefine SWIFT_NAME. |
| 48 | +#ifdef SWIFT_NAME |
| 49 | +#undef SWIFT_NAME |
| 50 | +#endif |
| 51 | + |
| 52 | +#if __has_attribute(swift_name) |
| 53 | +/// Specifies a name that will be used in Swift for this declaration instead of |
| 54 | +/// its original name. |
| 55 | +#define SWIFT_NAME(_name) __attribute__((swift_name(_name))) |
| 56 | +#else |
| 57 | +#define SWIFT_NAME(_name) |
| 58 | +#endif |
| 59 | + |
| 60 | +#endif // SWIFT_BASIC_SWIFT_BRIDGING_H |
| 61 | + |
0 commit comments