@@ -84,8 +84,6 @@ class Boxed<Value> {
84
84
}
85
85
86
86
struct ASTGenVisitor {
87
- typealias ResultType = ASTNode
88
-
89
87
fileprivate let diagnosticEngine : BridgedDiagnosticEngine
90
88
91
89
let base : UnsafeBufferPointer < UInt8 >
@@ -174,47 +172,9 @@ extension ASTGenVisitor {
174
172
}
175
173
}
176
174
177
- extension ASTGenVisitor {
178
- /// Generate ASTNode from a Syntax node. The node must be a decl, stmt, expr, or
179
- /// type.
180
- func generate( _ node: Syntax ) -> ASTNode {
181
- if let decl = node. as ( DeclSyntax . self) {
182
- return . decl( self . generate ( decl: decl) )
183
- }
184
- if let stmt = node. as ( StmtSyntax . self) {
185
- return . stmt( self . generate ( stmt: stmt) )
186
- }
187
- if let expr = node. as ( ExprSyntax . self) {
188
- return . expr( self . generate ( expr: expr) )
189
- }
190
- if let type = node. as ( TypeSyntax . self) {
191
- return . type( self . generate ( type: type) )
192
- }
193
-
194
- // --- Special cases where `node` doesn't belong to one of the base kinds.
195
-
196
- // CodeBlockSyntax -> BraceStmt.
197
- if let node = node. as ( CodeBlockSyntax . self) {
198
- return . stmt( self . generate ( codeBlock: node) . asStmt)
199
- }
200
- // CodeBlockItemSyntax -> ASTNode.
201
- if let node = node. as ( CodeBlockItemSyntax . self) {
202
- return self . generate ( codeBlockItem: node)
203
- }
204
-
205
- fatalError ( " node does not correspond to an ASTNode \( node. kind) " )
206
- }
207
- }
208
-
209
175
// Misc visits.
210
176
// TODO: Some of these are called within a single file/method; we may want to move them to the respective files.
211
177
extension ASTGenVisitor {
212
-
213
- /// Do NOT introduce another usage of this. Not all choices can produce 'ASTNode'.
214
- func generate( choices node: some SyntaxChildChoices ) -> ASTNode {
215
- return self . generate ( Syntax ( node) )
216
- }
217
-
218
178
public func generate( memberBlockItem node: MemberBlockItemSyntax ) -> BridgedDecl {
219
179
generate ( decl: node. decl)
220
180
}
@@ -224,7 +184,18 @@ extension ASTGenVisitor {
224
184
}
225
185
226
186
public func generate( conditionElement node: ConditionElementSyntax ) -> ASTNode {
227
- generate ( choices: node. condition)
187
+ // FIXME: returning ASTNode is wrong, non-expression conditions are not ASTNode.
188
+ switch node. condition {
189
+ case . availability( _) :
190
+ break
191
+ case . expression( let node) :
192
+ return . expr( self . generate ( expr: node) )
193
+ case . matchingPattern( _) :
194
+ break
195
+ case . optionalBinding( _) :
196
+ break
197
+ }
198
+ fatalError ( " unimplemented " )
228
199
}
229
200
230
201
public func generate( codeBlockItem node: CodeBlockItemSyntax ) -> ASTNode {
0 commit comments