@@ -37,33 +37,35 @@ import SwiftSyntax
3737/// it would not visit either `f` or `g`.
3838///
3939/// 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
4242/// diagnostics.
4343open class ActiveSyntaxVisitor < Configuration: BuildConfiguration > : SyntaxVisitor {
4444 /// The build configuration, which will be queried for each relevant `#if`.
4545 public let configuration : Configuration
4646
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 ] = [ ]
4949
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
5252
5353 public init ( viewMode: SyntaxTreeViewMode , configuration: Configuration ) {
5454 self . configuration = configuration
5555 super. init ( viewMode: viewMode)
5656 }
5757
5858 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.
5961 let ( activeClause, localDiagnostics) = node. activeClause ( in: configuration)
6062 diagnostics. append ( contentsOf: localDiagnostics)
6163
62- numIfClausesVisited += 1
64+ visitedAnyIfClauses = true
6365
6466 // If there is an active clause, visit it's children.
6567 if let activeClause, let elements = activeClause. elements {
66- walk ( Syntax ( elements) )
68+ walk ( elements)
6769 }
6870
6971 // Skip everything else in the #if.
@@ -95,32 +97,30 @@ open class ActiveSyntaxVisitor<Configuration: BuildConfiguration>: SyntaxVisitor
9597/// it would not visit either `f` or `g`.
9698///
9799/// 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.
105102open class ActiveSyntaxAnyVisitor < Configuration: BuildConfiguration > : SyntaxAnyVisitor {
106103 /// The build configuration, which will be queried for each relevant `#if`.
107104 public let configuration : Configuration
108105
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 ] = [ ]
111108
112109 public init ( viewMode: SyntaxTreeViewMode , configuration: Configuration ) {
113110 self . configuration = configuration
114111 super. init ( viewMode: viewMode)
115112 }
116113
117114 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+
118118 // If there is an active clause, visit it's children.
119119 let ( activeClause, localDiagnostics) = node. activeClause ( in: configuration)
120120 diagnostics. append ( contentsOf: localDiagnostics)
121121
122122 if let activeClause, let elements = activeClause. elements {
123- walk ( Syntax ( elements) )
123+ walk ( elements)
124124 }
125125
126126 // Skip everything else in the #if.
0 commit comments