@@ -18,18 +18,65 @@ import SwiftSyntax
18
18
19
19
// MARK: - ParamDecl
20
20
21
+ fileprivate protocol ValueParameterSyntax : SyntaxProtocol {
22
+ /// The `firstName` with optional type.
23
+ ///
24
+ /// This is the lowest denominator between `FunctionParameterSyntax` and `EnumCaseParameterSyntax`.
25
+ // FIXME: Rename once we support covariant witnesses.
26
+ var optionalFirstName : TokenSyntax ? { get }
27
+
28
+ var secondName : TokenSyntax ? { get }
29
+
30
+ /// The `firstName` with optional type.
31
+ ///
32
+ /// This is the lowest denominator between `FunctionParameterSyntax` and `EnumCaseParameterSyntax`.
33
+ // FIXME: Rename once we support covariant witnesses.
34
+ var optionalType : TypeSyntax ? { get }
35
+
36
+ var defaultValue : InitializerClauseSyntax ? { get }
37
+ }
38
+
39
+ extension FunctionParameterSyntax : ValueParameterSyntax {
40
+ fileprivate var optionalFirstName : TokenSyntax ? {
41
+ firstName
42
+ }
43
+
44
+ fileprivate var optionalType : TypeSyntax ? {
45
+ type
46
+ }
47
+ }
48
+
49
+ extension EnumCaseParameterSyntax : ValueParameterSyntax {
50
+ fileprivate var optionalFirstName : TokenSyntax ? {
51
+ firstName
52
+ }
53
+
54
+ fileprivate var optionalType : TypeSyntax ? {
55
+ type
56
+ }
57
+ }
58
+
21
59
extension ASTGenVisitor {
22
60
func visit( _ node: FunctionParameterSyntax ) -> ASTNode {
61
+ self . makeParamDecl ( node)
62
+ }
63
+
64
+ func visit( _ node: EnumCaseParameterSyntax ) -> ASTNode {
65
+ self . makeParamDecl ( node)
66
+ }
67
+
68
+ private func makeParamDecl( _ node: some ValueParameterSyntax ) -> ASTNode {
23
69
// FIXME: This location should be derived from the type repr.
24
70
let specifierLoc : BridgedSourceLoc = nil
25
71
26
72
let firstName : BridgedIdentifier
27
- if node. firstName. tokenKind != . wildcard {
28
- // Swift AST represents "_" as nil.
29
- firstName = node. firstName. bridgedIdentifier ( in: self )
30
- } else {
73
+ if node. optionalFirstName? . tokenKind == . wildcard {
74
+ // Swift AST represents "_" as a null identifier.
31
75
firstName = nil
76
+ } else {
77
+ firstName = node. optionalFirstName. bridgedIdentifier ( in: self )
32
78
}
79
+
33
80
let ( secondName, secondNameLoc) = node. secondName. bridgedIdentifierAndSourceLoc ( in: self )
34
81
35
82
return . decl(
@@ -38,10 +85,10 @@ extension ASTGenVisitor {
38
85
self . declContext,
39
86
specifierLoc,
40
87
firstName,
41
- self . bridgedSourceLoc ( for: node. firstName ) ,
88
+ self . bridgedSourceLoc ( for: node. optionalFirstName ) ,
42
89
secondName,
43
90
secondNameLoc,
44
- self . visit ( node. type ) . rawValue,
91
+ self . visit ( node. optionalType ) ? . rawValue,
45
92
self . visit ( node. defaultValue? . value) ? . rawValue
46
93
)
47
94
)
@@ -62,6 +109,19 @@ extension ASTGenVisitor {
62
109
)
63
110
}
64
111
112
+ func visit( _ node: EnumCaseParameterClauseSyntax ) -> ASTNode {
113
+ . misc(
114
+ ParameterList_create (
115
+ self . ctx,
116
+ self . bridgedSourceLoc ( for: node. leftParen) ,
117
+ node. parameters. lazy. map { self . visit ( $0) . rawValue } . bridgedArray ( in: self ) ,
118
+ self . bridgedSourceLoc ( for: node. rightParen)
119
+ )
120
+ )
121
+ }
122
+ }
123
+
124
+ extension ASTGenVisitor {
65
125
@inline ( __always)
66
126
func visit( _ node: FunctionParameterListSyntax ) -> BridgedArrayRef {
67
127
node. lazy. map { self . visit ( $0) . rawValue } . bridgedArray ( in: self )
0 commit comments