translate-c: fix regression in switch statement
parent
f67b8c68a0
commit
88f5e3a60d
|
@ -2554,9 +2554,8 @@ fn transForLoop(
|
||||||
|
|
||||||
fn getSwitchCaseCount(stmt: *const ZigClangSwitchStmt) usize {
|
fn getSwitchCaseCount(stmt: *const ZigClangSwitchStmt) usize {
|
||||||
const body = ZigClangSwitchStmt_getBody(stmt);
|
const body = ZigClangSwitchStmt_getBody(stmt);
|
||||||
assert(ZigClangStmt_getStmtClass(body) == .StmtExprClass);
|
assert(ZigClangStmt_getStmtClass(body) == .CompoundStmtClass);
|
||||||
const stmt_expr = @ptrCast(*const ZigClangStmtExpr, body);
|
const comp = @ptrCast(*const ZigClangCompoundStmt, body);
|
||||||
const comp = ZigClangStmtExpr_getSubStmt(stmt_expr);
|
|
||||||
// TODO https://github.com/ziglang/zig/issues/1738
|
// TODO https://github.com/ziglang/zig/issues/1738
|
||||||
// return ZigClangCompoundStmt_body_end(comp) - ZigClangCompoundStmt_body_begin(comp);
|
// return ZigClangCompoundStmt_body_end(comp) - ZigClangCompoundStmt_body_begin(comp);
|
||||||
const start_addr = @ptrToInt(ZigClangCompoundStmt_body_begin(comp));
|
const start_addr = @ptrToInt(ZigClangCompoundStmt_body_begin(comp));
|
||||||
|
@ -2614,19 +2613,17 @@ fn transSwitch(
|
||||||
switch_scope.pending_block = try Scope.Block.init(rp.c, scope, null);
|
switch_scope.pending_block = try Scope.Block.init(rp.c, scope, null);
|
||||||
try switch_scope.pending_block.statements.append(&switch_node.base);
|
try switch_scope.pending_block.statements.append(&switch_node.base);
|
||||||
|
|
||||||
_ = try transStmt(rp, &block_scope.base, ZigClangSwitchStmt_getBody(stmt), .unused, .r_value);
|
const last = try transStmt(rp, &block_scope.base, ZigClangSwitchStmt_getBody(stmt), .unused, .r_value);
|
||||||
_ = try appendToken(rp.c, .Semicolon, ";");
|
_ = try appendToken(rp.c, .Semicolon, ";");
|
||||||
|
|
||||||
// take all pending statements
|
// take all pending statements
|
||||||
try switch_scope.pending_block.statements.appendSlice(block_scope.statements.items);
|
const last_block_stmts = last.cast(ast.Node.Block).?.statements();
|
||||||
// TODO delete the following commented out code
|
try switch_scope.pending_block.statements.ensureCapacity(
|
||||||
//const last_block_stmts = last.cast(ast.Node.Block).?.statements();
|
switch_scope.pending_block.statements.items.len + last_block_stmts.len,
|
||||||
//switch_scope.pending_block.statements.ensureCapacity(
|
);
|
||||||
// switch_scope.pending_block.statements.items.len + last_block_stmts.len,
|
for (last_block_stmts) |n| {
|
||||||
//);
|
switch_scope.pending_block.statements.appendAssumeCapacity(n);
|
||||||
//for (last_block_stmts) |n| {
|
}
|
||||||
// switch_scope.pending_block.statements.appendAssumeCapacity(n);
|
|
||||||
//}
|
|
||||||
|
|
||||||
switch_scope.pending_block.label = try appendIdentifier(rp.c, "__switch");
|
switch_scope.pending_block.label = try appendIdentifier(rp.c, "__switch");
|
||||||
_ = try appendToken(rp.c, .Colon, ":");
|
_ = try appendToken(rp.c, .Colon, ":");
|
||||||
|
|
Loading…
Reference in New Issue