Skip to content

Commit 5ef41e6

Browse files
committed
rename
1 parent cf30b55 commit 5ef41e6

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

CodeGeneration/Sources/generate-swift-syntax/GenerateSwiftSyntax.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
115115
),
116116

117117
// SwiftSyntax
118-
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["ChildNameForKeyPath.swift"], childNameForKeyPathFile),
119118
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["ConcreteSyntaxProperty.swift"], concreteSyntaxPropertyFile),
120119
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["Keyword.swift"], keywordFile),
121120
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["raw", "RawSyntaxValidation.swift"], rawSyntaxValidationFile),
@@ -129,6 +128,7 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
129128
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxCollections.swift"], syntaxCollectionsFile),
130129
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxEnum.swift"], syntaxEnumFile),
131130
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxKind.swift"], syntaxKindFile),
131+
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxLayoutNodes.swift"], syntaxLayoutNodesFile),
132132
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxRewriter.swift"], syntaxRewriterFile),
133133
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxTraits.swift"], syntaxTraitsFile),
134134
GeneratedFileSpec(

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

-18
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ import SyntaxSupport
1616
import Utils
1717

1818
let concreteSyntaxPropertyFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("""
20-
extension SyntaxLayout {
21-
fileprivate init(kind: SyntaxKind, count: UInt32) {
22-
self.baseKind = kind
23-
self._count = count
24-
}
25-
}
26-
""")
27-
2819
DeclSyntax("""
2920
extension ConcreteSyntaxProperty {
3021
fileprivate init(index: UInt32) {
@@ -35,15 +26,6 @@ let concreteSyntaxPropertyFile = SourceFileSyntax(leadingTrivia: copyrightHeader
3526

3627
for node in NON_BASE_SYNTAX_NODES {
3728
if let layoutNode = node.layoutNode {
38-
try! ExtensionDeclSyntax(
39-
"extension \(node.kind.syntaxType): _LayoutSyntaxProtocol"
40-
) {
41-
DeclSyntax("""
42-
public static var layout: SyntaxLayout<Self> {
43-
SyntaxLayout<Self>(kind: .\(node.enumCaseCallName), count: \(literal: layoutNode.children.count))
44-
}
45-
""")
46-
}
4729
try! ExtensionDeclSyntax(
4830
"\(node.apiAttributes())extension ConcreteSyntaxProperty where Base == \(node.kind.syntaxType)"
4931
) {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/ChildNameForKeyPathFile.swift renamed to CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxLayoutNodesFile.swift

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,30 @@ import SwiftSyntaxBuilder
1515
import SyntaxSupport
1616
import Utils
1717

18-
let childNameForKeyPathFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) {
18+
let syntaxLayoutNodesFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) {
19+
DeclSyntax("""
20+
extension SyntaxLayout {
21+
fileprivate init(kind: SyntaxKind, count: UInt32) {
22+
self.baseKind = kind
23+
self._count = count
24+
}
25+
}
26+
""")
27+
28+
for node in NON_BASE_SYNTAX_NODES {
29+
if let layoutNode = node.layoutNode {
30+
try! ExtensionDeclSyntax(
31+
"extension \(node.kind.syntaxType): _LayoutSyntaxProtocol"
32+
) {
33+
DeclSyntax("""
34+
public static var layout: SyntaxLayout<Self> {
35+
SyntaxLayout<Self>(kind: .\(node.enumCaseCallName), count: \(literal: layoutNode.children.count))
36+
}
37+
""")
38+
}
39+
}
40+
}
41+
1942
try ExtensionDeclSyntax("extension SyntaxLayoutProperty") {
2043
try VariableDeclSyntax(
2144
"""

Sources/SwiftSyntax/SyntaxLayout.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public struct SyntaxLayout<Base: _LayoutSyntaxProtocol> {
5050
private init() { fatalError() }
5151
}
5252

53+
#if false // Not needed at this point.
5354
extension SyntaxLayout: Collection {
5455
public typealias Index = SyntaxLayoutIndex
5556
public typealias Element = SyntaxLayoutProperty
@@ -63,6 +64,7 @@ extension SyntaxLayout: Collection {
6364
return SyntaxLayoutProperty(baseKind: baseKind, index: position)
6465
}
6566
}
67+
#endif
6668

6769
public protocol _LayoutSyntaxProtocol: SyntaxProtocol {
6870
static var layout: SyntaxLayout<Self> { get }
@@ -106,7 +108,12 @@ extension SyntaxProtocol {
106108

107109
/// Returns a new syntax node that has the child at `property` replaced by
108110
/// `value`.
109-
func with<T: SyntaxProtocol>(_ property: ConcreteSyntaxProperty<Self, T>, _ value: T) -> Self {
111+
public func with<T: SyntaxProtocol>(_ property: ConcreteSyntaxProperty<Self, T>, _ value: T) -> Self {
112+
Syntax(self)
113+
.replacingChild(at: Int(property.index.value), with: Syntax(value), arena: SyntaxArena())
114+
.cast(Self.self)
115+
}
116+
public func with<T: SyntaxProtocol>(_ property: ConcreteSyntaxProperty<Self, T?>, _ value: T?) -> Self {
110117
Syntax(self)
111118
.replacingChild(at: Int(property.index.value), with: Syntax(value), arena: SyntaxArena())
112119
.cast(Self.self)

0 commit comments

Comments
 (0)