@@ -24,29 +24,29 @@ public enum ConfiguredRegionState {
2424 /// The region is active and is part of the compiled program.
2525 case active
2626
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 ] ) {
3434 // 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 ) )
3838 } . cast ( ExprSyntax . self)
3939
40- let ( active, versioned) = try evaluateIfConfig (
40+ let ( active, versioned, evalDiagnostics ) = evaluateIfConfig (
4141 condition: foldedCondition,
42- configuration: configuration,
43- diagnosticHandler: diagnosticHandler
42+ configuration: configuration
4443 )
4544
45+ let diagnostics = foldingDiagnostics + evalDiagnostics
4646 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 )
5050 }
5151 }
5252}
0 commit comments