|
1 |
| -//===--- PlatformKind.h - Swift Language Platform Kinds ---------*- C++ -*-===// |
| 1 | +//===--- AST/PlatformKind.h - Swift Language Platform Kinds -----*- C++ -*-===// |
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See https://swift.org/LICENSE.txt for license information
|
9 | 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 |
| -// |
13 |
| -// This file defines the platform kinds for API availability. |
14 |
| -// |
| 12 | +/// |
| 13 | +/// This file defines the platform kinds for API availability. |
| 14 | +/// |
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 | 17 | #ifndef SWIFT_AST_PLATFORM_KIND_H
|
18 | 18 | #define SWIFT_AST_PLATFORM_KIND_H
|
19 | 19 |
|
20 |
| -#include "swift/Basic/LLVM.h" |
21 |
| -#include "swift/Config.h" |
22 |
| -#include "llvm/ADT/StringRef.h" |
23 |
| -#include "llvm/Support/VersionTuple.h" |
24 |
| -#include "llvm/TargetParser/Triple.h" |
25 |
| -#include <optional> |
| 20 | +/// This header is included in a bridging header. Be *very* careful with what |
| 21 | +/// you include here! See include caveats in `ASTBridging.h`. |
| 22 | +#include "swift/Basic/SwiftBridging.h" |
| 23 | +#include <stdint.h> |
26 | 24 |
|
27 | 25 | namespace swift {
|
28 | 26 |
|
29 |
| -class LangOptions; |
30 |
| - |
31 | 27 | /// Available platforms for the availability attribute.
|
32 |
| -enum class PlatformKind: uint8_t { |
| 28 | +enum class ENUM_EXTENSIBILITY_ATTR(closed) PlatformKind : uint8_t { |
33 | 29 | none,
|
34 | 30 | #define AVAILABILITY_PLATFORM(X, PrettyName) X,
|
35 | 31 | #include "swift/AST/PlatformKinds.def"
|
36 | 32 | };
|
37 | 33 |
|
38 |
| -/// Returns the short string representing the platform, suitable for |
39 |
| -/// use in availability specifications (e.g., "OSX"). |
40 |
| -StringRef platformString(PlatformKind platform); |
41 |
| - |
42 |
| -/// Returns the platform kind corresponding to the passed-in short platform name |
43 |
| -/// or None if such a platform kind does not exist. |
44 |
| -std::optional<PlatformKind> platformFromString(StringRef Name); |
45 |
| - |
46 |
| -/// Safely converts the given unsigned value to a valid \c PlatformKind value or |
47 |
| -/// \c nullopt otherwise. |
48 |
| -std::optional<PlatformKind> platformFromUnsigned(unsigned value); |
49 |
| - |
50 |
| -/// Returns a valid platform string that is closest to the candidate string |
51 |
| -/// based on edit distance. Returns \c None if the closest valid platform |
52 |
| -/// distance is not within a minimum threshold. |
53 |
| -std::optional<StringRef> closestCorrectedPlatformString(StringRef candidate); |
54 |
| - |
55 |
| -/// Returns a human-readable version of the platform name as a string, suitable |
56 |
| -/// for emission in diagnostics (e.g., "macOS"). |
57 |
| -StringRef prettyPlatformString(PlatformKind platform); |
58 |
| - |
59 |
| -/// Returns the base platform for an application-extension platform. For example |
60 |
| -/// `iOS` would be returned for `iOSApplicationExtension`. Returns `None` for |
61 |
| -/// platforms which are not application extension platforms. |
62 |
| -std::optional<PlatformKind> |
63 |
| -basePlatformForExtensionPlatform(PlatformKind Platform); |
64 |
| - |
65 |
| -/// Returns true if \p Platform represents and application extension platform, |
66 |
| -/// e.g. `iOSApplicationExtension`. |
67 |
| -inline bool isApplicationExtensionPlatform(PlatformKind Platform) { |
68 |
| - return basePlatformForExtensionPlatform(Platform).has_value(); |
69 |
| -} |
70 |
| - |
71 |
| -/// Returns whether the passed-in platform is active, given the language |
72 |
| -/// options. A platform is active if either it is the target platform or its |
73 |
| -/// AppExtension variant is the target platform. For example, OS X is |
74 |
| -/// considered active when the target operating system is OS X and app extension |
75 |
| -/// restrictions are enabled, but OSXApplicationExtension is not considered |
76 |
| -/// active when the target platform is OS X and app extension restrictions are |
77 |
| -/// disabled. PlatformKind::none is always considered active. |
78 |
| -/// If ForTargetVariant is true then for zippered builds the target-variant |
79 |
| -/// triple will be used rather than the target to determine whether the |
80 |
| -/// platform is active. |
81 |
| -bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts, |
82 |
| - bool ForTargetVariant = false, bool ForRuntimeQuery = false); |
83 |
| - |
84 |
| -/// Returns the target platform for the given language options. |
85 |
| -PlatformKind targetPlatform(const LangOptions &LangOpts); |
86 |
| - |
87 |
| -/// Returns the target variant platform for the given language options. |
88 |
| -PlatformKind targetVariantPlatform(const LangOptions &LangOpts); |
89 |
| - |
90 |
| -/// Returns true when availability attributes from the "parent" platform |
91 |
| -/// should also apply to the "child" platform for declarations without |
92 |
| -/// an explicit attribute for the child. |
93 |
| -bool inheritsAvailabilityFromPlatform(PlatformKind Child, PlatformKind Parent); |
94 |
| - |
95 |
| -/// Returns the LLVM triple OS type for the given platform, if there is one. |
96 |
| -std::optional<llvm::Triple::OSType> |
97 |
| -tripleOSTypeForPlatform(PlatformKind platform); |
98 |
| - |
99 |
| -llvm::VersionTuple canonicalizePlatformVersion( |
100 |
| - PlatformKind platform, const llvm::VersionTuple &version); |
101 |
| - |
102 |
| -/// Returns true if \p Platform should be considered to be SPI and therefore not |
103 |
| -/// printed in public `.swiftinterface` files, for example. |
104 |
| -bool isPlatformSPI(PlatformKind Platform); |
105 |
| - |
106 | 34 | } // end namespace swift
|
107 | 35 |
|
108 |
| -#endif |
| 36 | +#endif // SWIFT_AST_PLATFORM_KIND_H |
0 commit comments