commit
499df9680c
|
@ -2625,6 +2625,9 @@ fn transSwitch(
|
||||||
const else_prong = try transCreateNodeSwitchCase(rp.c, try transCreateNodeSwitchElse(rp.c));
|
const else_prong = try transCreateNodeSwitchCase(rp.c, try transCreateNodeSwitchElse(rp.c));
|
||||||
else_prong.expr = &(try transCreateNodeBreak(rp.c, "__switch")).base;
|
else_prong.expr = &(try transCreateNodeBreak(rp.c, "__switch")).base;
|
||||||
_ = try appendToken(rp.c, .Comma, ",");
|
_ = try appendToken(rp.c, .Comma, ",");
|
||||||
|
|
||||||
|
if (switch_scope.case_index >= switch_scope.cases.len)
|
||||||
|
return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{});
|
||||||
switch_scope.cases[switch_scope.case_index] = &else_prong.base;
|
switch_scope.cases[switch_scope.case_index] = &else_prong.base;
|
||||||
switch_scope.case_index += 1;
|
switch_scope.case_index += 1;
|
||||||
}
|
}
|
||||||
|
@ -2666,6 +2669,9 @@ fn transCase(
|
||||||
const switch_prong = try transCreateNodeSwitchCase(rp.c, expr);
|
const switch_prong = try transCreateNodeSwitchCase(rp.c, expr);
|
||||||
switch_prong.expr = &(try transCreateNodeBreak(rp.c, label)).base;
|
switch_prong.expr = &(try transCreateNodeBreak(rp.c, label)).base;
|
||||||
_ = try appendToken(rp.c, .Comma, ",");
|
_ = try appendToken(rp.c, .Comma, ",");
|
||||||
|
|
||||||
|
if (switch_scope.case_index >= switch_scope.cases.len)
|
||||||
|
return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{});
|
||||||
switch_scope.cases[switch_scope.case_index] = &switch_prong.base;
|
switch_scope.cases[switch_scope.case_index] = &switch_prong.base;
|
||||||
switch_scope.case_index += 1;
|
switch_scope.case_index += 1;
|
||||||
|
|
||||||
|
@ -2699,6 +2705,9 @@ fn transDefault(
|
||||||
const else_prong = try transCreateNodeSwitchCase(rp.c, try transCreateNodeSwitchElse(rp.c));
|
const else_prong = try transCreateNodeSwitchCase(rp.c, try transCreateNodeSwitchElse(rp.c));
|
||||||
else_prong.expr = &(try transCreateNodeBreak(rp.c, label)).base;
|
else_prong.expr = &(try transCreateNodeBreak(rp.c, label)).base;
|
||||||
_ = try appendToken(rp.c, .Comma, ",");
|
_ = try appendToken(rp.c, .Comma, ",");
|
||||||
|
|
||||||
|
if (switch_scope.case_index >= switch_scope.cases.len)
|
||||||
|
return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{});
|
||||||
switch_scope.cases[switch_scope.case_index] = &else_prong.base;
|
switch_scope.cases[switch_scope.case_index] = &else_prong.base;
|
||||||
switch_scope.case_index += 1;
|
switch_scope.case_index += 1;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,21 @@ const std = @import("std");
|
||||||
const CrossTarget = std.zig.CrossTarget;
|
const CrossTarget = std.zig.CrossTarget;
|
||||||
|
|
||||||
pub fn addCases(cases: *tests.TranslateCContext) void {
|
pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||||
|
cases.add("complex switch",
|
||||||
|
\\int main() {
|
||||||
|
\\ int i = 2;
|
||||||
|
\\ switch (i) {
|
||||||
|
\\ case 0: {
|
||||||
|
\\ case 2:{
|
||||||
|
\\ i += 2;}
|
||||||
|
\\ i += 1;
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
, &[_][]const u8{ // TODO properly translate this
|
||||||
|
\\pub const main = @compileError("unable to translate function");
|
||||||
|
});
|
||||||
|
|
||||||
cases.add("correct semicolon after infixop",
|
cases.add("correct semicolon after infixop",
|
||||||
\\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
|
\\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
|
||||||
, &[_][]const u8{
|
, &[_][]const u8{
|
||||||
|
|
Loading…
Reference in New Issue