@@ -158,7 +158,6 @@ extension VersionTuple {
158
158
}
159
159
}
160
160
161
-
162
161
/// Evaluate the condition of an `#if`.
163
162
private func evaluateIfConfig(
164
163
condition: ExprSyntax ,
@@ -188,14 +187,16 @@ private func evaluateIfConfig(
188
187
189
188
// Logical '!'.
190
189
if let prefixOp = condition. as ( PrefixOperatorExprSyntax . self) ,
191
- prefixOp. operatorToken? . text == " ! " {
190
+ prefixOp. operatorToken? . text == " ! "
191
+ {
192
192
return try ! evaluateIfConfig( condition: prefixOp. postfixExpression, configuration: configuration)
193
193
}
194
194
195
195
// Logical '&&' and '||'.
196
196
if let binOp = condition. as ( InfixOperatorExprSyntax . self) ,
197
- let op = binOp. operatorOperand. as ( BinaryOperatorExprSyntax . self) ,
198
- ( op. operatorToken. text == " && " || op. operatorToken. text == " || " ) {
197
+ let op = binOp. operatorOperand. as ( BinaryOperatorExprSyntax . self) ,
198
+ ( op. operatorToken. text == " && " || op. operatorToken. text == " || " )
199
+ {
199
200
// Evaluate the left-hand side.
200
201
let lhsResult = try evaluateIfConfig ( condition: binOp. leftOperand, configuration: configuration)
201
202
@@ -212,20 +213,23 @@ private func evaluateIfConfig(
212
213
213
214
// Look through parentheses.
214
215
if let tuple = condition. as ( TupleExprSyntax . self) , tuple. isParentheses,
215
- let element = tuple. elements. first {
216
+ let element = tuple. elements. first
217
+ {
216
218
return try evaluateIfConfig ( condition: element. expression, configuration: configuration)
217
219
}
218
220
219
221
// Calls syntax is for operations.
220
222
if let call = condition. as ( FunctionCallExprSyntax . self) ,
221
- let fnName = call. calledExpression. simpleIdentifierExpr,
222
- let fn = IfConfigFunctions ( rawValue: fnName) {
223
+ let fnName = call. calledExpression. simpleIdentifierExpr,
224
+ let fn = IfConfigFunctions ( rawValue: fnName)
225
+ {
223
226
224
227
/// Perform a check for an operation that takes a single identifier argument.
225
228
func doSingleIdentifierArgumentCheck( _ body: ( String , ExprSyntax ) -> Bool ? ) throws -> Bool ? {
226
229
// Ensure that we have a single argument that is a simple identifier.
227
230
guard let argExpr = call. argumentList. singleUnlabeledExpression,
228
- let arg = argExpr. simpleIdentifierExpr else { return nil }
231
+ let arg = argExpr. simpleIdentifierExpr
232
+ else { return nil }
229
233
230
234
guard let result = body ( arg, ExprSyntax ( argExpr) ) else {
231
235
throw IfConfigError . unhandledFunction ( name: fnName, syntax: ExprSyntax ( call) )
@@ -239,8 +243,9 @@ private func evaluateIfConfig(
239
243
// Ensure that we have a single unlabeled argument that is either >= or < as a prefix
240
244
// operator applied to a version.
241
245
guard let argExpr = call. argumentList. singleUnlabeledExpression,
242
- let unaryArg = argExpr. as ( PrefixOperatorExprSyntax . self) ,
243
- let opToken = unaryArg. operatorToken else {
246
+ let unaryArg = argExpr. as ( PrefixOperatorExprSyntax . self) ,
247
+ let opToken = unaryArg. operatorToken
248
+ else {
244
249
return nil
245
250
}
246
251
@@ -289,8 +294,9 @@ private func evaluateIfConfig(
289
294
// Ensure that we have a single argument that is a simple identifier,
290
295
// either "little" or "big".
291
296
guard let argExpr = call. argumentList. singleUnlabeledExpression,
292
- let arg = argExpr. simpleIdentifierExpr,
293
- let expectedEndianness = Endianness ( rawValue: arg) else {
297
+ let arg = argExpr. simpleIdentifierExpr,
298
+ let expectedEndianness = Endianness ( rawValue: arg)
299
+ else {
294
300
result = nil
295
301
break
296
302
}
@@ -306,10 +312,11 @@ private func evaluateIfConfig(
306
312
// Ensure that we have a single argument that is a simple identifier, which
307
313
// is an underscore followed by an integer.
308
314
guard let argExpr = call. argumentList. singleUnlabeledExpression,
309
- let arg = argExpr. simpleIdentifierExpr,
310
- let argFirst = arg. first,
311
- argFirst == " _ " ,
312
- let expectedPointerBitWidth = Int ( arg. dropFirst ( ) ) else {
315
+ let arg = argExpr. simpleIdentifierExpr,
316
+ let argFirst = arg. first,
317
+ argFirst == " _ " ,
318
+ let expectedPointerBitWidth = Int ( arg. dropFirst ( ) )
319
+ else {
313
320
result = nil
314
321
break
315
322
}
@@ -331,10 +338,11 @@ private func evaluateIfConfig(
331
338
// Argument is a single unlabeled argument containing a string
332
339
// literal.
333
340
guard let argExpr = call. argumentList. singleUnlabeledExpression,
334
- let stringLiteral = argExpr. as ( StringLiteralExprSyntax . self) ,
335
- stringLiteral. segments. count == 1 ,
336
- let segment = stringLiteral. segments. first,
337
- case . stringSegment( let stringSegment) = segment else {
341
+ let stringLiteral = argExpr. as ( StringLiteralExprSyntax . self) ,
342
+ stringLiteral. segments. count == 1 ,
343
+ let segment = stringLiteral. segments. first,
344
+ case . stringSegment( let stringSegment) = segment
345
+ else {
338
346
// FIXME: better diagnostic here
339
347
throw IfConfigError . unknownExpression ( condition)
340
348
}
@@ -352,7 +360,8 @@ private func evaluateIfConfig(
352
360
// Retrieve the first argument, which must not have a label. This is
353
361
// the module import path.
354
362
guard let firstArg = call. argumentList. first,
355
- firstArg. label == nil else {
363
+ firstArg. label == nil
364
+ else {
356
365
throw IfConfigError . canImportMissingModule ( syntax: ExprSyntax ( call) )
357
366
}
358
367
@@ -363,16 +372,16 @@ private func evaluateIfConfig(
363
372
// _underlyingVersion.
364
373
let version : CanImportVersion
365
374
if let secondArg = call. argumentList. dropFirst ( ) . first {
366
- if secondArg. label? . text != " _version " &&
367
- secondArg. label? . text != " _underlyingVersion " {
375
+ if secondArg. label? . text != " _version " && secondArg. label? . text != " _underlyingVersion " {
368
376
throw IfConfigError . canImportLabel ( syntax: secondArg. expression)
369
377
}
370
378
371
379
let versionText : String
372
380
if let stringLiteral = secondArg. expression. as ( StringLiteralExprSyntax . self) ,
373
- stringLiteral. segments. count == 1 ,
374
- let firstSegment = stringLiteral. segments. first,
375
- case . stringSegment( let stringSegment) = firstSegment {
381
+ stringLiteral. segments. count == 1 ,
382
+ let firstSegment = stringLiteral. segments. first,
383
+ case . stringSegment( let stringSegment) = firstSegment
384
+ {
376
385
versionText = stringSegment. content. text
377
386
} else {
378
387
versionText = secondArg. expression. trimmedDescription
@@ -386,7 +395,7 @@ private func evaluateIfConfig(
386
395
387
396
if secondArg. label? . text == " _version " {
388
397
version = . version( versionTuple)
389
- } else {
398
+ } else {
390
399
assert ( secondArg. label? . text == " _underlyingVersion " )
391
400
version = . underlyingVersion( versionTuple)
392
401
}
@@ -400,7 +409,8 @@ private func evaluateIfConfig(
400
409
401
410
result = configuration. canImport (
402
411
importPath: importPath. map { String ( $0) } ,
403
- version: version, syntax: ExprSyntax ( call)
412
+ version: version,
413
+ syntax: ExprSyntax ( call)
404
414
)
405
415
}
406
416
0 commit comments