Skip to content

Commit 1621138

Browse files
committed
Split FunctionParameterSyntax and related types
FunctionParameterSyntax was used in a number of cases (function parameter, closure parameter and enum case parameter) and because it needs to satisfy all of them all its parameters are optional. Split it into three different types that have non-optional children. rdar://106874808
1 parent 96e6850 commit 1621138

35 files changed

+5568
-2377
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,94 @@ public let DECL_NODES: [Node] = [
428428
]
429429
),
430430

431+
Node(
432+
name: "EnumCaseParameterClause",
433+
nameForDiagnostics: "parameter clause",
434+
kind: "Syntax",
435+
traits: [
436+
"Parenthesized"
437+
],
438+
children: [
439+
Child(
440+
name: "LeftParen",
441+
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
442+
description: "The '(' to open the parameter clause."
443+
),
444+
Child(
445+
name: "ParameterList",
446+
kind: .collection(kind: "EnumCaseParameterList", collectionElementName: "Parameter"),
447+
nameForDiagnostics: "parameters",
448+
description: "The actual parameters.",
449+
isIndented: true
450+
),
451+
Child(
452+
name: "RightParen",
453+
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
454+
description: "The ')' to close the parameter clause."
455+
),
456+
]
457+
),
458+
459+
Node(
460+
name: "EnumCaseParameterList",
461+
nameForDiagnostics: "parameter list",
462+
kind: "SyntaxCollection",
463+
element: "EnumCaseParameter"
464+
),
465+
466+
Node(
467+
name: "EnumCaseParameter",
468+
nameForDiagnostics: "parameter",
469+
kind: "Syntax",
470+
traits: [
471+
"WithTrailingComma"
472+
],
473+
parserFunction: "parseEnumCaseParameter",
474+
children: [
475+
Child(
476+
name: "Modifiers",
477+
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
478+
nameForDiagnostics: "modifiers",
479+
isOptional: true
480+
),
481+
Child(
482+
name: "FirstName",
483+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
484+
isOptional: true
485+
),
486+
Child(
487+
name: "SecondName",
488+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
489+
isOptional: true
490+
),
491+
Child(
492+
name: "Colon",
493+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
494+
description: "If the parameter has a label, the colon separating the label from the type.",
495+
isOptional: true
496+
),
497+
Child(
498+
name: "Type",
499+
kind: .node(kind: "Type"),
500+
nameForDiagnostics: "type",
501+
description: "The parameter's type."
502+
),
503+
Child(
504+
name: "DefaultArgument",
505+
kind: .node(kind: "InitializerClause"),
506+
nameForDiagnostics: "default argument",
507+
description: "If the parameter has a default value, the initializer clause describing the default value.",
508+
isOptional: true
509+
),
510+
Child(
511+
name: "TrailingComma",
512+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
513+
description: "If the parameter is followed by another parameter, the comma separating them.",
514+
isOptional: true
515+
),
516+
]
517+
),
518+
431519
Node(
432520
name: "EnumCaseDecl",
433521
nameForDiagnostics: "enum case",
@@ -489,7 +577,7 @@ public let DECL_NODES: [Node] = [
489577
),
490578
Child(
491579
name: "AssociatedValue",
492-
kind: .node(kind: "ParameterClause"),
580+
kind: .node(kind: "EnumCaseParameterClause"),
493581
nameForDiagnostics: "associated values",
494582
description: "The set of associated values of the case.",
495583
isOptional: true
@@ -699,6 +787,7 @@ public let DECL_NODES: [Node] = [
699787
"WithTrailingComma",
700788
"Attributed",
701789
],
790+
parserFunction: "parseFunctionParameter",
702791
children: [
703792
Child(
704793
name: "Attributes",
@@ -714,8 +803,7 @@ public let DECL_NODES: [Node] = [
714803
),
715804
Child(
716805
name: "FirstName",
717-
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
718-
isOptional: true
806+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")])
719807
),
720808
// One of these two names needs be optional, we choose the second
721809
// name to avoid backtracking.
@@ -727,14 +815,12 @@ public let DECL_NODES: [Node] = [
727815
),
728816
Child(
729817
name: "Colon",
730-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
731-
isOptional: true
818+
kind: .token(choices: [.token(tokenKind: "ColonToken")])
732819
),
733820
Child(
734821
name: "Type",
735822
kind: .node(kind: "Type"),
736-
nameForDiagnostics: "type",
737-
isOptional: true
823+
nameForDiagnostics: "type"
738824
),
739825
Child(
740826
name: "Ellipsis",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,101 @@ public let EXPR_NODES: [Node] = [
301301
]
302302
),
303303

304+
Node(
305+
name: "ClosureParameter",
306+
nameForDiagnostics: "parameter",
307+
kind: "Syntax",
308+
traits: [
309+
"WithTrailingComma"
310+
],
311+
parserFunction: "parseClosureParameter",
312+
children: [
313+
Child(
314+
name: "Attributes",
315+
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
316+
nameForDiagnostics: "attributes",
317+
isOptional: true
318+
),
319+
Child(
320+
name: "Modifiers",
321+
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
322+
nameForDiagnostics: "modifiers",
323+
isOptional: true
324+
),
325+
Child(
326+
name: "FirstName",
327+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
328+
description: "The label of this parameter that will be used when the closure is called."
329+
),
330+
Child(
331+
name: "SecondName",
332+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
333+
description: "If this is specified, it is the name by which the parameter can be referenced inside the closure body. If it is `nil`, the closure parameter is referenced by the first name.",
334+
isOptional: true
335+
),
336+
Child(
337+
name: "Colon",
338+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
339+
description: "The colon separating the parameter's name and type.",
340+
isOptional: true
341+
),
342+
Child(
343+
name: "Type",
344+
kind: .node(kind: "Type"),
345+
nameForDiagnostics: "type",
346+
description: "The type of the parameter.",
347+
isOptional: true
348+
),
349+
Child(
350+
name: "Ellipsis",
351+
kind: .token(choices: [.token(tokenKind: "EllipsisToken")]),
352+
description: "If the parameter is variadic, `...` to indicate that.",
353+
isOptional: true
354+
),
355+
Child(
356+
name: "TrailingComma",
357+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
358+
description: "If the parameter is followed by another parameter, the comma separating them.",
359+
isOptional: true
360+
),
361+
]
362+
),
363+
364+
Node(
365+
name: "ClosureParameterList",
366+
nameForDiagnostics: "parameter list",
367+
kind: "SyntaxCollection",
368+
element: "ClosureParameter"
369+
),
370+
371+
Node(
372+
name: "ClosureParameterClause",
373+
nameForDiagnostics: "parameter clause",
374+
kind: "Syntax",
375+
traits: [
376+
"Parenthesized"
377+
],
378+
children: [
379+
Child(
380+
name: "LeftParen",
381+
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
382+
description: "The '(' to open the parameter clause."
383+
),
384+
Child(
385+
name: "ParameterList",
386+
kind: .collection(kind: "ClosureParameterList", collectionElementName: "Parameter"),
387+
nameForDiagnostics: "parameters",
388+
description: "The actual parameters.",
389+
isIndented: true
390+
),
391+
Child(
392+
name: "RightParen",
393+
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
394+
description: "The ')' to close the parameter clause."
395+
),
396+
]
397+
),
398+
304399
Node(
305400
name: "ClosureExpr",
306401
nameForDiagnostics: "closure",
@@ -389,7 +484,7 @@ public let EXPR_NODES: [Node] = [
389484
),
390485
Child(
391486
name: "Input",
392-
kind: .node(kind: "ParameterClause")
487+
kind: .node(kind: "ClosureParameterClause")
393488
),
394489
]),
395490
isOptional: true

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ open class BasicFormat: SyntaxRewriter {
9999
return true
100100
case \ClosureExprSyntax.statements:
101101
return true
102+
case \ClosureParameterClauseSyntax.parameterList:
103+
return true
102104
case \CodeBlockSyntax.statements:
103105
return true
104106
case \DictionaryElementSyntax.valueExpression:
105107
return true
106108
case \DictionaryExprSyntax.content:
107109
return true
110+
case \EnumCaseParameterClauseSyntax.parameterList:
111+
return true
108112
case \FunctionCallExprSyntax.argumentList:
109113
return true
110114
case \FunctionTypeSyntax.arguments:

Sources/SwiftParser/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_swift_host_library(SwiftParser
1818
Modifiers.swift
1919
Names.swift
2020
Nominals.swift
21+
Parameters.swift
2122
Parser.swift
2223
Patterns.swift
2324
TokenSpec.swift

0 commit comments

Comments
 (0)