@@ -24,29 +24,29 @@ public enum ConfiguredRegionState {
24
24
/// The region is active and is part of the compiled program.
25
25
case active
26
26
27
- /// Evaluate the given `#if` condition using the given build configuration, throwing an error if there is
28
- /// insufficient information to make a determination.
29
- public init (
30
- condition : some ExprSyntaxProtocol ,
31
- configuration : some BuildConfiguration ,
32
- diagnosticHandler : ( ( Diagnostic ) -> Void ) ? = nil
33
- ) throws {
27
+ /// Evaluate the given `#if` condition using the given build configuration
28
+ /// to determine its state and identify any problems encountered along the
29
+ /// way.
30
+ public static func evaluating (
31
+ _ condition : some ExprSyntaxProtocol ,
32
+ in configuration : some BuildConfiguration
33
+ ) -> ( state : ConfiguredRegionState , diagnostics : [ Diagnostic ] ) {
34
34
// Apply operator folding for !/&&/||.
35
- let foldedCondition = try OperatorTable . logicalOperators . foldAll ( condition ) { error in
36
- diagnosticHandler ? ( error . asDiagnostic )
37
- throw error
35
+ var foldingDiagnostics : [ Diagnostic ] = [ ]
36
+ let foldedCondition = OperatorTable . logicalOperators . foldAll ( condition ) { error in
37
+ foldingDiagnostics . append ( contentsOf : error. asDiagnostics ( at : condition ) )
38
38
} . cast ( ExprSyntax . self)
39
39
40
- let ( active, versioned) = try evaluateIfConfig (
40
+ let ( active, versioned, evalDiagnostics ) = evaluateIfConfig (
41
41
condition: foldedCondition,
42
- configuration: configuration,
43
- diagnosticHandler: diagnosticHandler
42
+ configuration: configuration
44
43
)
45
44
45
+ let diagnostics = foldingDiagnostics + evalDiagnostics
46
46
switch ( active, versioned) {
47
- case ( true , _) : self = . active
48
- case ( false , false ) : self = . inactive
49
- case ( false , true ) : self = . unparsed
47
+ case ( true , _) : return ( . active, diagnostics )
48
+ case ( false , false ) : return ( . inactive, diagnostics )
49
+ case ( false , true ) : return ( . unparsed, diagnostics )
50
50
}
51
51
}
52
52
}
0 commit comments