Skip to content

Commit 5446b66

Browse files
committed
Make DeclModifierList children non-optional
1 parent 33e6274 commit 5446b66

27 files changed

+385
-390
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ public let COMMON_NODES: [Node] = [
172172
),
173173
Child(
174174
name: "Modifiers",
175-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
176-
documentation: "If there were standalone modifiers without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these.",
177-
isOptional: true
175+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
176+
documentation: "If there were standalone modifiers without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
178177
),
179178
Child(
180179
name: "Placeholder",

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ public let DECL_NODES: [Node] = [
192192
),
193193
Child(
194194
name: "Modifiers",
195-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
196-
nameForDiagnostics: "modifiers",
197-
isOptional: true
195+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
196+
nameForDiagnostics: "modifiers"
198197
),
199198
Child(
200199
name: "ActorKeyword",
@@ -283,10 +282,9 @@ public let DECL_NODES: [Node] = [
283282
),
284283
Child(
285284
name: "Modifiers",
286-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
285+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
287286
nameForDiagnostics: "modifiers",
288-
documentation: "Modifiers attached to the associated type declaration.",
289-
isOptional: true
287+
documentation: "Modifiers attached to the associated type declaration."
290288
),
291289
Child(
292290
name: "AssociatedtypeKeyword",
@@ -375,10 +373,9 @@ public let DECL_NODES: [Node] = [
375373
),
376374
Child(
377375
name: "Modifiers",
378-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
376+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
379377
nameForDiagnostics: "modifiers",
380-
documentation: "Modifiers attached to the class declaration, such as `public`.",
381-
isOptional: true
378+
documentation: "Modifiers attached to the class declaration, such as `public`."
382379
),
383380
Child(
384381
name: "ClassKeyword",
@@ -525,10 +522,9 @@ public let DECL_NODES: [Node] = [
525522
),
526523
Child(
527524
name: "Modifiers",
528-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
525+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
529526
nameForDiagnostics: "modifiers",
530-
documentation: "Modifiers that are attached to the deinitializer.",
531-
isOptional: true
527+
documentation: "Modifiers that are attached to the deinitializer."
532528
),
533529
Child(
534530
name: "DeinitKeyword",
@@ -594,9 +590,8 @@ public let DECL_NODES: [Node] = [
594590
),
595591
Child(
596592
name: "Modifiers",
597-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
598-
documentation: "If there were modifiers before the editor placeholder, the `EditorPlaceholderDecl` will contain these.",
599-
isOptional: true
593+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
594+
documentation: "If there were modifiers before the editor placeholder, the `EditorPlaceholderDecl` will contain these."
600595
),
601596
Child(
602597
name: "Placeholder",
@@ -653,9 +648,8 @@ public let DECL_NODES: [Node] = [
653648
children: [
654649
Child(
655650
name: "Modifiers",
656-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
657-
nameForDiagnostics: "modifiers",
658-
isOptional: true
651+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
652+
nameForDiagnostics: "modifiers"
659653
),
660654
Child(
661655
name: "FirstName",
@@ -715,10 +709,9 @@ public let DECL_NODES: [Node] = [
715709
),
716710
Child(
717711
name: "Modifiers",
718-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
712+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
719713
nameForDiagnostics: "modifiers",
720-
documentation: "The declaration modifiers applied to the case declaration.",
721-
isOptional: true
714+
documentation: "The declaration modifiers applied to the case declaration."
722715
),
723716
Child(
724717
name: "CaseKeyword",
@@ -802,10 +795,9 @@ public let DECL_NODES: [Node] = [
802795
),
803796
Child(
804797
name: "Modifiers",
805-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
798+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
806799
nameForDiagnostics: "modifiers",
807-
documentation: "The declaration modifiers applied to the enum declaration.",
808-
isOptional: true
800+
documentation: "The declaration modifiers applied to the enum declaration."
809801
),
810802
Child(
811803
name: "EnumKeyword",
@@ -873,9 +865,8 @@ public let DECL_NODES: [Node] = [
873865
),
874866
Child(
875867
name: "Modifiers",
876-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
877-
nameForDiagnostics: "modifiers",
878-
isOptional: true
868+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
869+
nameForDiagnostics: "modifiers"
879870
),
880871
Child(
881872
name: "ExtensionKeyword",
@@ -924,9 +915,8 @@ public let DECL_NODES: [Node] = [
924915
),
925916
Child(
926917
name: "Modifiers",
927-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
928-
nameForDiagnostics: "modifiers",
929-
isOptional: true
918+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
919+
nameForDiagnostics: "modifiers"
930920
),
931921
Child(
932922
name: "FuncKeyword",
@@ -994,9 +984,8 @@ public let DECL_NODES: [Node] = [
994984
),
995985
Child(
996986
name: "Modifiers",
997-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
998-
nameForDiagnostics: "modifiers",
999-
isOptional: true
987+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
988+
nameForDiagnostics: "modifiers"
1000989
),
1001990
Child(
1002991
name: "FirstName",
@@ -1163,10 +1152,9 @@ public let DECL_NODES: [Node] = [
11631152
),
11641153
Child(
11651154
name: "Modifiers",
1166-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1155+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
11671156
nameForDiagnostics: "modifiers",
1168-
documentation: "Modifiers attached to the import declaration. Currently, no modifiers are supported by Swift.",
1169-
isOptional: true
1157+
documentation: "Modifiers attached to the import declaration. Currently, no modifiers are supported by Swift."
11701158
),
11711159
Child(
11721160
name: "ImportKeyword",
@@ -1279,10 +1267,9 @@ public let DECL_NODES: [Node] = [
12791267
),
12801268
Child(
12811269
name: "Modifiers",
1282-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1270+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
12831271
nameForDiagnostics: "modifiers",
1284-
documentation: "Modifiers attached to the initializer",
1285-
isOptional: true
1272+
documentation: "Modifiers attached to the initializer"
12861273
),
12871274
Child(
12881275
name: "InitKeyword",
@@ -1347,9 +1334,8 @@ public let DECL_NODES: [Node] = [
13471334
),
13481335
Child(
13491336
name: "Modifiers",
1350-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1351-
nameForDiagnostics: "modifiers",
1352-
isOptional: true
1337+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
1338+
nameForDiagnostics: "modifiers"
13531339
),
13541340
Child(
13551341
name: "MacroKeyword",
@@ -1407,9 +1393,8 @@ public let DECL_NODES: [Node] = [
14071393
),
14081394
Child(
14091395
name: "Modifiers",
1410-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1411-
nameForDiagnostics: "modifiers",
1412-
isOptional: true
1396+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
1397+
nameForDiagnostics: "modifiers"
14131398
),
14141399
Child(
14151400
name: "Pound",
@@ -1849,10 +1834,9 @@ public let DECL_NODES: [Node] = [
18491834
),
18501835
Child(
18511836
name: "Modifiers",
1852-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1837+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
18531838
nameForDiagnostics: "modifiers",
1854-
documentation: "The declaration modifiers applied to the 'precedencegroup' declaration.",
1855-
isOptional: true
1839+
documentation: "The declaration modifiers applied to the 'precedencegroup' declaration."
18561840
),
18571841
Child(
18581842
name: "PrecedencegroupKeyword",
@@ -1966,10 +1950,9 @@ public let DECL_NODES: [Node] = [
19661950
),
19671951
Child(
19681952
name: "Modifiers",
1969-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
1953+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
19701954
nameForDiagnostics: "modifiers",
1971-
documentation: "Modifiers attached to the protocol declaration, such as `public`.",
1972-
isOptional: true
1955+
documentation: "Modifiers attached to the protocol declaration, such as `public`."
19731956
),
19741957
Child(
19751958
name: "ProtocolKeyword",
@@ -2138,10 +2121,9 @@ public let DECL_NODES: [Node] = [
21382121
),
21392122
Child(
21402123
name: "Modifiers",
2141-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
2124+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
21422125
nameForDiagnostics: "modifiers",
2143-
documentation: "Modifiers that are attached to the struct declaration.",
2144-
isOptional: true
2126+
documentation: "Modifiers that are attached to the struct declaration."
21452127
),
21462128
Child(
21472129
name: "StructKeyword",
@@ -2202,9 +2184,8 @@ public let DECL_NODES: [Node] = [
22022184
),
22032185
Child(
22042186
name: "Modifiers",
2205-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
2206-
nameForDiagnostics: "modifiers",
2207-
isOptional: true
2187+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
2188+
nameForDiagnostics: "modifiers"
22082189
),
22092190
Child(
22102191
name: "SubscriptKeyword",
@@ -2302,9 +2283,8 @@ public let DECL_NODES: [Node] = [
23022283
),
23032284
Child(
23042285
name: "Modifiers",
2305-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
2306-
nameForDiagnostics: "modifiers",
2307-
isOptional: true
2286+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
2287+
nameForDiagnostics: "modifiers"
23082288
),
23092289
Child(
23102290
name: "TypealiasKeyword",
@@ -2359,9 +2339,8 @@ public let DECL_NODES: [Node] = [
23592339
),
23602340
Child(
23612341
name: "Modifiers",
2362-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
2363-
nameForDiagnostics: "modifiers",
2364-
isOptional: true
2342+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
2343+
nameForDiagnostics: "modifiers"
23652344
),
23662345
Child(
23672346
name: "BindingSpecifier",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,8 @@ public let EXPR_NODES: [Node] = [
379379
),
380380
Child(
381381
name: "Modifiers",
382-
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier"),
383-
nameForDiagnostics: "modifiers",
384-
isOptional: true
382+
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
383+
nameForDiagnostics: "modifiers"
385384
),
386385
Child(
387386
name: "FirstName",

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public let TRAITS: [Trait] = [
3838
traitName: "DeclGroup",
3939
children: [
4040
Child(name: "Attributes", kind: .node(kind: .attributeList), isOptional: true),
41-
Child(name: "Modifiers", kind: .node(kind: .declModifierList), isOptional: true),
41+
Child(name: "Modifiers", kind: .node(kind: .declModifierList)),
4242
Child(name: "InheritanceClause", kind: .node(kind: .inheritanceClause), isOptional: true),
4343
Child(
4444
name: "GenericWhereClause",
@@ -140,7 +140,7 @@ public let TRAITS: [Trait] = [
140140
Trait(
141141
traitName: "WithModifiers",
142142
children: [
143-
Child(name: "Modifiers", kind: .node(kind: .declModifierList), isOptional: true)
143+
Child(name: "Modifiers", kind: .node(kind: .declModifierList))
144144
]
145145
),
146146
Trait(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ 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: nil, arena: self.arena))),
60+
item: .decl(RawDeclSyntax(RawMissingDeclSyntax(attributes: nil, modifiers: self.emptyCollection(RawDeclModifierListSyntax.self), arena: self.arena))),
6161
semicolon: nil,
6262
arena: self.arena
6363
)

Sources/SwiftParser/CollectionNodes+Parsable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extension MemberBlockItemListSyntax: SyntaxParseable {
107107
} makeMissing: { remainingTokens, arena in
108108
let missingDecl = RawMissingDeclSyntax(
109109
attributes: nil,
110-
modifiers: nil,
110+
modifiers: RawDeclModifierListSyntax(elements: [], arena: arena),
111111
placeholder: RawTokenSyntax(missing: .identifier, text: "<#declaration#>", arena: arena),
112112
RawUnexpectedNodesSyntax(remainingTokens, arena: arena),
113113
arena: arena

0 commit comments

Comments
 (0)