Collects all items for this case, returns the first statement after the labels. If items ends up empty, the prong should be translated as an else.
fn transCaseStmt(
t: *Translator,
scope: *Scope,
stmt: Node.Index,
items: *std.ArrayList(ZigNode),
) TransError!Node.Index
fn transCaseStmt(
t: *Translator,
scope: *Scope,
stmt: Node.Index,
items: *std.ArrayList(ZigNode),
) TransError!Node.Index {
var sub = stmt;
var seen_default = false;
while (true) {
switch (sub.get(t.tree)) {
.default_stmt => |default_stmt| {
seen_default = true;
items.items.len = 0;
sub = default_stmt.body;
},
.case_stmt => |case_stmt| {
if (seen_default) {
items.items.len = 0;
sub = case_stmt.body;
continue;
}
const expr = if (case_stmt.end) |end| blk: {
const start_node = try t.transExpr(scope, case_stmt.start, .used);
const end_node = try t.transExpr(scope, end, .used);
break :blk try ZigTag.ellipsis3.create(t.arena, .{ .lhs = start_node, .rhs = end_node });
} else try t.transExpr(scope, case_stmt.start, .used);
try items.append(t.gpa, expr);
sub = case_stmt.body;
},
else => return sub,
}
}
}