Skip to content

Commit e1cea6f

Browse files
committed
introduced private methods
1 parent 85d15cf commit e1cea6f

File tree

4 files changed

+2885
-846
lines changed

4 files changed

+2885
-846
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxAnyVisitorFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let syntaxAnyVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
8383
DeclSyntax(
8484
"""
8585
\(node.apiAttributes())\
86-
override open func visit\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) -> SyntaxVisitorContinueKind {
86+
override open func visit(_ node: \(node.kind.syntaxType)) -> SyntaxVisitorContinueKind {
8787
return visitAny(node._syntaxNode)
8888
}
8989
"""
@@ -92,7 +92,7 @@ let syntaxAnyVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
9292
DeclSyntax(
9393
"""
9494
\(node.apiAttributes())\
95-
override open func visitPost\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) {
95+
override open func visitPost(_ node: \(node.kind.syntaxType)) {
9696
visitAnyPost(node._syntaxNode)
9797
}
9898
"""

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,23 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6161
/// Visit a ``TokenSyntax``.
6262
/// - Parameter node: the node that is being visited
6363
/// - Returns: the rewritten node
64-
open func visitTokenSyntax(_ token: TokenSyntax) -> TokenSyntax {
64+
open func visit(_ token: TokenSyntax) -> TokenSyntax {
6565
return token
6666
}
6767
"""
6868
)
6969

70+
DeclSyntax(
71+
"""
72+
/// Forwards call to self.visit(_ token: TokenSyntax).
73+
/// - Parameter node: the node that is being visited
74+
/// - Returns: the rewritten node
75+
private func visitTokenSyntax(_ token: TokenSyntax) -> TokenSyntax {
76+
self.visit(token)
77+
}
78+
"""
79+
)
80+
7081
DeclSyntax(
7182
"""
7283
/// The function called before visiting the node and its descendants.
@@ -126,7 +137,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
126137
/// - Parameter node: the node that is being visited
127138
/// - Returns: the rewritten node
128139
\(node.apiAttributes())\
129-
open func visit\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) -> \(node.kind.syntaxType) {
140+
open func visit(_ node: \(node.kind.syntaxType)) -> \(node.kind.syntaxType) {
130141
return visitChildren(node)
131142
}
132143
"""
@@ -138,7 +149,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
138149
/// - Parameter node: the node that is being visited
139150
/// - Returns: the rewritten node
140151
\(node.apiAttributes())\
141-
open func visit\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) -> \(node.baseType.syntaxBaseName) {
152+
open func visit(_ node: \(node.kind.syntaxType)) -> \(node.baseType.syntaxBaseName) {
142153
return \(node.baseType.syntaxBaseName)(visitChildren(node))
143154
}
144155
"""
@@ -154,13 +165,53 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
154165
/// - Parameter node: the node that is being visited
155166
/// - Returns: the rewritten node
156167
\(baseNode.apiAttributes())\
157-
public func visit\(baseKind.syntaxType)(_ node: \(baseKind.syntaxType)) -> \(baseKind.syntaxType) {
168+
public func visit(_ node: \(baseKind.syntaxType)) -> \(baseKind.syntaxType) {
158169
return dispatchVisit(Syntax(node)).cast(\(baseKind.syntaxType).self)
159170
}
160171
"""
161172
)
162173
}
163174

175+
for node in SYNTAX_NODES where !node.kind.isBase {
176+
if (node.base == .syntax || node.base == .syntaxCollection) && node.kind != .missing {
177+
DeclSyntax(
178+
"""
179+
/// Forward call to self.visit(_ node: ``\(node.kind.syntaxType)``).
180+
/// - Parameter node: the node that is being visited
181+
/// - Returns: the rewritten node
182+
private func visit\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) -> \(node.kind.syntaxType) {
183+
visit(node)
184+
}
185+
"""
186+
)
187+
} else {
188+
DeclSyntax(
189+
"""
190+
/// Forward call to self.visit(_ node: ``\(node.kind.syntaxType)``).
191+
/// - Parameter node: the node that is being visited
192+
/// - Returns: the rewritten node
193+
private func visit\(node.kind.syntaxType)(_ node: \(node.kind.syntaxType)) -> \(node.baseType.syntaxBaseName) {
194+
visit(node)
195+
}
196+
"""
197+
)
198+
}
199+
}
200+
201+
for baseNode in SYNTAX_NODES where baseNode.kind.isBase && baseNode.kind != .syntax && baseNode.kind != .syntaxCollection {
202+
let baseKind = baseNode.kind
203+
DeclSyntax(
204+
"""
205+
/// Forward call to self.visit(_ node: ``\(baseKind.syntaxType)``).
206+
/// - Parameter node: the node that is being visited
207+
/// - Returns: the rewritten node
208+
private func visit\(baseKind.syntaxType)(_ node: \(baseKind.syntaxType)) -> \(baseKind.syntaxType) {
209+
visit(node)
210+
}
211+
"""
212+
)
213+
}
214+
164215
DeclSyntax(
165216
"""
166217
/// Interpret `node` as a node of type `nodeType`, visit it, calling

0 commit comments

Comments
 (0)