|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 | import SwiftSyntax
|
13 | 13 |
|
| 14 | +/// Describes the ordering of a sequence of bytes that make up a word of |
| 15 | +/// storage for a particular architecture. |
14 | 16 | public enum Endianness: String {
|
| 17 | + /// Little endian, meaning that the least significant byte of a word is |
| 18 | + /// stored at the lowest address. |
15 | 19 | case little
|
| 20 | + |
| 21 | + /// Big endian, meaning that the most significant byte of a word is stored |
| 22 | + /// at the lowest address. |
16 | 23 | case big
|
17 | 24 | }
|
18 | 25 |
|
19 |
| -/// Describes the requested version of a module |
| 26 | +/// Describes the requested version of a module. |
20 | 27 | public enum CanImportVersion {
|
21 | 28 | /// Any version of the module will suffice.
|
22 | 29 | case unversioned
|
@@ -45,48 +52,216 @@ public protocol BuildConfiguration {
|
45 | 52 | ///
|
46 | 53 | /// Custom build conditions can be set by the `-D` command line option to
|
47 | 54 | /// the Swift compiler. For example, `-DDEBUG` sets the custom condition
|
48 |
| - /// named `DEBUG`. |
| 55 | + /// named `DEBUG`, which could be checked with, e.g., |
| 56 | + /// |
| 57 | + /// ``` |
| 58 | + /// #if DEBUG |
| 59 | + /// // ... |
| 60 | + /// #endif |
| 61 | + /// ``` |
| 62 | + /// |
| 63 | + /// - Parameters: |
| 64 | + /// - name: The name of the custom build condition being checked (e.g., |
| 65 | + /// `DEBUG`. |
| 66 | + /// - syntax: The syntax node for the name of the custom build |
| 67 | + /// configuration. |
| 68 | + /// - Returns: Whether the custom condition is set. |
49 | 69 | func isCustomConditionSet(name: String, syntax: ExprSyntax) -> Bool?
|
50 | 70 |
|
51 | 71 | /// Determine whether the given feature is enabled.
|
52 | 72 | ///
|
53 | 73 | /// Features are determined by the Swift compiler, language mode, and other
|
54 |
| - /// options such as `--enable-upcoming-feature`. |
| 74 | + /// options such as `--enable-upcoming-feature`, and can be checked with |
| 75 | + /// the `hasFeature` syntax, e.g., |
| 76 | + /// |
| 77 | + /// ``` |
| 78 | + /// #if hasFeature(VariadicGenerics) |
| 79 | + /// // ... |
| 80 | + /// #endif |
| 81 | + /// ``` |
| 82 | + /// |
| 83 | + /// - Parameters: |
| 84 | + /// - name: The name of the feature being checked. |
| 85 | + /// - syntax: The syntax node for the `hasFeature(<name>)`. |
| 86 | + /// - Returns: Whether the requested feature is available. |
55 | 87 | func hasFeature(name: String, syntax: ExprSyntax) -> Bool?
|
56 | 88 |
|
57 | 89 | /// Determine whether the given attribute is available.
|
58 | 90 | ///
|
59 |
| - /// Attributes are determined by the Swift compiler. |
| 91 | + /// Attributes are determined by the Swift compiler. They can be checked |
| 92 | + /// with `hasAttribute` syntax, e.g., |
| 93 | + /// |
| 94 | + /// ``` |
| 95 | + /// #if hasAttribute(available) |
| 96 | + /// // ... |
| 97 | + /// #endif |
| 98 | + /// ``` |
| 99 | + /// |
| 100 | + /// - Parameters: |
| 101 | + /// - name: The name of the attribute being queried. |
| 102 | + /// - syntax: The syntax node for the `hasAttribute(<name>)`. |
| 103 | + /// - Returns: Whether the requested attribute is supported. |
60 | 104 | func hasAttribute(name: String, syntax: ExprSyntax) -> Bool?
|
61 | 105 |
|
62 | 106 | /// Determine whether a module with the given import path can be imported,
|
63 | 107 | /// with additional version information.
|
| 108 | + /// |
| 109 | + /// The availability of a module for import can be checked with `canImport`, |
| 110 | + /// e.g., |
| 111 | + /// |
| 112 | + /// ``` |
| 113 | + /// #if canImport(UIKit) |
| 114 | + /// // ... |
| 115 | + /// #endif |
| 116 | + /// ``` |
| 117 | + /// |
| 118 | + /// There is an experimental syntax for providing required module version |
| 119 | + /// information, which will translate into the `version` argument. |
| 120 | + /// |
| 121 | + /// - Parameters: |
| 122 | + /// - importPath: A nonempty sequence of identifiers describing the |
| 123 | + /// imported module, which was written in source as a dotted sequence, |
| 124 | + /// e.g., `UIKit.UIViewController` will be passed in as the import path |
| 125 | + /// array `["UIKit", "UIViewController"]`. |
| 126 | + /// - version: The version restriction on the imported module. For the |
| 127 | + /// normal `canImport(<import-path>)` syntax, this will always be |
| 128 | + /// `CanImportVersion.unversioned`. |
| 129 | + /// - syntax: The syntax node for the `canImport` expression. |
| 130 | + /// - Returns: Whether the module can be imported. |
64 | 131 | func canImport(importPath: [String], version: CanImportVersion, syntax: ExprSyntax) -> Bool?
|
65 | 132 |
|
66 | 133 | /// Determine whether the given name is the active target OS (e.g., Linux, iOS).
|
| 134 | + /// |
| 135 | + /// The target operating system can be queried with `os(<name>)`, e.g., |
| 136 | + /// |
| 137 | + /// ``` |
| 138 | + /// #if os(Linux) |
| 139 | + /// // Linux-specific implementation |
| 140 | + /// #endif |
| 141 | + /// |
| 142 | + /// - Parameters: |
| 143 | + /// - name: The name of the operating system being queried, such as `Linux`, |
| 144 | + /// `Windows`, `macOS`, etc. |
| 145 | + /// - syntax: The syntax node for the `os(<name>)` expression. |
| 146 | + /// - Returns: Whether the given operating system name is the target operating |
| 147 | + /// system, i.e., the operating system for which code is being generated. |
67 | 148 | func isActiveTargetOS(name: String, syntax: ExprSyntax) -> Bool?
|
68 | 149 |
|
69 |
| - /// Determine whether the given name is the active target architecture (e.g., x86_64, arm64) |
| 150 | + /// Determine whether the given name is the active target architecture |
| 151 | + /// (e.g., x86_64, arm64). |
| 152 | + /// |
| 153 | + /// The target processor architecture can be queried with `arch(<name>)`, e.g., |
| 154 | + /// |
| 155 | + /// ``` |
| 156 | + /// #if arch(x86_64) |
| 157 | + /// // 64-bit x86 Intel-specific code |
| 158 | + /// #endif |
| 159 | + /// |
| 160 | + /// - Parameters: |
| 161 | + /// - name: The name of the target architecture to check. |
| 162 | + /// - syntax: The syntax node for the `arch(<name>)` expression. |
| 163 | + /// - Returns: Whether the given processor architecture is the target |
| 164 | + /// architecture. |
70 | 165 | func isActiveTargetArchitecture(name: String, syntax: ExprSyntax) -> Bool?
|
71 | 166 |
|
72 | 167 | /// Determine whether the given name is the active target environment (e.g., simulator)
|
| 168 | + /// |
| 169 | + /// The target environment can be queried with `targetEnvironment(<name>)`, |
| 170 | + /// e.g., |
| 171 | + /// |
| 172 | + /// ``` |
| 173 | + /// #if targetEnvironment(simulator) |
| 174 | + /// // Simulator-specific code |
| 175 | + /// #endif |
| 176 | + /// |
| 177 | + /// - Parameters: |
| 178 | + /// - name: The name of the target environment to check. |
| 179 | + /// - syntax: The syntax node for the `targetEnvironment(<name>)` |
| 180 | + /// expression. |
| 181 | + /// - Returns: Whether the target platform is for a specific environment, |
| 182 | + /// such as a simulator or emulator. |
73 | 183 | func isActiveTargetEnvironment(name: String, syntax: ExprSyntax) -> Bool?
|
74 | 184 |
|
75 | 185 | /// Determine whether the given name is the active target runtime (e.g., _ObjC vs. _Native)
|
| 186 | + /// |
| 187 | + /// The target runtime can only be queried by an experimental syntax |
| 188 | + /// `_runtime(<name>)`, e.g., |
| 189 | + /// |
| 190 | + /// #if _runtime(_ObjC) |
| 191 | + /// // Code that depends on Swift being built for use with the Objective-C |
| 192 | + /// // runtime, e.g., on Apple platforms. |
| 193 | + /// #endif |
| 194 | + /// |
| 195 | + /// The only other runtime is "none", when Swift isn't tying into any other |
| 196 | + /// specific runtime. |
| 197 | + /// |
| 198 | + /// - Parameters: |
| 199 | + /// - name: The name of the runtime. |
| 200 | + /// - syntax: The syntax node for the `_runtime(<name>)` expression. |
| 201 | + /// - Returns: Whether the target runtime matches the given name. |
76 | 202 | func isActiveTargetRuntime(name: String, syntax: ExprSyntax) -> Bool?
|
77 | 203 |
|
78 | 204 | /// Determine whether the given name is the active target pointer authentication scheme (e.g., arm64e).
|
| 205 | + /// |
| 206 | + /// The target pointer authentication scheme describes how pointers are |
| 207 | + /// signed, as a security mitigation. This scheme can only be queried by |
| 208 | + /// an experimental syntax `_ptrath(<name>)`, e.g., |
| 209 | + /// |
| 210 | + /// ``` |
| 211 | + /// #if _ptrauth(arm64e) |
| 212 | + /// // Special logic for arm64e pointer signing |
| 213 | + /// #endif |
| 214 | + /// |
| 215 | + /// - Parameters: |
| 216 | + /// - name: The name of the pointer authentication scheme to check. |
| 217 | + /// - syntax: The syntax node for the `_ptrauth(<name>)` expression. |
| 218 | + /// - Returns: Whether the code generated for the target will use the given |
| 219 | + /// pointer authentication scheme. |
79 | 220 | func isActiveTargetPointerAuthentication(name: String, syntax: ExprSyntax) -> Bool?
|
80 | 221 |
|
81 | 222 | /// The bit width of a data pointer for the target architecture.
|
| 223 | + /// |
| 224 | + /// The target's pointer bit with (which also corresponds to the number of |
| 225 | + /// bits in `Int`/`UInt`) can only be queried with the experimental syntax |
| 226 | + /// `_pointerBitWidth(_<bitwidth>)`, e.g., |
| 227 | + /// |
| 228 | + /// ``` |
| 229 | + /// #if _pointerBitWidth(32) |
| 230 | + /// // 32-bit system |
| 231 | + /// #endif |
82 | 232 | var targetPointerBitWidth: Int? { get }
|
83 | 233 |
|
84 | 234 | /// The endianness of the target architecture.
|
| 235 | + /// |
| 236 | + /// The target's endianness can onyl be queried with the experimental syntax |
| 237 | + /// `_endian(<name>)`, where `<name>` can be either "big" or "little", e.g., |
| 238 | + /// |
| 239 | + /// #if _endian(little) |
| 240 | + /// // Swap some bytes around for network byte order |
| 241 | + /// #endif |
85 | 242 | var endianness: Endianness? { get }
|
86 | 243 |
|
87 | 244 | /// The effective language version, which can be set by the user (e.g., 5.0).
|
| 245 | + /// |
| 246 | + /// The language version can be queried with the `swift` directive that checks |
| 247 | + /// how the supported language version compares, as described by |
| 248 | + /// [SE-0212](https://github.com/apple/swift-evolution/blob/main/proposals/0212-compiler-version-directive.md). For example: |
| 249 | + /// |
| 250 | + /// ``` |
| 251 | + /// #if swift(>=5.5) |
| 252 | + /// // Hooray, we can use tasks! |
| 253 | + /// ``` |
88 | 254 | var languageVersion: VersionTuple? { get }
|
89 | 255 |
|
90 | 256 | /// The version of the compiler (e.g., 5.9).
|
| 257 | + /// |
| 258 | + /// The compiler version can be queried with the `compiler` directive that |
| 259 | + /// checks the specific version of the compiler being used to process the |
| 260 | + /// code, e.g., |
| 261 | + /// |
| 262 | + /// ``` |
| 263 | + /// #if compiler(>=5.7) |
| 264 | + /// // Hoorway, we can implicitly open existentials! |
| 265 | + /// #endif |
91 | 266 | var compilerVersion: VersionTuple? { get }
|
92 | 267 | }
|
0 commit comments