authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-29 17:09:31+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-29 17:09:31+02:00
log621629e20d7114d09761b49d8fb2bba203aadd1a
tree4fb02a16d8d16ce54aad4593d23ba515e02a9442
parentf5e7d2d00c0bfdbdf95c57b8b5528f945fcf00c2
signature Commit is signed but in an unrecognized format.

translate-c-2 fix assertion failure rendering do while


2 files changed, 17 insertions(+), 1 deletions(-)

src-self-hosted/translate_c.zig+4-1
......@@ -1792,7 +1792,10 @@ fn transDoWhileLoop(
17921792 // zig: b;
17931793 // zig: if (!cond) break;
17941794 // zig: }
1795 break :blk (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?;
1795 const body = (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?;
1796 // if this is used as an expression in Zig it needs to be immediately followed by a semicolon
1797 _ = try appendToken(rp.c, .Semicolon, ";");
1798 break :blk body;
17961799 } else blk: {
17971800 // the C statement is without a block, so we need to create a block to contain it.
17981801 // c: do
test/translate_c.zig+13
......@@ -2185,4 +2185,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21852185 , &[_][]const u8{
21862186 \\pub const FOO = if (a) b else c;
21872187 });
2188
2189 cases.add("do while as expr",
2190 \\static void foo(void) {
2191 \\ if (1)
2192 \\ do {} while (0);
2193 \\}
2194 , &[_][]const u8{
2195 \\pub fn foo() void {
2196 \\ if (1 != 0) while (true) {
2197 \\ if (!(0 != 0)) break;
2198 \\ };
2199 \\}
2200 });
21882201}