parent
51e430fac0
commit
a712ea333b
@ -2119,14 +2119,16 @@ fn transForLoop(
|
||||
.parent = scope,
|
||||
.id = .Loop,
|
||||
};
|
||||
var block = false;
|
||||
|
||||
var block_scope: ?*Scope.Block = null;
|
||||
if (ZigClangForStmt_getInit(stmt)) |init| {
|
||||
block_scope = try Scope.Block.init(rp.c, scope, null);
|
||||
block_scope.?.block_node = try transCreateNodeBlock(rp.c, null);
|
||||
const block = try transCreateNodeBlock(rp.c, null);
|
||||
block_scope.?.block_node = block;
|
||||
loop_scope.parent = &block_scope.?.base;
|
||||
const init_stmt = try transStmt(rp, &loop_scope, init, .unused, .r_value);
|
||||
try block_scope.?.block_node.statements.push(init_stmt);
|
||||
const result = try transStmt(rp, &block_scope.?.base, init, .unused, .r_value);
|
||||
if (result != &block.base)
|
||||
try block.statements.push(result);
|
||||
}
|
||||
var cond_scope = Scope{
|
||||
.parent = scope,
|
||||
|
@ -696,6 +696,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\}
|
||||
});
|
||||
|
||||
cases.add("for loop with simple init expression",
|
||||
\\void foo(void) {
|
||||
\\ int i;
|
||||
\\ for (i = 3; i; i--) { }
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
\\pub export fn foo() void {
|
||||
\\ var i: c_int = undefined;
|
||||
\\ {
|
||||
\\ i = 3;
|
||||
\\ while (i != 0) : (i -= 1) {}
|
||||
\\ }
|
||||
\\}
|
||||
});
|
||||
|
||||
cases.add("break statement",
|
||||
\\void foo(void) {
|
||||
\\ for (;;) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user