@@ -121,6 +121,133 @@ unsigned BridgedASTContext_majorLanguageVersion(BridgedASTContext cContext) {
121
121
return cContext.unbridged ().LangOpts .EffectiveLanguageVersion [0 ];
122
122
}
123
123
124
+ bool BridgedASTContext_langOptsCustomConditionSet (BridgedASTContext cContext,
125
+ BridgedStringRef cName) {
126
+ return cContext.unbridged ().LangOpts
127
+ .isCustomConditionalCompilationFlagSet (cName.unbridged ());
128
+ }
129
+
130
+ bool BridgedASTContext_langOptsHasFeatureNamed (BridgedASTContext cContext,
131
+ BridgedStringRef cName) {
132
+ return cContext.unbridged ().LangOpts .hasFeature (cName.unbridged ());
133
+ }
134
+
135
+ bool BridgedASTContext_langOptsHasAttributeNamed (BridgedASTContext cContext,
136
+ BridgedStringRef cName) {
137
+ return hasAttribute (cContext.unbridged ().LangOpts , cName.unbridged ());
138
+ }
139
+
140
+ bool BridgedASTContext_langOptsIsActiveTargetOS (BridgedASTContext cContext,
141
+ BridgedStringRef cName) {
142
+ return cContext.unbridged ().LangOpts .checkPlatformCondition (
143
+ PlatformConditionKind::OS, cName.unbridged ());
144
+ }
145
+
146
+ bool BridgedASTContext_langOptsIsActiveTargetArchitecture (BridgedASTContext cContext,
147
+ BridgedStringRef cName) {
148
+ return cContext.unbridged ().LangOpts .checkPlatformCondition (
149
+ PlatformConditionKind::Arch, cName.unbridged ());
150
+ }
151
+
152
+ bool BridgedASTContext_langOptsIsActiveTargetEnvironment (BridgedASTContext cContext,
153
+ BridgedStringRef cName) {
154
+ return cContext.unbridged ().LangOpts .checkPlatformCondition (
155
+ PlatformConditionKind::TargetEnvironment, cName.unbridged ());
156
+ }
157
+
158
+ bool BridgedASTContext_langOptsIsActiveTargetRuntime (BridgedASTContext cContext,
159
+ BridgedStringRef cName) {
160
+ return cContext.unbridged ().LangOpts .checkPlatformCondition (
161
+ PlatformConditionKind::Runtime, cName.unbridged ());
162
+ }
163
+
164
+ bool BridgedASTContext_langOptsIsActiveTargetPtrAuth (BridgedASTContext cContext,
165
+ BridgedStringRef cName) {
166
+ return cContext.unbridged ().LangOpts .checkPlatformCondition (
167
+ PlatformConditionKind::PtrAuth, cName.unbridged ());
168
+ }
169
+
170
+ unsigned BridgedASTContext_langOptsTargetPointerBitWidth (BridgedASTContext cContext) {
171
+ return cContext.unbridged ().LangOpts .Target .isArch64Bit () ? 64
172
+ : cContext.unbridged ().LangOpts .Target .isArch32Bit () ? 32
173
+ : cContext.unbridged ().LangOpts .Target .isArch16Bit () ? 16
174
+ : 0 ;
175
+ }
176
+
177
+ BridgedEndianness BridgedASTContext_langOptsTargetEndianness (BridgedASTContext cContext) {
178
+ return cContext.unbridged ().LangOpts .Target .isLittleEndian () ? EndianLittle
179
+ : EndianBig;
180
+ }
181
+
182
+ // / Convert an array of numbers into a form we can use in Swift.
183
+ namespace {
184
+ template <typename Arr>
185
+ SwiftInt convertArray (const Arr &array, SwiftInt **cElements) {
186
+ SwiftInt numElements = array.size ();
187
+ *cElements = (SwiftInt *)malloc (sizeof (SwiftInt) * numElements);
188
+ for (SwiftInt i = 0 ; i != numElements; ++i)
189
+ (*cElements)[i] = array[i];
190
+ return numElements;
191
+ }
192
+ }
193
+
194
+ SwiftInt BridgedASTContext_langOptsGetLanguageVersion (BridgedASTContext cContext,
195
+ SwiftInt** cComponents) {
196
+ auto theVersion = cContext.unbridged ().LangOpts .EffectiveLanguageVersion ;
197
+ return convertArray (theVersion, cComponents);
198
+ }
199
+
200
+ SWIFT_NAME (" BridgedASTContext.langOptsGetCompilerVersion(self:_:)" )
201
+ SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
202
+ SwiftInt** cComponents) {
203
+ auto theVersion = version::Version::getCurrentLanguageVersion ();
204
+ return convertArray (theVersion, cComponents);
205
+ }
206
+
207
+ SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths (BridgedASTContext cContext,
208
+ SwiftInt* _Nullable * _Nonnull cElements) {
209
+ return convertArray (cContext.unbridged ().LangOpts .getAtomicBitWidthValues (),
210
+ cElements);
211
+ }
212
+
213
+ bool BridgedASTContext_canImport (BridgedASTContext cContext,
214
+ BridgedStringRef importPath,
215
+ BridgedCanImportVersion versionKind,
216
+ const SwiftInt * _Nullable versionComponents,
217
+ SwiftInt numVersionComponents) {
218
+ // Map the version.
219
+ llvm::VersionTuple version;
220
+ switch (numVersionComponents) {
221
+ case 0 :
222
+ break ;
223
+ case 1 :
224
+ version = llvm::VersionTuple (versionComponents[0 ]);
225
+ break ;
226
+ case 2 :
227
+ version = llvm::VersionTuple (versionComponents[0 ], versionComponents[1 ]);
228
+ break ;
229
+ case 3 :
230
+ version = llvm::VersionTuple (versionComponents[0 ], versionComponents[1 ],
231
+ versionComponents[2 ]);
232
+ break ;
233
+ default :
234
+ version = llvm::VersionTuple (versionComponents[0 ], versionComponents[1 ],
235
+ versionComponents[2 ], versionComponents[3 ]);
236
+ break ;
237
+ }
238
+
239
+ // FIXME: The source location here is empty because build configurations
240
+ // are supposed to be completely separated from source code. We could re-plumb
241
+ // things to have any errors reported up thruough the "canImportModule"
242
+ // API.
243
+ ImportPath::Module::Builder builder (
244
+ cContext.unbridged (), importPath.unbridged (), /* separator=*/ ' .' ,
245
+ SourceLoc ());
246
+ return cContext.unbridged ().canImportModule (
247
+ builder.get (), SourceLoc (), version,
248
+ versionKind == CanImportUnderlyingVersion);
249
+ }
250
+
124
251
// ===----------------------------------------------------------------------===//
125
252
// MARK: AST nodes
126
253
// ===----------------------------------------------------------------------===//
0 commit comments