Skip to content

Commit d95d7e5

Browse files
committed
[ASTGen] Generate ConditionElement using switch
Generating ConditionElement using generate(_:) wouldn't work when we implemnt other condition kinds e.g. patterns because they are not ASTNode kinds. Remove generate(choices:) and generate(_:) as they weren't used anymore.
1 parent 1d558eb commit d95d7e5

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

lib/ASTGen/Sources/ASTGen/ASTGen.swift

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class Boxed<Value> {
8484
}
8585

8686
struct 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.
211177
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-
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 {

lib/ASTGen/Sources/ASTGen/Stmts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension ASTGenVisitor {
6666
func makeIfStmt(_ node: IfExprSyntax) -> BridgedIfStmt {
6767
// FIXME: handle multiple coniditons.
6868
// FIXME: handle non-expression conditions.
69-
let conditions = node.conditions.map(self.generate)
69+
let conditions = node.conditions.map(self.generate(conditionElement:))
7070
assert(conditions.count == 1)
7171

7272
return .createParsed(

0 commit comments

Comments
 (0)