update tests

master
Vexu 2019-12-12 16:56:21 +02:00
parent ef361161e2
commit 3bca025091
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 112 additions and 151 deletions

View File

@ -322,7 +322,8 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void {
var var_node = try transCreateNodeVarDecl(c, true, is_extern, is_const, var_name); var var_node = try transCreateNodeVarDecl(c, true, is_extern, is_const, var_name);
const type_node = transQualType(rp, qual_type, var_decl_loc) catch |err| switch (err) { _= try appendToken(rp.c, .Colon, ":");
var_node.type_node = transQualType(rp, qual_type, var_decl_loc) catch |err| switch (err) {
error.UnsupportedType => { error.UnsupportedType => {
return failDecl(c, var_decl_loc, var_name, "unable to resolve variable type", .{}); return failDecl(c, var_decl_loc, var_name, "unable to resolve variable type", .{});
}, },
@ -336,7 +337,8 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void {
return failDecl(c, var_decl_loc, var_name, "unable to evaluate initializer", .{}); return failDecl(c, var_decl_loc, var_name, "unable to evaluate initializer", .{});
break :blk transApValue(rp, ap_value, qual_type, var_decl_loc) catch |err| switch (err) { break :blk transApValue(rp, ap_value, qual_type, var_decl_loc) catch |err| switch (err) {
error.UnsupportedTranslation, error.UnsupportedTranslation,
error.UnsupportedType, => { error.UnsupportedType,
=> {
return failDecl(c, var_decl_loc, var_name, "unable to evaluate initializer", .{}); return failDecl(c, var_decl_loc, var_name, "unable to evaluate initializer", .{});
}, },
error.OutOfMemory => |e| return e, error.OutOfMemory => |e| return e,
@ -345,9 +347,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void {
try transCreateNodeUndefinedLiteral(c); try transCreateNodeUndefinedLiteral(c);
var_node.eq_token = eq_tok; var_node.eq_token = eq_tok;
var_node.init_node = init_node; var_node.init_node = init_node;
} } else if (!is_extern) {
if (!is_extern) {
return failDecl(c, var_decl_loc, var_name, "non-extern, non-static variable not supported", .{}); return failDecl(c, var_decl_loc, var_name, "non-extern, non-static variable not supported", .{});
} }

View File

@ -1604,16 +1604,6 @@ pub const TranslateCContext = struct {
self.addCase(tc); self.addCase(tc);
} }
pub fn addC(
self: *TranslateCContext,
name: []const u8,
source: []const u8,
expected_lines: []const []const u8,
) void {
const tc = self.create(false, "source.c", name, source, expected_lines);
self.addCase(tc);
}
pub fn add_both( pub fn add_both(
self: *TranslateCContext, self: *TranslateCContext,
name: []const u8, name: []const u8,
@ -1627,19 +1617,6 @@ pub const TranslateCContext = struct {
} }
} }
pub fn addC_both(
self: *TranslateCContext,
name: []const u8,
source: []const u8,
expected_lines: []const []const u8,
) void {
for ([_]bool{ false, true }) |stage2| {
const tc = self.create(false, "source.c", name, source, expected_lines);
tc.stage2 = stage2;
self.addCase(tc);
}
}
pub fn add_2( pub fn add_2(
self: *TranslateCContext, self: *TranslateCContext,
name: []const u8, name: []const u8,
@ -1651,17 +1628,6 @@ pub const TranslateCContext = struct {
self.addCase(tc); self.addCase(tc);
} }
pub fn addC_2(
self: *TranslateCContext,
name: []const u8,
source: []const u8,
expected_lines: []const []const u8,
) void {
const tc = self.create(false, "source.c", name, source, expected_lines);
tc.stage2 = true;
self.addCase(tc);
}
pub fn addAllowWarnings( pub fn addAllowWarnings(
self: *TranslateCContext, self: *TranslateCContext,
name: []const u8, name: []const u8,

View File

@ -4,11 +4,8 @@ const builtin = @import("builtin");
// add_both - test for stage1 and stage2, in #include mode // add_both - test for stage1 and stage2, in #include mode
// add - test stage1 only, in #include mode // add - test stage1 only, in #include mode
// add_2 - test stage2 only, in #include mode // add_2 - test stage2 only, in #include mode
// addC_both - test for stage1 and stage2, in -c mode
// addC - test stage1 only, in -c mode
// addC_2 - test stage2 only, in -c mode
pub fn addCases(cases: *tests.TranslateCContext) void { pub export fn addCases(cases: *tests.TranslateCContext) void {
/////////////// Cases that pass for both stage1/stage2 //////////////// /////////////// Cases that pass for both stage1/stage2 ////////////////
cases.add_both("simple function prototypes", cases.add_both("simple function prototypes",
\\void __attribute__((noreturn)) foo(void); \\void __attribute__((noreturn)) foo(void);
@ -26,7 +23,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ const unsigned d = 440; \\ const unsigned d = 440;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ var a: c_int = undefined; \\ var a: c_int = undefined;
\\ var b: u8 = @as(u8, 123); \\ var b: u8 = @as(u8, 123);
\\ const c: c_int = undefined; \\ const c: c_int = undefined;
@ -44,7 +41,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ a = 1; \\ a = 1;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ var a: c_int = undefined; \\ var a: c_int = undefined;
\\ _ = 1; \\ _ = 1;
\\ _ = "hey"; \\ _ = "hey";
@ -54,29 +51,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.add_both("variables",
\\extern int extern_var;
\\static const int int_var = 13;
, &[_][]const u8{
\\pub extern var extern_var: c_int;
,
\\pub const int_var: c_int = 13;
});
cases.add_both("const ptr initializer",
\\static const char *v0 = "0.0.0";
, &[_][]const u8{
\\pub var v0: [*c]const u8 = "0.0.0";
});
/////////////// Cases that pass for only stage2 //////////////// /////////////// Cases that pass for only stage2 ////////////////
// TODO: restore these tests after removing "import mode" concept
// https://github.com/ziglang/zig/issues/2780
// cases.add_2("Parameterless function prototypes", cases.add_2("Parameterless function prototypes",
// \\void a() {} \\void a() {}
// \\void b(void) {} \\void b(void) {}
// \\void c(); \\void c();
// \\void d(void); \\void d(void);
// , , &[_][]const u8{
// \\pub export fn a() void {} \\pub export fn a() void {}
// \\pub export fn b() void {} \\pub export fn b() void {}
// \\pub extern fn c(...) void; \\pub extern fn c(...) void;
// \\pub extern fn d() void; \\pub extern fn d() void;
// ); });
// cases.add_2("simple function definition", cases.add_2("simple function definition",
// \\void foo(void) {} \\void foo(void) {}
// \\static void bar(void) {} \\static void bar(void) {}
// , , &[_][]const u8{
// \\pub export fn foo() void {} \\pub export fn foo() void {}
// \\pub extern fn bar() void {} \\pub fn bar() void {}
// ); });
cases.add_2("parameterless function prototypes", cases.add_2("parameterless function prototypes",
\\void a() {} \\void a() {}
@ -84,8 +94,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\void c(); \\void c();
\\void d(void); \\void d(void);
, &[_][]const u8{ , &[_][]const u8{
\\pub fn a(...) void {} \\pub export fn a() void {}
\\pub fn b() void {} \\pub export fn b() void {}
\\pub extern fn c(...) void; \\pub extern fn c(...) void;
\\pub extern fn d() void; \\pub extern fn d() void;
}); });
@ -124,7 +134,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\void foo(void) {} \\void foo(void) {}
\\static void bar(void) {} \\static void bar(void) {}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void {} \\pub export fn foo() void {}
\\pub fn bar() void {} \\pub fn bar() void {}
}); });
@ -142,7 +152,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub extern fn foo() void; \\pub extern fn foo() void;
\\pub fn bar() void { \\pub export fn bar() void {
\\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
\\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr))); \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr)));
\\} \\}
@ -212,7 +222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ __PRETTY_FUNCTION__; \\ __PRETTY_FUNCTION__;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ _ = "foo"; \\ _ = "foo";
\\ _ = "foo"; \\ _ = "foo";
\\ _ = "void foo(void)"; \\ _ = "void foo(void)";
@ -229,7 +239,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ a = 1; \\ a = 1;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ var a: c_int = undefined; \\ var a: c_int = undefined;
\\ _ = 1; \\ _ = 1;
\\ _ = "hey"; \\ _ = "hey";
@ -244,7 +254,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ for (int x = 0; x < 10; x++); \\ for (int x = 0; x < 10; x++);
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ { \\ {
\\ var x: c_int = 0; \\ var x: c_int = 0;
\\ while (x < 10) : (x += 1) {} \\ while (x < 10) : (x += 1) {}
@ -257,7 +267,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ do ; while (1); \\ do ; while (1);
\\} \\}
, &[_][]const u8{ // TODO this should be if (1 != 0) break , &[_][]const u8{ // TODO this should be if (1 != 0) break
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (true) { \\ while (true) {
\\ {} \\ {}
\\ if (!1) break; \\ if (!1) break;
@ -270,7 +280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ for (;;); \\ for (;;);
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (true) {} \\ while (true) {}
\\} \\}
}); });
@ -280,7 +290,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ while (1); \\ while (1);
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (1 != 0) {} \\ while (1 != 0) {}
\\} \\}
}); });
@ -326,7 +336,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern fn foo() noreturn; \\pub extern fn foo() noreturn;
}); });
cases.addC("simple function", cases.add("simple function",
\\int abs(int a) { \\int abs(int a) {
\\ return a < 0 ? -a : a; \\ return a < 0 ? -a : a;
\\} \\}
@ -482,15 +492,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const THING2 = THING1; \\pub const THING2 = THING1;
}); });
cases.add("variables",
\\extern int extern_var;
\\static const int int_var = 13;
, &[_][]const u8{
\\pub extern var extern_var: c_int;
,
\\pub const int_var: c_int = 13;
});
cases.add("circular struct definitions", cases.add("circular struct definitions",
\\struct Bar; \\struct Bar;
\\ \\
@ -642,7 +643,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const LUA_GLOBALSINDEX = -10002; \\pub const LUA_GLOBALSINDEX = -10002;
}); });
cases.addC("post increment", cases.add("post increment",
\\unsigned foo1(unsigned a) { \\unsigned foo1(unsigned a) {
\\ a++; \\ a++;
\\ return a; \\ return a;
@ -664,7 +665,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("shift right assign", cases.add("shift right assign",
\\int log2(unsigned a) { \\int log2(unsigned a) {
\\ int i = 0; \\ int i = 0;
\\ while (a > 0) { \\ while (a > 0) {
@ -683,7 +684,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("if statement", cases.add("if statement",
\\int max(int a, int b) { \\int max(int a, int b) {
\\ if (a < b) \\ if (a < b)
\\ return b; \\ return b;
@ -703,7 +704,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("==, !=", cases.add("==, !=",
\\int max(int a, int b) { \\int max(int a, int b) {
\\ if (a == b) \\ if (a == b)
\\ return a; \\ return a;
@ -719,7 +720,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC_both("add, sub, mul, div, rem", cases.add_both("add, sub, mul, div, rem",
\\int s(int a, int b) { \\int s(int a, int b) {
\\ int c; \\ int c;
\\ c = a + b; \\ c = a + b;
@ -755,7 +756,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("bitwise binary operators", cases.add("bitwise binary operators",
\\int max(int a, int b) { \\int max(int a, int b) {
\\ return (a & b) ^ (a | b); \\ return (a & b) ^ (a | b);
\\} \\}
@ -765,7 +766,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("logical and, logical or", cases.add("logical and, logical or",
\\int max(int a, int b) { \\int max(int a, int b) {
\\ if (a < b || a == b) \\ if (a < b || a == b)
\\ return b; \\ return b;
@ -781,7 +782,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("logical and, logical or on none bool values", cases.add("logical and, logical or on none bool values",
\\int and_or_none_bool(int a, float b, void *c) { \\int and_or_none_bool(int a, float b, void *c) {
\\ if (a && b) return 0; \\ if (a && b) return 0;
\\ if (b && c) return 1; \\ if (b && c) return 1;
@ -803,7 +804,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("assign", cases.add("assign",
\\int max(int a) { \\int max(int a) {
\\ int tmp; \\ int tmp;
\\ tmp = a; \\ tmp = a;
@ -818,7 +819,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("chaining assign", cases.add("chaining assign",
\\void max(int a) { \\void max(int a) {
\\ int b, c; \\ int b, c;
\\ c = b = a; \\ c = b = a;
@ -835,7 +836,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("shift right assign with a fixed size type", cases.add("shift right assign with a fixed size type",
\\#include <stdint.h> \\#include <stdint.h>
\\int log2(uint32_t a) { \\int log2(uint32_t a) {
\\ int i = 0; \\ int i = 0;
@ -865,7 +866,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const Two = 1; \\pub const Two = 1;
}); });
cases.addC("function call", cases.add("function call",
\\static void bar(void) { } \\static void bar(void) { }
\\static int baz(void) { return 0; } \\static int baz(void) { return 0; }
\\void foo(void) { \\void foo(void) {
@ -883,7 +884,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("field access expression", cases.add("field access expression",
\\struct Foo { \\struct Foo {
\\ int field; \\ int field;
\\}; \\};
@ -899,7 +900,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("null statements", cases.add("null statements",
\\void foo(void) { \\void foo(void) {
\\ ;;;;; \\ ;;;;;
\\} \\}
@ -919,7 +920,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub var array: [100]c_int = undefined; \\pub var array: [100]c_int = undefined;
}); });
cases.addC("array access", cases.add("array access",
\\int array[100]; \\int array[100];
\\int foo(int index) { \\int foo(int index) {
\\ return array[index]; \\ return array[index];
@ -931,7 +932,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("c style cast", cases.add("c style cast",
\\int float_to_int(float a) { \\int float_to_int(float a) {
\\ return (int)a; \\ return (int)a;
\\} \\}
@ -941,7 +942,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("void cast", cases.add("void cast",
\\void foo(int a) { \\void foo(int a) {
\\ (void) a; \\ (void) a;
\\} \\}
@ -951,7 +952,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("implicit cast to void *", cases.add("implicit cast to void *",
\\void *foo(unsigned short *x) { \\void *foo(unsigned short *x) {
\\ return x; \\ return x;
\\} \\}
@ -961,7 +962,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("sizeof", cases.add("sizeof",
\\#include <stddef.h> \\#include <stddef.h>
\\size_t size_of(void) { \\size_t size_of(void) {
\\ return sizeof(int); \\ return sizeof(int);
@ -972,7 +973,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("null pointer implicit cast", cases.add("null pointer implicit cast",
\\int* foo(void) { \\int* foo(void) {
\\ return 0; \\ return 0;
\\} \\}
@ -982,7 +983,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("comma operator", cases.add("comma operator",
\\int foo(void) { \\int foo(void) {
\\ return 1, 2; \\ return 1, 2;
\\} \\}
@ -995,7 +996,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("statement expression", cases.add("statement expression",
\\int foo(void) { \\int foo(void) {
\\ return ({ \\ return ({
\\ int a = 1; \\ int a = 1;
@ -1011,7 +1012,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("__extension__ cast", cases.add("__extension__ cast",
\\int foo(void) { \\int foo(void) {
\\ return __extension__ 1; \\ return __extension__ 1;
\\} \\}
@ -1021,7 +1022,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("bitshift", cases.add("bitshift",
\\int foo(void) { \\int foo(void) {
\\ return (1 << 2) >> 1; \\ return (1 << 2) >> 1;
\\} \\}
@ -1031,7 +1032,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("compound assignment operators", cases.add("compound assignment operators",
\\void foo(void) { \\void foo(void) {
\\ int a = 0; \\ int a = 0;
\\ a += (a += 1); \\ a += (a += 1);
@ -1089,7 +1090,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("compound assignment operators unsigned", cases.add("compound assignment operators unsigned",
\\void foo(void) { \\void foo(void) {
\\ unsigned a = 0; \\ unsigned a = 0;
\\ a += (a += 1); \\ a += (a += 1);
@ -1147,7 +1148,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("duplicate typedef", cases.add("duplicate typedef",
\\typedef long foo; \\typedef long foo;
\\typedef int bar; \\typedef int bar;
\\typedef long foo; \\typedef long foo;
@ -1158,7 +1159,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub const baz = c_int; \\pub const baz = c_int;
}); });
cases.addC("post increment/decrement", cases.add("post increment/decrement",
\\void foo(void) { \\void foo(void) {
\\ int i = 0; \\ int i = 0;
\\ unsigned u = 0; \\ unsigned u = 0;
@ -1206,7 +1207,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("pre increment/decrement", cases.add("pre increment/decrement",
\\void foo(void) { \\void foo(void) {
\\ int i = 0; \\ int i = 0;
\\ unsigned u = 0; \\ unsigned u = 0;
@ -1250,7 +1251,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("do loop", cases.add("do loop",
\\void foo(void) { \\void foo(void) {
\\ int a = 2; \\ int a = 2;
\\ do { \\ do {
@ -1277,7 +1278,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("deref function pointer", cases.add("deref function pointer",
\\void foo(void) {} \\void foo(void) {}
\\int baz(void) { return 0; } \\int baz(void) { return 0; }
\\void bar(void) { \\void bar(void) {
@ -1307,7 +1308,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("normal deref", cases.add("normal deref",
\\void foo(int *x) { \\void foo(int *x) {
\\ *x = 1; \\ *x = 1;
\\} \\}
@ -1338,7 +1339,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return *ptr; \\ return *ptr;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() c_int { \\pub export fn foo() c_int {
\\ var x: c_int = 1234; \\ var x: c_int = 1234;
\\ var ptr: [*c]c_int = &x; \\ var ptr: [*c]c_int = &x;
\\ return ptr.?.*; \\ return ptr.?.*;
@ -1350,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return "bar"; \\ return "bar";
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() [*c]const u8 { \\pub export fn foo() [*c]const u8 {
\\ return "bar"; \\ return "bar";
\\} \\}
}); });
@ -1360,7 +1361,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return; \\ return;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ return; \\ return;
\\} \\}
}); });
@ -1370,7 +1371,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ for (int i = 0; i < 10; i += 1) { } \\ for (int i = 0; i < 10; i += 1) { }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ { \\ {
\\ var i: c_int = 0; \\ var i: c_int = 0;
\\ while (i < 10) : (i += 1) {} \\ while (i < 10) : (i += 1) {}
@ -1383,7 +1384,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ for (;;) { } \\ for (;;) { }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (true) {} \\ while (true) {}
\\} \\}
}); });
@ -1395,7 +1396,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ } \\ }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (true) { \\ while (true) {
\\ break; \\ break;
\\ } \\ }
@ -1409,7 +1410,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ } \\ }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ while (true) { \\ while (true) {
\\ continue; \\ continue;
\\ } \\ }
@ -1464,7 +1465,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return x; \\ return x;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() c_int { \\pub export fn foo() c_int {
\\ var x: c_int = 1; \\ var x: c_int = 1;
\\ { \\ {
\\ var x_0: c_int = 2; \\ var x_0: c_int = 2;
@ -1489,7 +1490,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return ~x; \\ return ~x;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo(x: c_int) c_int { \\pub export fn foo(x: c_int) c_int {
\\ return ~x; \\ return ~x;
\\} \\}
}); });
@ -1502,7 +1503,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return !c; \\ return !c;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int { \\pub export fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
\\ return !(a == 0); \\ return !(a == 0);
\\ return !(a != 0); \\ return !(a != 0);
\\ return !(b != 0); \\ return !(b != 0);
@ -1515,23 +1516,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return u32; \\ return u32;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo(u32_0: c_int) c_int { \\pub export fn foo(u32_0: c_int) c_int {
\\ return u32_0; \\ return u32_0;
\\} \\}
}); });
cases.add("const ptr initializer",
\\static const char *v0 = "0.0.0";
, &[_][]const u8{
\\pub var v0: [*c]const u8 = "0.0.0";
});
cases.add("static incomplete array inside function", cases.add("static incomplete array inside function",
\\void foo(void) { \\void foo(void) {
\\ static const char v2[] = "2.2.2"; \\ static const char v2[] = "2.2.2";
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn foo() void { \\pub export fn foo() void {
\\ const v2: [*c]const u8 = "2.2.2"; \\ const v2: [*c]const u8 = "2.2.2";
\\} \\}
}); });
@ -1560,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ B, \\ B,
\\ C, \\ C,
\\}; \\};
\\pub fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int { \\pub export fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int {
\\ if (a != 0) return 0; \\ if (a != 0) return 0;
\\ if (b != 0) return 1; \\ if (b != 0) return 1;
\\ if (c != null) return 2; \\ if (c != null) return 2;
@ -1577,7 +1572,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return 3; \\ return 3;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { \\pub export fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
\\ while (a != 0) return 0; \\ while (a != 0) return 0;
\\ while (b != 0) return 1; \\ while (b != 0) return 1;
\\ while (c != null) return 2; \\ while (c != null) return 2;
@ -1593,7 +1588,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return 3; \\ return 3;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { \\pub export fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
\\ while (a != 0) return 0; \\ while (a != 0) return 0;
\\ while (b != 0) return 1; \\ while (b != 0) return 1;
\\ while (c != null) return 2; \\ while (c != null) return 2;
@ -1617,7 +1612,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ } \\ }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
\\pub fn switch_fn(i: c_int) c_int { \\pub export fn switch_fn(i: c_int) c_int {
\\ var res: c_int = 0; \\ var res: c_int = 0;
\\ __switch: { \\ __switch: {
\\ __case_2: { \\ __case_2: {
@ -1643,7 +1638,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC( cases.add(
"u integer suffix after 0 (zero) in macro definition", "u integer suffix after 0 (zero) in macro definition",
"#define ZERO 0U", "#define ZERO 0U",
&[_][]const u8{ &[_][]const u8{
@ -1651,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"l integer suffix after 0 (zero) in macro definition", "l integer suffix after 0 (zero) in macro definition",
"#define ZERO 0L", "#define ZERO 0L",
&[_][]const u8{ &[_][]const u8{
@ -1659,7 +1654,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"ul integer suffix after 0 (zero) in macro definition", "ul integer suffix after 0 (zero) in macro definition",
"#define ZERO 0UL", "#define ZERO 0UL",
&[_][]const u8{ &[_][]const u8{
@ -1667,7 +1662,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"lu integer suffix after 0 (zero) in macro definition", "lu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LU", "#define ZERO 0LU",
&[_][]const u8{ &[_][]const u8{
@ -1675,7 +1670,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"ll integer suffix after 0 (zero) in macro definition", "ll integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LL", "#define ZERO 0LL",
&[_][]const u8{ &[_][]const u8{
@ -1683,7 +1678,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"ull integer suffix after 0 (zero) in macro definition", "ull integer suffix after 0 (zero) in macro definition",
"#define ZERO 0ULL", "#define ZERO 0ULL",
&[_][]const u8{ &[_][]const u8{
@ -1691,7 +1686,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"llu integer suffix after 0 (zero) in macro definition", "llu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LLU", "#define ZERO 0LLU",
&[_][]const u8{ &[_][]const u8{
@ -1699,7 +1694,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC( cases.add(
"bitwise not on u-suffixed 0 (zero) in macro definition", "bitwise not on u-suffixed 0 (zero) in macro definition",
"#define NOT_ZERO (~0U)", "#define NOT_ZERO (~0U)",
&[_][]const u8{ &[_][]const u8{
@ -1707,7 +1702,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
}, },
); );
cases.addC("implicit casts", cases.add("implicit casts",
\\#include <stdbool.h> \\#include <stdbool.h>
\\ \\
\\void fn_int(int x); \\void fn_int(int x);
@ -1762,7 +1757,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("pointer conversion with different alignment", cases.add("pointer conversion with different alignment",
\\void test_ptr_cast() { \\void test_ptr_cast() {
\\ void *p; \\ void *p;
\\ { \\ {
@ -1796,7 +1791,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\} \\}
}); });
cases.addC("escape sequences", cases.add("escape sequences",
\\const char *escapes() { \\const char *escapes() {
\\char a = '\'', \\char a = '\'',
\\ b = '\\', \\ b = '\\',
@ -1840,7 +1835,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
} }
/////////////// Cases for only stage1 because stage2 behavior is better //////////////// /////////////// Cases for only stage1 because stage2 behavior is better ////////////////
cases.addC("Parameterless function prototypes", cases.add("Parameterless function prototypes",
\\void foo() {} \\void foo() {}
\\void bar(void) {} \\void bar(void) {}
, &[_][]const u8{ , &[_][]const u8{