@@ -25,22 +25,22 @@ import SwiftSyntax
25
25
/// - Returns: A pair of Boolean values and any diagnostics produced during the
26
26
/// evaluation. The first Boolean describes whether the condition holds with
27
27
/// the given build configuration. The second Boolean described whether
28
- /// the build condition is a "versioned" check that implies that we shouldn't
28
+ /// the build condition's failure implies that we shouldn't
29
29
/// diagnose syntax errors in blocks where the check fails.
30
30
func evaluateIfConfig(
31
31
condition: ExprSyntax ,
32
32
configuration: some BuildConfiguration
33
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
33
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
34
34
var extraDiagnostics : [ Diagnostic ] = [ ]
35
35
36
36
/// Record the error before returning the given value.
37
37
func recordError(
38
38
_ error: any Error ,
39
39
at node: some SyntaxProtocol
40
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
40
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
41
41
return (
42
42
active: false ,
43
- versioned : true ,
43
+ syntaxErrorsAllowed : true ,
44
44
diagnostics: extraDiagnostics + error. asDiagnostics ( at: node)
45
45
)
46
46
}
@@ -49,7 +49,7 @@ func evaluateIfConfig(
49
49
/// every 'throw' site in this evaluation.
50
50
func recordError(
51
51
_ error: IfConfigError
52
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
52
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
53
53
return recordError ( error, at: error. syntax)
54
54
}
55
55
@@ -58,10 +58,10 @@ func evaluateIfConfig(
58
58
func checkConfiguration(
59
59
at node: some SyntaxProtocol ,
60
60
body: ( ) throws -> ( Bool , Bool )
61
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
61
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
62
62
do {
63
- let ( active, versioned ) = try body ( )
64
- return ( active, versioned , extraDiagnostics)
63
+ let ( active, syntaxErrorsAllowed ) = try body ( )
64
+ return ( active, syntaxErrorsAllowed , extraDiagnostics)
65
65
} catch let error {
66
66
return recordError ( error, at: node)
67
67
}
@@ -71,7 +71,7 @@ func evaluateIfConfig(
71
71
if let boolLiteral = condition. as ( BooleanLiteralExprSyntax . self) {
72
72
return (
73
73
active: boolLiteral. literalValue,
74
- versioned : false ,
74
+ syntaxErrorsAllowed : false ,
75
75
diagnostics: extraDiagnostics
76
76
)
77
77
}
@@ -84,7 +84,7 @@ func evaluateIfConfig(
84
84
85
85
return (
86
86
active: result,
87
- versioned : false ,
87
+ syntaxErrorsAllowed : false ,
88
88
diagnostics: [
89
89
IfConfigError . integerLiteralCondition (
90
90
syntax: condition,
@@ -101,20 +101,20 @@ func evaluateIfConfig(
101
101
102
102
// Evaluate the custom condition. If the build configuration cannot answer this query, fail.
103
103
return checkConfiguration ( at: identExpr) {
104
- ( active: try configuration. isCustomConditionSet ( name: ident) , versioned : false )
104
+ ( active: try configuration. isCustomConditionSet ( name: ident) , syntaxErrorsAllowed : false )
105
105
}
106
106
}
107
107
108
108
// Logical '!'.
109
109
if let prefixOp = condition. as ( PrefixOperatorExprSyntax . self) ,
110
110
prefixOp. operator. text == " ! "
111
111
{
112
- let ( innerActive, innerVersioned , innerDiagnostics) = evaluateIfConfig (
112
+ let ( innerActive, innersyntaxErrorsAllowed , innerDiagnostics) = evaluateIfConfig (
113
113
condition: prefixOp. expression,
114
114
configuration: configuration
115
115
)
116
116
117
- return ( active: !innerActive, versioned : innerVersioned , diagnostics: innerDiagnostics)
117
+ return ( active: !innerActive, syntaxErrorsAllowed : innersyntaxErrorsAllowed , diagnostics: innerDiagnostics)
118
118
}
119
119
120
120
// Logical '&&' and '||'.
@@ -123,26 +123,26 @@ func evaluateIfConfig(
123
123
( op. operator. text == " && " || op. operator. text == " || " )
124
124
{
125
125
// Evaluate the left-hand side.
126
- let ( lhsActive, lhsVersioned , lhsDiagnostics) = evaluateIfConfig (
126
+ let ( lhsActive, lhssyntaxErrorsAllowed , lhsDiagnostics) = evaluateIfConfig (
127
127
condition: binOp. leftOperand,
128
128
configuration: configuration
129
129
)
130
130
131
131
// Short-circuit evaluation if we know the answer and the left-hand side
132
- // was versioned .
133
- if lhsVersioned {
132
+ // was syntaxErrorsAllowed .
133
+ if lhssyntaxErrorsAllowed {
134
134
switch ( lhsActive, op. operator. text) {
135
135
case ( true , " || " ) :
136
- return ( active: true , versioned : lhsVersioned , diagnostics: lhsDiagnostics)
136
+ return ( active: true , syntaxErrorsAllowed : lhssyntaxErrorsAllowed , diagnostics: lhsDiagnostics)
137
137
case ( false , " && " ) :
138
- return ( active: false , versioned : lhsVersioned , diagnostics: lhsDiagnostics)
138
+ return ( active: false , syntaxErrorsAllowed : lhssyntaxErrorsAllowed , diagnostics: lhsDiagnostics)
139
139
default :
140
140
break
141
141
}
142
142
}
143
143
144
144
// Evaluate the right-hand side.
145
- let ( rhsActive, rhsVersioned , rhsDiagnostics) = evaluateIfConfig (
145
+ let ( rhsActive, rhssyntaxErrorsAllowed , rhsDiagnostics) = evaluateIfConfig (
146
146
condition: binOp. rightOperand,
147
147
configuration: configuration
148
148
)
@@ -151,14 +151,14 @@ func evaluateIfConfig(
151
151
case " || " :
152
152
return (
153
153
active: lhsActive || rhsActive,
154
- versioned : lhsVersioned && rhsVersioned ,
154
+ syntaxErrorsAllowed : lhssyntaxErrorsAllowed && rhssyntaxErrorsAllowed ,
155
155
diagnostics: lhsDiagnostics + rhsDiagnostics
156
156
)
157
157
158
158
case " && " :
159
159
return (
160
160
active: lhsActive && rhsActive,
161
- versioned : lhsVersioned || rhsVersioned ,
161
+ syntaxErrorsAllowed : lhssyntaxErrorsAllowed || rhssyntaxErrorsAllowed ,
162
162
diagnostics: lhsDiagnostics + rhsDiagnostics
163
163
)
164
164
@@ -186,7 +186,7 @@ func evaluateIfConfig(
186
186
func doSingleIdentifierArgumentCheck(
187
187
_ body: ( String ) throws -> Bool ,
188
188
role: String
189
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
189
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
190
190
// Ensure that we have a single argument that is a simple identifier.
191
191
guard let argExpr = call. arguments. singleUnlabeledExpression,
192
192
let arg = argExpr. simpleIdentifierExpr
@@ -197,14 +197,14 @@ func evaluateIfConfig(
197
197
}
198
198
199
199
return checkConfiguration ( at: argExpr) {
200
- ( active: try body ( arg) , versioned : fn. isVersioned )
200
+ ( active: try body ( arg) , syntaxErrorsAllowed : fn. syntaxErrorsAllowed )
201
201
}
202
202
}
203
203
204
204
/// Perform a check for a version constraint as used in the "swift" or "compiler" version checks.
205
205
func doVersionComparisonCheck(
206
206
_ actualVersion: VersionTuple
207
- ) -> ( active: Bool , versioned : Bool , diagnostics: [ Diagnostic ] ) {
207
+ ) -> ( active: Bool , syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
208
208
// Ensure that we have a single unlabeled argument that is either >= or < as a prefix
209
209
// operator applied to a version.
210
210
guard let argExpr = call. arguments. singleUnlabeledExpression,
@@ -229,13 +229,13 @@ func evaluateIfConfig(
229
229
case " >= " :
230
230
return (
231
231
active: actualVersion >= version,
232
- versioned : fn. isVersioned ,
232
+ syntaxErrorsAllowed : fn. syntaxErrorsAllowed ,
233
233
diagnostics: extraDiagnostics
234
234
)
235
235
case " < " :
236
236
return (
237
237
active: actualVersion < version,
238
- versioned : fn. isVersioned ,
238
+ syntaxErrorsAllowed : fn. syntaxErrorsAllowed ,
239
239
diagnostics: extraDiagnostics
240
240
)
241
241
default :
@@ -286,7 +286,7 @@ func evaluateIfConfig(
286
286
287
287
return (
288
288
active: configuration. endianness == expectedEndianness,
289
- versioned : fn. isVersioned ,
289
+ syntaxErrorsAllowed : fn. syntaxErrorsAllowed ,
290
290
diagnostics: extraDiagnostics
291
291
)
292
292
@@ -317,7 +317,7 @@ func evaluateIfConfig(
317
317
fatalError ( " extraneous case above not handled " )
318
318
}
319
319
320
- return ( active: active, versioned : fn. isVersioned , diagnostics: extraDiagnostics)
320
+ return ( active: active, syntaxErrorsAllowed : fn. syntaxErrorsAllowed , diagnostics: extraDiagnostics)
321
321
322
322
case . swift:
323
323
return doVersionComparisonCheck ( configuration. languageVersion)
@@ -353,7 +353,7 @@ func evaluateIfConfig(
353
353
354
354
return (
355
355
active: configuration. compilerVersion >= expectedVersion,
356
- versioned : fn. isVersioned ,
356
+ syntaxErrorsAllowed : fn. syntaxErrorsAllowed ,
357
357
diagnostics: extraDiagnostics
358
358
)
359
359
@@ -429,7 +429,7 @@ func evaluateIfConfig(
429
429
importPath: importPath. map { String ( $0) } ,
430
430
version: version
431
431
) ,
432
- versioned : fn. isVersioned
432
+ syntaxErrorsAllowed : fn. syntaxErrorsAllowed
433
433
)
434
434
}
435
435
}
@@ -439,20 +439,20 @@ func evaluateIfConfig(
439
439
}
440
440
441
441
extension IfConfigClauseSyntax {
442
- /// Determine whether this condition is "versioned ".
443
- func isVersioned (
442
+ /// Determine whether this condition is "syntaxErrorsAllowed ".
443
+ func syntaxErrorsAllowed (
444
444
configuration: some BuildConfiguration
445
- ) -> ( versioned : Bool , diagnostics: [ Diagnostic ] ) {
445
+ ) -> ( syntaxErrorsAllowed : Bool , diagnostics: [ Diagnostic ] ) {
446
446
guard let condition else {
447
- return ( versioned : false , diagnostics: [ ] )
447
+ return ( syntaxErrorsAllowed : false , diagnostics: [ ] )
448
448
}
449
449
450
450
// Evaluate this condition against the build configuration.
451
- let ( _, versioned , diagnostics) = evaluateIfConfig (
451
+ let ( _, syntaxErrorsAllowed , diagnostics) = evaluateIfConfig (
452
452
condition: condition,
453
453
configuration: configuration
454
454
)
455
455
456
- return ( versioned , diagnostics)
456
+ return ( syntaxErrorsAllowed , diagnostics)
457
457
}
458
458
}
0 commit comments