Skip to content

Commit 403b363

Browse files
committed
Make all AttributeListSyntax children non-optional
1 parent 9bdab58 commit 403b363

32 files changed

+428
-430
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ public let COMMON_NODES: [Node] = [
166166
children: [
167167
Child(
168168
name: "Attributes",
169-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
170-
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these.",
171-
isOptional: true
169+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
170+
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
172171
),
173172
Child(
174173
name: "Modifiers",

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ public let DECL_NODES: [Node] = [
8484
children: [
8585
Child(
8686
name: "Attributes",
87-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
88-
nameForDiagnostics: "attributes",
89-
isOptional: true
87+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
88+
nameForDiagnostics: "attributes"
9089
),
9190
Child(
9291
name: "Modifier",
@@ -186,9 +185,8 @@ public let DECL_NODES: [Node] = [
186185
children: [
187186
Child(
188187
name: "Attributes",
189-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
190-
nameForDiagnostics: "attributes",
191-
isOptional: true
188+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
189+
nameForDiagnostics: "attributes"
192190
),
193191
Child(
194192
name: "Modifiers",
@@ -275,10 +273,9 @@ public let DECL_NODES: [Node] = [
275273
children: [
276274
Child(
277275
name: "Attributes",
278-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
276+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
279277
nameForDiagnostics: "attributes",
280-
documentation: "Attributes attached to the associated type declaration.",
281-
isOptional: true
278+
documentation: "Attributes attached to the associated type declaration."
282279
),
283280
Child(
284281
name: "Modifiers",
@@ -366,10 +363,9 @@ public let DECL_NODES: [Node] = [
366363
children: [
367364
Child(
368365
name: "Attributes",
369-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
366+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
370367
nameForDiagnostics: "attributes",
371-
documentation: "Attributes attached to the class declaration, such as an `@available` attribute.",
372-
isOptional: true
368+
documentation: "Attributes attached to the class declaration, such as an `@available` attribute."
373369
),
374370
Child(
375371
name: "Modifiers",
@@ -515,10 +511,9 @@ public let DECL_NODES: [Node] = [
515511
children: [
516512
Child(
517513
name: "Attributes",
518-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
514+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
519515
nameForDiagnostics: "attributes",
520-
documentation: "Attributes that are attached to the deinitializer.",
521-
isOptional: true
516+
documentation: "Attributes that are attached to the deinitializer."
522517
),
523518
Child(
524519
name: "Modifiers",
@@ -584,9 +579,8 @@ public let DECL_NODES: [Node] = [
584579
children: [
585580
Child(
586581
name: "Attributes",
587-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
588-
documentation: "If there were attributes before the editor placeholder, the ``EditorPlaceholderDeclSyntax`` will contain these.",
589-
isOptional: true
582+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
583+
documentation: "If there were attributes before the editor placeholder, the ``EditorPlaceholderDeclSyntax`` will contain these."
590584
),
591585
Child(
592586
name: "Modifiers",
@@ -702,10 +696,9 @@ public let DECL_NODES: [Node] = [
702696
children: [
703697
Child(
704698
name: "Attributes",
705-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
699+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
706700
nameForDiagnostics: "attributes",
707-
documentation: "The attributes applied to the case declaration.",
708-
isOptional: true
701+
documentation: "The attributes applied to the case declaration."
709702
),
710703
Child(
711704
name: "Modifiers",
@@ -788,10 +781,9 @@ public let DECL_NODES: [Node] = [
788781
children: [
789782
Child(
790783
name: "Attributes",
791-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
784+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
792785
nameForDiagnostics: "attributes",
793-
documentation: "The attributes applied to the enum declaration.",
794-
isOptional: true
786+
documentation: "The attributes applied to the enum declaration."
795787
),
796788
Child(
797789
name: "Modifiers",
@@ -859,9 +851,8 @@ public let DECL_NODES: [Node] = [
859851
children: [
860852
Child(
861853
name: "Attributes",
862-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
863-
nameForDiagnostics: "attributes",
864-
isOptional: true
854+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
855+
nameForDiagnostics: "attributes"
865856
),
866857
Child(
867858
name: "Modifiers",
@@ -909,9 +900,8 @@ public let DECL_NODES: [Node] = [
909900
children: [
910901
Child(
911902
name: "Attributes",
912-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
913-
nameForDiagnostics: "attributes",
914-
isOptional: true
903+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
904+
nameForDiagnostics: "attributes"
915905
),
916906
Child(
917907
name: "Modifiers",
@@ -978,9 +968,8 @@ public let DECL_NODES: [Node] = [
978968
children: [
979969
Child(
980970
name: "Attributes",
981-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
982-
nameForDiagnostics: "attributes",
983-
isOptional: true
971+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
972+
nameForDiagnostics: "attributes"
984973
),
985974
Child(
986975
name: "Modifiers",
@@ -1145,10 +1134,9 @@ public let DECL_NODES: [Node] = [
11451134
children: [
11461135
Child(
11471136
name: "Attributes",
1148-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1137+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
11491138
nameForDiagnostics: "attributes",
1150-
documentation: "Attributes attached to the import declaration, for example `@testable`.",
1151-
isOptional: true
1139+
documentation: "Attributes attached to the import declaration, for example `@testable`."
11521140
),
11531141
Child(
11541142
name: "Modifiers",
@@ -1260,10 +1248,9 @@ public let DECL_NODES: [Node] = [
12601248
children: [
12611249
Child(
12621250
name: "Attributes",
1263-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1251+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
12641252
nameForDiagnostics: "attributes",
1265-
documentation: "Attributes that are attached to the initializer.",
1266-
isOptional: true
1253+
documentation: "Attributes that are attached to the initializer."
12671254
),
12681255
Child(
12691256
name: "Modifiers",
@@ -1328,9 +1315,8 @@ public let DECL_NODES: [Node] = [
13281315
children: [
13291316
Child(
13301317
name: "Attributes",
1331-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1332-
nameForDiagnostics: "attributes",
1333-
isOptional: true
1318+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
1319+
nameForDiagnostics: "attributes"
13341320
),
13351321
Child(
13361322
name: "Modifiers",
@@ -1387,9 +1373,8 @@ public let DECL_NODES: [Node] = [
13871373
children: [
13881374
Child(
13891375
name: "Attributes",
1390-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1391-
nameForDiagnostics: "attributes",
1392-
isOptional: true
1376+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
1377+
nameForDiagnostics: "attributes"
13931378
),
13941379
Child(
13951380
name: "Modifiers",
@@ -1827,10 +1812,9 @@ public let DECL_NODES: [Node] = [
18271812
children: [
18281813
Child(
18291814
name: "Attributes",
1830-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1815+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
18311816
nameForDiagnostics: "attributes",
1832-
documentation: "The attributes applied to the 'precedencegroup' declaration.",
1833-
isOptional: true
1817+
documentation: "The attributes applied to the 'precedencegroup' declaration."
18341818
),
18351819
Child(
18361820
name: "Modifiers",
@@ -1943,10 +1927,9 @@ public let DECL_NODES: [Node] = [
19431927
children: [
19441928
Child(
19451929
name: "Attributes",
1946-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
1930+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
19471931
nameForDiagnostics: "attributes",
1948-
documentation: "Attributes attached to the protocol declaration, such as an `@available` attribute.",
1949-
isOptional: true
1932+
documentation: "Attributes attached to the protocol declaration, such as an `@available` attribute."
19501933
),
19511934
Child(
19521935
name: "Modifiers",
@@ -2114,10 +2097,9 @@ public let DECL_NODES: [Node] = [
21142097
children: [
21152098
Child(
21162099
name: "Attributes",
2117-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
2100+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
21182101
nameForDiagnostics: "attributes",
2119-
documentation: "Attributes that are attached to the struct declaration.",
2120-
isOptional: true
2102+
documentation: "Attributes that are attached to the struct declaration."
21212103
),
21222104
Child(
21232105
name: "Modifiers",
@@ -2178,9 +2160,8 @@ public let DECL_NODES: [Node] = [
21782160
children: [
21792161
Child(
21802162
name: "Attributes",
2181-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
2182-
nameForDiagnostics: "attributes",
2183-
isOptional: true
2163+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
2164+
nameForDiagnostics: "attributes"
21842165
),
21852166
Child(
21862167
name: "Modifiers",
@@ -2277,9 +2258,8 @@ public let DECL_NODES: [Node] = [
22772258
children: [
22782259
Child(
22792260
name: "Attributes",
2280-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
2281-
nameForDiagnostics: "attributes",
2282-
isOptional: true
2261+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
2262+
nameForDiagnostics: "attributes"
22832263
),
22842264
Child(
22852265
name: "Modifiers",
@@ -2333,9 +2313,8 @@ public let DECL_NODES: [Node] = [
23332313
children: [
23342314
Child(
23352315
name: "Attributes",
2336-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
2337-
nameForDiagnostics: "attributes",
2338-
isOptional: true
2316+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
2317+
nameForDiagnostics: "attributes"
23392318
),
23402319
Child(
23412320
name: "Modifiers",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ public let EXPR_NODES: [Node] = [
373373
children: [
374374
Child(
375375
name: "Attributes",
376-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
377-
nameForDiagnostics: "attributes",
378-
isOptional: true
376+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
377+
nameForDiagnostics: "attributes"
379378
),
380379
Child(
381380
name: "Modifiers",
@@ -525,9 +524,8 @@ public let EXPR_NODES: [Node] = [
525524
children: [
526525
Child(
527526
name: "Attributes",
528-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
529-
nameForDiagnostics: "attributes",
530-
isOptional: true
527+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
528+
nameForDiagnostics: "attributes"
531529
),
532530
Child(
533531
name: "Capture",

CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public let GENERIC_NODES: [Node] = [
9090
children: [
9191
Child(
9292
name: "Attributes",
93-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
94-
isOptional: true
93+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true)
9594
),
9695
Child(
9796
name: "EachKeyword",

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public let TRAITS: [Trait] = [
3737
Trait(
3838
traitName: "DeclGroup",
3939
children: [
40-
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true),
40+
Child(name: "Attributes", kind: .node(kind: .attributeList)),
4141
Child(name: "Modifiers", kind: .node(kind: .declModifierList)),
4242
Child(name: "InheritanceClause", kind: .node(kind: .inheritanceClause), isOptional: true),
4343
Child(
@@ -105,7 +105,7 @@ public let TRAITS: [Trait] = [
105105
Trait(
106106
traitName: "WithAttributes",
107107
children: [
108-
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true)
108+
Child(name: "Attributes", kind: .node(kind: .attributeList))
109109
]
110110
),
111111
Trait(

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public let TYPE_NODES: [Node] = [
6060
),
6161
Child(
6262
name: "Attributes",
63-
kind: .collection(kind: .attributeList, collectionElementName: "Attribute"),
64-
isOptional: true
63+
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true)
6564
),
6665
Child(
6766
name: "BaseType",

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
5757
// The missing item is not necessary to be a declaration,
5858
// which is just a placeholder here
5959
return RawCodeBlockItemSyntax(
60-
item: .decl(RawDeclSyntax(RawMissingDeclSyntax(attributes: nil, modifiers: self.emptyCollection(RawDeclModifierListSyntax.self), arena: self.arena))),
60+
item: .decl(
61+
RawDeclSyntax(
62+
RawMissingDeclSyntax(
63+
attributes: self.emptyCollection(RawAttributeListSyntax.self),
64+
modifiers: self.emptyCollection(RawDeclModifierListSyntax.self),
65+
arena: self.arena
66+
)
67+
)
68+
),
6169
semicolon: nil,
6270
arena: self.arena
6371
)

Sources/SwiftParser/Attributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
@_spi(RawSyntax) import SwiftSyntax
1414

1515
extension Parser {
16-
mutating func parseAttributeList() -> RawAttributeListSyntax? {
16+
mutating func parseAttributeList() -> RawAttributeListSyntax {
1717
guard self.at(.atSign, .poundIf) else {
18-
return nil
18+
return self.emptyCollection(RawAttributeListSyntax.self)
1919
}
2020

2121
var elements = [RawAttributeListSyntax.Element]()

Sources/SwiftParser/CollectionNodes+Parsable.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension AccessorDeclListSyntax: SyntaxParseable {
5858
return parser.parseAccessorList() ?? RawAccessorDeclListSyntax(elements: [], arena: parser.arena)
5959
} makeMissing: { remainingTokens, arena in
6060
return RawAccessorDeclSyntax(
61-
attributes: nil,
61+
attributes: RawAttributeListSyntax(elements: [], arena: arena),
6262
modifier: nil,
6363
accessorSpecifier: RawTokenSyntax(missing: .keyword, text: "get", arena: arena),
6464
parameters: nil,
@@ -73,8 +73,7 @@ extension AccessorDeclListSyntax: SyntaxParseable {
7373
extension AttributeListSyntax: SyntaxParseable {
7474
public static func parse(from parser: inout Parser) -> Self {
7575
return parse(from: &parser) { parser in
76-
let node = parser.parseAttributeList() ?? RawAttributeListSyntax(elements: [], arena: parser.arena)
77-
return RawSyntax(node)
76+
return RawSyntax(parser.parseAttributeList())
7877
} makeMissing: { remainingTokens, arena in
7978
return RawAttributeSyntax(
8079
atSign: RawTokenSyntax(missing: .atSign, arena: arena),
@@ -106,7 +105,7 @@ extension MemberBlockItemListSyntax: SyntaxParseable {
106105
return RawSyntax(parser.parseMemberDeclList())
107106
} makeMissing: { remainingTokens, arena in
108107
let missingDecl = RawMissingDeclSyntax(
109-
attributes: nil,
108+
attributes: RawAttributeListSyntax(elements: [], arena: arena),
110109
modifiers: RawDeclModifierListSyntax(elements: [], arena: arena),
111110
placeholder: RawTokenSyntax(missing: .identifier, text: "<#declaration#>", arena: arena),
112111
RawUnexpectedNodesSyntax(remainingTokens, arena: arena),

0 commit comments

Comments
 (0)