@@ -84,8 +84,6 @@ class Boxed<Value> {
8484}
8585
8686struct ASTGenVisitor {
87- typealias ResultType = ASTNode
88-
8987 fileprivate let diagnosticEngine : BridgedDiagnosticEngine
9088
9189 let base : UnsafeBufferPointer < UInt8 >
@@ -174,47 +172,9 @@ extension ASTGenVisitor {
174172 }
175173}
176174
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-
209175// Misc visits.
210176// TODO: Some of these are called within a single file/method; we may want to move them to the respective files.
211177extension 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-
218178 public func generate( memberBlockItem node: MemberBlockItemSyntax ) -> BridgedDecl {
219179 generate ( decl: node. decl)
220180 }
@@ -224,7 +184,18 @@ extension ASTGenVisitor {
224184 }
225185
226186 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 " )
228199 }
229200
230201 public func generate( codeBlockItem node: CodeBlockItemSyntax ) -> ASTNode {
0 commit comments