Skip to content

Commit c186fe3

Browse files
committed
Add "late specifiers" to attributed types.
This is needed to account for 'nonisolated' occuring after type attributes within a protocol conformance.
1 parent e8c3dcf commit c186fe3

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public enum ChildKind {
4747
kind: SyntaxNodeKind,
4848
collectionElementName: String? = nil,
4949
defaultsToEmpty: Bool = false,
50-
deprecatedCollectionElementName: String? = nil
50+
deprecatedCollectionElementName: String? = nil,
51+
generateDeprecatedAddFunction: Bool = true
5152
)
5253
/// The child is a token that matches one of the given `choices`.
5354
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
@@ -132,7 +133,7 @@ public class Child: NodeChoiceConvertible {
132133
return kind
133134
case .nodeChoices:
134135
return .syntax
135-
case .collection(kind: let kind, _, _, _):
136+
case .collection(kind: let kind, _, _, _, _):
136137
return kind
137138
case .token:
138139
return .token
@@ -268,7 +269,7 @@ public class Child: NodeChoiceConvertible {
268269
/// Whether this child has syntax kind `UnexpectedNodes`.
269270
public var isUnexpectedNodes: Bool {
270271
switch kind {
271-
case .collection(kind: .unexpectedNodes, _, _, _):
272+
case .collection(kind: .unexpectedNodes, _, _, _, _):
272273
return true
273274
default:
274275
return false
@@ -283,7 +284,7 @@ public class Child: NodeChoiceConvertible {
283284
return choices.isEmpty
284285
case .node(let kind):
285286
return kind.isBase
286-
case .collection(kind: let kind, _, _, _):
287+
case .collection(kind: let kind, _, _, _, _):
287288
return kind.isBase
288289
case .token:
289290
return false

CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct GrammarGenerator {
4141
case .nodeChoices(let choices, _):
4242
let choicesDescriptions = choices.map { grammar(for: $0) }
4343
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
44-
case .collection(kind: let kind, _, _, _):
44+
case .collection(kind: let kind, _, _, _, _):
4545
return "\(kind.doccLink)\(optionality)"
4646
case .token(let choices, _, _):
4747
if choices.count == 1 {

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ fileprivate extension Child {
391391
return [kind]
392392
case .nodeChoices(let choices, _):
393393
return choices.flatMap(\.kinds)
394-
case .collection(kind: let kind, _, _, _):
394+
case .collection(kind: let kind, _, _, _, _):
395395
return [kind]
396396
case .token:
397397
return [.token]

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public let TYPE_NODES: [Node] = [
5757
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
5858
documentation: "A list of attributes that can be attached to the type, such as `@escaping`."
5959
),
60+
Child(
61+
name: "lateSpecifiers",
62+
kind: .collection(kind: .typeSpecifierList, collectionElementName: "Specifier", defaultsToEmpty: true,
63+
generateDeprecatedAddFunction: false),
64+
documentation:
65+
"A list of specifiers that can be attached to the type after the attributes, such as 'nonisolated'."
66+
),
6067
Child(
6168
name: "baseType",
6269
kind: .node(kind: .type),

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension Child {
3333
buildableKind = .node(kind: kind)
3434
case .nodeChoices:
3535
buildableKind = .node(kind: .syntax)
36-
case .collection(kind: let kind, _, _, _):
36+
case .collection(kind: let kind, _, _, _, _):
3737
buildableKind = .node(kind: kind)
3838
case .token:
3939
buildableKind = .token(self.tokenKind!)
@@ -65,7 +65,7 @@ extension Child {
6565
return ExprSyntax("nil")
6666
}
6767
}
68-
if case .collection(_, _, defaultsToEmpty: true, _) = kind {
68+
if case .collection(_, _, defaultsToEmpty: true, _, _) = kind {
6969
return ExprSyntax("[]")
7070
}
7171
guard let token = token, isToken else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func makeCompatibilityAddMethod(for child: Child) -> DeclSyntax? {
8585
kind: _,
8686
collectionElementName: let collectionElementName?,
8787
defaultsToEmpty: _,
88-
deprecatedCollectionElementName: let deprecatedCollectionElementName?
88+
deprecatedCollectionElementName: let deprecatedCollectionElementName?,
89+
generateDeprecatedAddFunction: _
8990
) = child.kind
9091
{
9192
let childEltType = childNode.collectionElementType.syntaxBaseName

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
176176
// If needed, this could be added in the future, but for now withUnexpected should be sufficient.
177177
if let childNode = SYNTAX_NODE_MAP[child.syntaxNodeKind]?.collectionNode,
178178
!child.isUnexpectedNodes,
179-
case .collection(_, collectionElementName: let childElt?, _, _) = child.kind
179+
case .collection(_, collectionElementName: let childElt?, _, _, generateDeprecatedAddFunction: true) = child.kind
180180
{
181181
let childEltType = childNode.collectionElementType.syntaxBaseName
182182

0 commit comments

Comments
 (0)