Skip to content

Commit 034dca0

Browse files
authored
Merge pull request #1817 from kimdv/kimdv/1756-generate-deprecated-children
Generate deprecated children
2 parents a9cff1a + c197b4d commit 034dca0

23 files changed

+1536
-993
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public let ATTRIBUTE_NODES: [Node] = [
169169
),
170170
Child(
171171
name: "AvailabilityArguments",
172-
kind: .collection(kind: .availabilitySpecList, collectionElementName: "AvailabilityArgument")
172+
deprecatedName: "AvailabilityList",
173+
kind: .collection(kind: .availabilitySpecList, collectionElementName: "AvailabilityArgument", deprecatedCollectionElementName: "Availability")
173174
),
174175
Child(
175176
name: "Semicolon",
@@ -229,7 +230,8 @@ public let ATTRIBUTE_NODES: [Node] = [
229230
),
230231
Child(
231232
name: "Platforms",
232-
kind: .collection(kind: .availabilityVersionRestrictionList, collectionElementName: "Platform"),
233+
deprecatedName: "VersionList",
234+
kind: .collection(kind: .availabilityVersionRestrictionList, collectionElementName: "Platform", deprecatedCollectionElementName: "Availability"),
233235
documentation: "The list of OS versions in which the declaration became ABI stable."
234236
),
235237
]

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public enum ChildKind {
3030
/// The child always contains a node that matches one of the `choices`.
3131
case nodeChoices(choices: [Child])
3232
/// The child is a collection of `kind`.
33-
case collection(kind: SyntaxNodeKind, collectionElementName: String)
33+
case collection(kind: SyntaxNodeKind, collectionElementName: String, deprecatedCollectionElementName: String? = nil)
3434
/// The child is a token that matches one of the given `choices`.
3535
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
3636
/// overrides the default leading/trailing space behavior of the token.
@@ -57,6 +57,7 @@ public enum ChildKind {
5757
/// restricted subset of acceptable kinds or texts.
5858
public class Child {
5959
public let name: String
60+
public let deprecatedName: String?
6061
public let kind: ChildKind
6162
public let nameForDiagnostics: String?
6263
public let documentation: String?
@@ -71,7 +72,7 @@ public class Child {
7172
return kind
7273
case .nodeChoices:
7374
return .syntax
74-
case .collection(kind: let kind, collectionElementName: _):
75+
case .collection(kind: let kind, _, _):
7576
return kind
7677
case .token:
7778
return .token
@@ -83,6 +84,14 @@ public class Child {
8384
return lowercaseFirstWord(name: name)
8485
}
8586

87+
/// The deprecated name of this child that's suitable to be used for variable or enum case names.
88+
public var deprecatedVarName: String? {
89+
guard let deprecatedName = deprecatedName else {
90+
return nil
91+
}
92+
return lowercaseFirstWord(name: deprecatedName)
93+
}
94+
8695
/// If the child ends with "token" in the kind, it's considered a token node.
8796
/// Grab the existing reference to that token from the global list.
8897
public var tokenKind: String? {
@@ -118,7 +127,7 @@ public class Child {
118127
/// Whether this child has syntax kind `UnexpectedNodes`.
119128
public var isUnexpectedNodes: Bool {
120129
switch kind {
121-
case .collection(kind: .unexpectedNodes, collectionElementName: _):
130+
case .collection(kind: .unexpectedNodes, _, _):
122131
return true
123132
default:
124133
return false
@@ -133,7 +142,7 @@ public class Child {
133142
return choices.isEmpty
134143
case .node(let kind):
135144
return kind.isBase
136-
case .collection(kind: let kind, collectionElementName: _):
145+
case .collection(let kind, _, _):
137146
return kind.isBase
138147
case .token:
139148
return false
@@ -153,6 +162,7 @@ public class Child {
153162
/// identifiers) inherit the syntax classification.
154163
init(
155164
name: String,
165+
deprecatedName: String? = nil,
156166
kind: ChildKind,
157167
nameForDiagnostics: String? = nil,
158168
documentation: String? = nil,
@@ -165,6 +175,7 @@ public class Child {
165175
precondition(firstCharInName.isUppercase == true, "The first letter of a child’s name should be uppercase")
166176
}
167177
self.name = name
178+
self.deprecatedName = deprecatedName
168179
self.kind = kind
169180
self.nameForDiagnostics = nameForDiagnostics
170181
self.documentation = documentation

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ public let DECL_NODES: [Node] = [
649649
),
650650
Child(
651651
name: "Placeholder",
652+
deprecatedName: "Identifier",
652653
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
653654
documentation: """
654655
The actual editor placeholder that starts with `<#` and ends with `#>`.
@@ -863,6 +864,7 @@ public let DECL_NODES: [Node] = [
863864
),
864865
Child(
865866
name: "GenericParameterClause",
867+
deprecatedName: "GenericParameters",
866868
kind: .node(kind: .genericParameterClause),
867869
nameForDiagnostics: "generic parameter clause",
868870
documentation: "The generic parameters, if any, for this enum declaration.",
@@ -1205,6 +1207,7 @@ public let DECL_NODES: [Node] = [
12051207
),
12061208
Child(
12071209
name: "ImportKeyword",
1210+
deprecatedName: "ImportTok",
12081211
kind: .token(choices: [.keyword(text: "import")]),
12091212
documentation: "The `import` keyword for this declaration."
12101213
),
@@ -1909,6 +1912,7 @@ public let DECL_NODES: [Node] = [
19091912
children: [
19101913
Child(
19111914
name: "HigherThanOrLowerThanKeyword",
1915+
deprecatedName: "HigherThanOrLowerThan",
19121916
kind: .token(choices: [.keyword(text: "higherThan"), .keyword(text: "lowerThan")]),
19131917
documentation: "The relation to specified other precedence groups.",
19141918
classification: "Keyword"

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public let EXPR_NODES: [Node] = [
4848
children: [
4949
Child(
5050
name: "LeftSquare",
51+
deprecatedName: "LeftSquareBracket",
5152
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
5253
),
5354
Child(
@@ -57,6 +58,7 @@ public let EXPR_NODES: [Node] = [
5758
),
5859
Child(
5960
name: "RightSquare",
61+
deprecatedName: "RightSquareBracket",
6062
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
6163
),
6264
]
@@ -1777,6 +1779,7 @@ public let EXPR_NODES: [Node] = [
17771779
),
17781780
Child(
17791781
name: "Elements",
1782+
deprecatedName: "ElementList",
17801783
kind: .collection(kind: .tupleExprElementList, collectionElementName: "Element"),
17811784
isIndented: true
17821785
),

CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public let GENERIC_NODES: [Node] = [
4545
),
4646
Child(
4747
name: "Parameters",
48-
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter")
48+
deprecatedName: "GenericParameterList",
49+
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter", deprecatedCollectionElementName: "GenericParameter")
4950
),
5051
Child(
5152
name: "GenericWhereClause",

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,32 @@ public class Node {
115115
childrenWithUnexpected =
116116
children.enumerated().flatMap { (i, child) -> [Child] in
117117
let unexpectedName: String
118+
let unexpectedDeprecatedName: String?
119+
118120
if i == 0 {
119121
unexpectedName = "UnexpectedBefore\(child.name)"
122+
unexpectedDeprecatedName = child.deprecatedName.map { "UnexpectedBefore\($0)" }
120123
} else {
121124
unexpectedName = "UnexpectedBetween\(children[i - 1].name)And\(child.name)"
125+
if let deprecatedName = children[i - 1].deprecatedName {
126+
unexpectedDeprecatedName = "UnexpectedBetween\(deprecatedName)And\(child.deprecatedName ?? child.name)"
127+
} else if let deprecatedName = child.deprecatedName {
128+
unexpectedDeprecatedName = "UnexpectedBetween\(children[i - 1].name)And\(deprecatedName)"
129+
} else {
130+
unexpectedDeprecatedName = nil
131+
}
122132
}
123133
let unexpectedBefore = Child(
124134
name: unexpectedName,
135+
deprecatedName: unexpectedDeprecatedName,
125136
kind: .collection(kind: .unexpectedNodes, collectionElementName: unexpectedName),
126137
isOptional: true
127138
)
128139
return [unexpectedBefore, child]
129140
} + [
130141
Child(
131142
name: "UnexpectedAfter\(children.last!.name)",
143+
deprecatedName: children.last!.deprecatedName.map { "UnexpectedAfter\($0)" },
132144
kind: .collection(kind: .unexpectedNodes, collectionElementName: "UnexpectedAfter\(children.last!.name)"),
133145
isOptional: true
134146
)

CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public let STMT_NODES: [Node] = [
2727
),
2828
Child(
2929
name: "AvailabilityArguments",
30+
deprecatedName: "AvailabilitySpec",
3031
kind: .collection(kind: .availabilitySpecList, collectionElementName: "AvailabilityArgument")
3132
),
3233
Child(

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public let TYPE_NODES: [Node] = [
1919
children: [
2020
Child(
2121
name: "LeftSquare",
22+
deprecatedName: "LeftSquareBracket",
2223
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
2324
),
2425
Child(
@@ -27,6 +28,7 @@ public let TYPE_NODES: [Node] = [
2728
),
2829
Child(
2930
name: "RightSquare",
31+
deprecatedName: "RightSquareBracket",
3032
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
3133
),
3234
]
@@ -144,6 +146,7 @@ public let TYPE_NODES: [Node] = [
144146
children: [
145147
Child(
146148
name: "LeftSquare",
149+
deprecatedName: "LeftSquareBracket",
147150
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
148151
),
149152
Child(
@@ -162,6 +165,7 @@ public let TYPE_NODES: [Node] = [
162165
),
163166
Child(
164167
name: "RightSquare",
168+
deprecatedName: "RightSquareBracket",
165169
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
166170
),
167171
]
@@ -184,7 +188,8 @@ public let TYPE_NODES: [Node] = [
184188
),
185189
Child(
186190
name: "Parameters",
187-
kind: .collection(kind: .tupleTypeElementList, collectionElementName: "Parameter"),
191+
deprecatedName: "arguments",
192+
kind: .collection(kind: .tupleTypeElementList, collectionElementName: "Parameter", deprecatedCollectionElementName: "Argument"),
188193
isIndented: true
189194
),
190195
Child(
@@ -331,6 +336,7 @@ public let TYPE_NODES: [Node] = [
331336
children: [
332337
Child(
333338
name: "GenericParameterClause",
339+
deprecatedName: "GenericParameters",
334340
kind: .node(kind: .genericParameterClause)
335341
),
336342
Child(

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public extension Child {
3333
buildableKind = .node(kind: kind)
3434
case .nodeChoices:
3535
buildableKind = .node(kind: .syntax)
36-
case .collection(kind: let kind, collectionElementName: _):
36+
case .collection(let kind, _, _):
3737
buildableKind = .node(kind: kind)
3838
case .token:
3939
buildableKind = .token(tokenKind: self.tokenKind!)

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
102102
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["Keyword.swift"], keywordFile),
103103
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["raw", "RawSyntaxNodes.swift"], rawSyntaxNodesFile),
104104
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["raw", "RawSyntaxValidation.swift"], rawSyntaxValidationFile),
105+
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["RenamedChildrenCompatibility.swift"], renamedChildrenCompatibilityFile),
105106
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxAnyVisitor.swift"], syntaxAnyVisitorFile),
106107
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxBaseNodes.swift"], syntaxBaseNodesFile),
107108
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxCollections.swift"], syntaxCollectionsFile),
@@ -123,6 +124,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
123124
swiftSyntaxBuilderGeneratedDir + ["SyntaxExpressibleByStringInterpolationConformances.swift"],
124125
syntaxExpressibleByStringInterpolationConformancesFile
125126
),
127+
GeneratedFileSpec(swiftSyntaxBuilderGeneratedDir + ["RenamedChildrenBuilderCompatibility.swift"], renamedChildrenBuilderCompatibilityFile),
126128
]
127129
+ BASE_KIND_FILES.map { baseKind in
128130
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["syntaxNodes", baseKind.value], syntaxNode(emitKind: baseKind.key))

0 commit comments

Comments
 (0)