@@ -37,33 +37,35 @@ import SwiftSyntax
37
37
/// it would not visit either `f` or `g`.
38
38
///
39
39
/// All notes visited by this visitor will have the "active" state, i.e.,
40
- /// `node.isActive(in: configuration)` will evaluate to `.active` or will
41
- /// throw. When errors occur, they will be recorded in the set of
40
+ /// `node.isActive(in: configuration)` will have evaluated to `.active`
41
+ /// When errors occur, they will be recorded in the set of
42
42
/// diagnostics.
43
43
open class ActiveSyntaxVisitor < Configuration: BuildConfiguration > : SyntaxVisitor {
44
44
/// The build configuration, which will be queried for each relevant `#if`.
45
45
public let configuration : Configuration
46
46
47
- /// The set of diagnostics accumulated during this walk of active syntax.
48
- public var diagnostics : [ Diagnostic ] = [ ]
47
+ /// The diagnostics accumulated during this walk of active syntax.
48
+ public private ( set ) var diagnostics : [ Diagnostic ] = [ ]
49
49
50
- /// The number of "#if" clauses that were visited .
51
- var numIfClausesVisited : Int = 0
50
+ /// Whether we visited any "#if" clauses.
51
+ var visitedAnyIfClauses : Bool = false
52
52
53
53
public init ( viewMode: SyntaxTreeViewMode , configuration: Configuration ) {
54
54
self . configuration = configuration
55
55
super. init ( viewMode: viewMode)
56
56
}
57
57
58
58
open override func visit( _ node: IfConfigDeclSyntax ) -> SyntaxVisitorContinueKind {
59
+ // Note: there is a clone of this code in ActiveSyntaxAnyVisitor. If you
60
+ // change one, please also change the other.
59
61
let ( activeClause, localDiagnostics) = node. activeClause ( in: configuration)
60
62
diagnostics. append ( contentsOf: localDiagnostics)
61
63
62
- numIfClausesVisited += 1
64
+ visitedAnyIfClauses = true
63
65
64
66
// If there is an active clause, visit it's children.
65
67
if let activeClause, let elements = activeClause. elements {
66
- walk ( Syntax ( elements) )
68
+ walk ( elements)
67
69
}
68
70
69
71
// Skip everything else in the #if.
@@ -95,32 +97,30 @@ open class ActiveSyntaxVisitor<Configuration: BuildConfiguration>: SyntaxVisitor
95
97
/// it would not visit either `f` or `g`.
96
98
///
97
99
/// All notes visited by this visitor will have the "active" state, i.e.,
98
- /// `node.isActive(in: configuration)` will evaluate to `.active` or will
99
- /// throw.
100
- ///
101
- /// All notes visited by this visitor will have the "active" state, i.e.,
102
- /// `node.isActive(in: configuration)` will evaluate to `.active` or will
103
- /// throw. When errors occur, they will be recorded in the set of
104
- /// diagnostivs.
100
+ /// `node.isActive(in: configuration)` will have evaluated to `.active`.
101
+ /// When errors occur, they will be recorded in the array of diagnostics.
105
102
open class ActiveSyntaxAnyVisitor < Configuration: BuildConfiguration > : SyntaxAnyVisitor {
106
103
/// The build configuration, which will be queried for each relevant `#if`.
107
104
public let configuration : Configuration
108
105
109
- /// The set of diagnostics accumulated during this walk of active syntax.
110
- public var diagnostics : [ Diagnostic ] = [ ]
106
+ /// The diagnostics accumulated during this walk of active syntax.
107
+ public private ( set ) var diagnostics : [ Diagnostic ] = [ ]
111
108
112
109
public init ( viewMode: SyntaxTreeViewMode , configuration: Configuration ) {
113
110
self . configuration = configuration
114
111
super. init ( viewMode: viewMode)
115
112
}
116
113
117
114
open override func visit( _ node: IfConfigDeclSyntax ) -> SyntaxVisitorContinueKind {
115
+ // Note: there is a clone of this code in ActiveSyntaxVisitor. If you
116
+ // change one, please also change the other.
117
+
118
118
// If there is an active clause, visit it's children.
119
119
let ( activeClause, localDiagnostics) = node. activeClause ( in: configuration)
120
120
diagnostics. append ( contentsOf: localDiagnostics)
121
121
122
122
if let activeClause, let elements = activeClause. elements {
123
- walk ( Syntax ( elements) )
123
+ walk ( elements)
124
124
}
125
125
126
126
// Skip everything else in the #if.
0 commit comments