authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-13 18:55:34+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-13 19:06:32+02:00
log45abfa9e7189e5d87d4d49763399531973c2f899
treee0e9796f3267e802a3ab15a28a8f0886c22a97a5
parent41a67126a50e3cfab67c749bfc52ac242694774b
signature Commit is signed but in an unrecognized format.

revert removal of translate mode in stage 1


6 files changed, 119 insertions(+), 79 deletions(-)

src/codegen.cpp+6-2
......@@ -9020,6 +9020,10 @@ void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_us
90209020
90219021 init(g);
90229022
9023 TranslateMode trans_mode = buf_ends_with_str(full_path, ".h") ?
9024 TranslateModeImport : TranslateModeTranslate;
9025
9026
90239027 ZigList<const char *> clang_argv = {0};
90249028 add_cc_args(g, clang_argv, nullptr, true);
90259029
......@@ -9045,8 +9049,8 @@ void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_us
90459049 err = stage2_translate_c(&ast, &errors_ptr, &errors_len,
90469050 &clang_argv.at(0), &clang_argv.last(), resources_path);
90479051 } else {
9048 err = parse_h_file(g, &root_node, &errors_ptr, &errors_len, &clang_argv.at(0),
9049 &clang_argv.last(), resources_path);
9052 err = parse_h_file(g, &root_node, &errors_ptr, &errors_len, &clang_argv.at(0), &clang_argv.last(),
9053 trans_mode, resources_path);
90509054 }
90519055
90529056 if (err == ErrorCCompileErrors && errors_len > 0) {
src/ir.cpp+1-1
......@@ -23343,7 +23343,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2334323343 const char *resources_path = buf_ptr(ira->codegen->zig_c_headers_dir);
2334423344
2334523345 if ((err = parse_h_file(ira->codegen, &root_node, &errors_ptr, &errors_len,
23346 &clang_argv.at(0), &clang_argv.last(), resources_path)))
23346 &clang_argv.at(0), &clang_argv.last(), TranslateModeImport, resources_path)))
2334723347 {
2334823348 if (err != ErrorCCompileErrors) {
2334923349 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));
src/translate_c.cpp+8-2
......@@ -64,6 +64,7 @@ struct TransScopeWhile {
6464
6565struct Context {
6666 AstNode *root;
67 bool want_export;
6768 HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table;
6869 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table;
6970 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> global_table;
......@@ -4090,7 +4091,7 @@ static void visit_fn_decl(Context *c, const ZigClangFunctionDecl *fn_decl) {
40904091 ZigClangStorageClass sc = ZigClangFunctionDecl_getStorageClass(fn_decl);
40914092 if (sc == ZigClangStorageClass_None) {
40924093 proto_node->data.fn_proto.visib_mod = VisibModPub;
4093 proto_node->data.fn_proto.is_export = ZigClangFunctionDecl_hasBody(fn_decl);
4094 proto_node->data.fn_proto.is_export = ZigClangFunctionDecl_hasBody(fn_decl) ? c->want_export : false;
40944095 } else if (sc == ZigClangStorageClass_Extern || sc == ZigClangStorageClass_Static) {
40954096 proto_node->data.fn_proto.visib_mod = VisibModPub;
40964097 } else if (sc == ZigClangStorageClass_PrivateExtern) {
......@@ -5111,11 +5112,16 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *unit) {
51115112Error parse_h_file(CodeGen *codegen, AstNode **out_root_node,
51125113 Stage2ErrorMsg **errors_ptr, size_t *errors_len,
51135114 const char **args_begin, const char **args_end,
5114 const char *resources_path)
5115 TranslateMode mode, const char *resources_path)
51155116{
51165117 Context context = {0};
51175118 Context *c = &context;
51185119 c->warnings_on = codegen->verbose_cimport;
5120 if (mode == TranslateModeImport) {
5121 c->want_export = false;
5122 } else {
5123 c->want_export = true;
5124 }
51195125 c->decl_table.init(8);
51205126 c->macro_table.init(8);
51215127 c->global_table.init(8);
src/translate_c.hpp+6-1
......@@ -11,9 +11,14 @@
1111
1212#include "all_types.hpp"
1313
14enum TranslateMode {
15 TranslateModeImport,
16 TranslateModeTranslate,
17};
18
1419Error parse_h_file(CodeGen *codegen, AstNode **out_root_node,
1520 Stage2ErrorMsg **errors_ptr, size_t *errors_len,
1621 const char **args_begin, const char **args_end,
17 const char *resources_path);
22 TranslateMode mode, const char *resources_path);
1823
1924#endif
test/tests.zig+23
......@@ -1604,6 +1604,16 @@ pub const TranslateCContext = struct {
16041604 self.addCase(tc);
16051605 }
16061606
1607 pub fn addC(
1608 self: *TranslateCContext,
1609 name: []const u8,
1610 source: []const u8,
1611 expected_lines: []const []const u8,
1612 ) void {
1613 const tc = self.create(false, "source.c", name, source, expected_lines);
1614 self.addCase(tc);
1615 }
1616
16071617 pub fn add_both(
16081618 self: *TranslateCContext,
16091619 name: []const u8,
......@@ -1617,6 +1627,19 @@ pub const TranslateCContext = struct {
16171627 }
16181628 }
16191629
1630 pub fn addC_both(
1631 self: *TranslateCContext,
1632 name: []const u8,
1633 source: []const u8,
1634 expected_lines: []const []const u8,
1635 ) void {
1636 for ([_]bool{ false, true }) |stage2| {
1637 const tc = self.create(false, "source.c", name, source, expected_lines);
1638 tc.stage2 = stage2;
1639 self.addCase(tc);
1640 }
1641 }
1642
16201643 pub fn add_2(
16211644 self: *TranslateCContext,
16221645 name: []const u8,
test/translate_c.zig+75-73
......@@ -1,9 +1,11 @@
11const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
4// add_both - test for stage1 and stage2
5// add - test stage1 only
4// add_both - test for stage1 and stage2, in #include mode
5// add - test stage1 only, in #include mode
66// add_2 - test stage2 only
7// addC_both - test for stage1 and stage2, in -c mode
8// addC - test stage1 only, in -c mode
79
810pub fn addCases(cases: *tests.TranslateCContext) void {
911 /////////////// Cases that pass for both stage1/stage2 ////////////////
......@@ -15,7 +17,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1517 \\pub extern fn bar() c_int;
1618 });
1719
18 cases.add_both("simple var decls",
20 cases.addC_both("simple var decls",
1921 \\void foo(void) {
2022 \\ int a;
2123 \\ char b = 123;
......@@ -31,7 +33,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3133 \\}
3234 });
3335
34 cases.add_both("ignore result, explicit function arguments",
36 cases.addC_both("ignore result, explicit function arguments",
3537 \\void foo(void) {
3638 \\ int a;
3739 \\ 1;
......@@ -51,7 +53,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
5153 \\}
5254 });
5355
54 cases.add_both("variables",
56 cases.addC_both("variables",
5557 \\extern int extern_var;
5658 \\static const int int_var = 13;
5759 , &[_][]const u8{
......@@ -66,7 +68,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
6668 \\pub var v0: [*c]const u8 = "0.0.0";
6769 });
6870
69 cases.add_both("static incomplete array inside function",
71 cases.addC_both("static incomplete array inside function",
7072 \\void foo(void) {
7173 \\ static const char v2[] = "2.2.2";
7274 \\}
......@@ -76,7 +78,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
7678 \\}
7779 });
7880
79 cases.add_both("simple function definition",
81 cases.addC_both("simple function definition",
8082 \\void foo(void) {}
8183 \\static void bar(void) {}
8284 , &[_][]const u8{
......@@ -104,7 +106,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
104106 \\pub const baz = c_int;
105107 });
106108
107 cases.add_both("casting pointers to ints and ints to pointers",
109 cases.addC_both("casting pointers to ints and ints to pointers",
108110 \\void foo(void);
109111 \\void bar(void) {
110112 \\ void *func_ptr = foo;
......@@ -124,7 +126,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
124126 \\pub extern fn foo() noreturn;
125127 });
126128
127 cases.add_both("add, sub, mul, div, rem",
129 cases.addC_both("add, sub, mul, div, rem",
128130 \\int s(int a, int b) {
129131 \\ int c;
130132 \\ c = a + b;
......@@ -284,7 +286,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
284286 \\ __PRETTY_FUNCTION__;
285287 \\}
286288 , &[_][]const u8{
287 \\pub export fn foo() void {
289 \\pub fn foo() void {
288290 \\ _ = "foo";
289291 \\ _ = "foo";
290292 \\ _ = "void foo(void)";
......@@ -301,7 +303,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
301303 \\ a = 1;
302304 \\}
303305 , &[_][]const u8{
304 \\pub export fn foo() void {
306 \\pub fn foo() void {
305307 \\ var a: c_int = undefined;
306308 \\ _ = 1;
307309 \\ _ = "hey";
......@@ -316,7 +318,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
316318 \\ for (int x = 0; x < 10; x++);
317319 \\}
318320 , &[_][]const u8{
319 \\pub export fn foo() void {
321 \\pub fn foo() void {
320322 \\ {
321323 \\ var x: c_int = 0;
322324 \\ while (x < 10) : (x += 1) {}
......@@ -329,7 +331,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
329331 \\ do ; while (1);
330332 \\}
331333 , &[_][]const u8{ // TODO this should be if (1 != 0) break
332 \\pub export fn foo() void {
334 \\pub fn foo() void {
333335 \\ while (true) {
334336 \\ {}
335337 \\ if (!1) break;
......@@ -342,7 +344,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
342344 \\ for (;;);
343345 \\}
344346 , &[_][]const u8{
345 \\pub export fn foo() void {
347 \\pub fn foo() void {
346348 \\ while (true) {}
347349 \\}
348350 });
......@@ -352,7 +354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
352354 \\ while (1);
353355 \\}
354356 , &[_][]const u8{
355 \\pub export fn foo() void {
357 \\pub fn foo() void {
356358 \\ while (1 != 0) {}
357359 \\}
358360 });
......@@ -392,7 +394,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
392394 \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64) void;
393395 });
394396
395 cases.add("simple function",
397 cases.addC("simple function",
396398 \\int abs(int a) {
397399 \\ return a < 0 ? -a : a;
398400 \\}
......@@ -690,7 +692,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
690692 \\pub const LUA_GLOBALSINDEX = -10002;
691693 });
692694
693 cases.add("post increment",
695 cases.addC("post increment",
694696 \\unsigned foo1(unsigned a) {
695697 \\ a++;
696698 \\ return a;
......@@ -712,7 +714,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
712714 \\}
713715 });
714716
715 cases.add("shift right assign",
717 cases.addC("shift right assign",
716718 \\int log2(unsigned a) {
717719 \\ int i = 0;
718720 \\ while (a > 0) {
......@@ -731,7 +733,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
731733 \\}
732734 });
733735
734 cases.add("if statement",
736 cases.addC("if statement",
735737 \\int max(int a, int b) {
736738 \\ if (a < b)
737739 \\ return b;
......@@ -751,7 +753,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
751753 \\}
752754 });
753755
754 cases.add("==, !=",
756 cases.addC("==, !=",
755757 \\int max(int a, int b) {
756758 \\ if (a == b)
757759 \\ return a;
......@@ -767,7 +769,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
767769 \\}
768770 });
769771
770 cases.add("bitwise binary operators",
772 cases.addC("bitwise binary operators",
771773 \\int max(int a, int b) {
772774 \\ return (a & b) ^ (a | b);
773775 \\}
......@@ -777,7 +779,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
777779 \\}
778780 });
779781
780 cases.add("logical and, logical or",
782 cases.addC("logical and, logical or",
781783 \\int max(int a, int b) {
782784 \\ if (a < b || a == b)
783785 \\ return b;
......@@ -793,7 +795,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
793795 \\}
794796 });
795797
796 cases.add("logical and, logical or on none bool values",
798 cases.addC("logical and, logical or on none bool values",
797799 \\int and_or_none_bool(int a, float b, void *c) {
798800 \\ if (a && b) return 0;
799801 \\ if (b && c) return 1;
......@@ -815,7 +817,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
815817 \\}
816818 });
817819
818 cases.add("assign",
820 cases.addC("assign",
819821 \\int max(int a) {
820822 \\ int tmp;
821823 \\ tmp = a;
......@@ -830,7 +832,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
830832 \\}
831833 });
832834
833 cases.add("chaining assign",
835 cases.addC("chaining assign",
834836 \\void max(int a) {
835837 \\ int b, c;
836838 \\ c = b = a;
......@@ -847,7 +849,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
847849 \\}
848850 });
849851
850 cases.add("shift right assign with a fixed size type",
852 cases.addC("shift right assign with a fixed size type",
851853 \\#include <stdint.h>
852854 \\int log2(uint32_t a) {
853855 \\ int i = 0;
......@@ -877,7 +879,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
877879 \\pub const Two = 1;
878880 });
879881
880 cases.add("function call",
882 cases.addC("function call",
881883 \\static void bar(void) { }
882884 \\static int baz(void) { return 0; }
883885 \\void foo(void) {
......@@ -895,7 +897,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
895897 \\}
896898 });
897899
898 cases.add("field access expression",
900 cases.addC("field access expression",
899901 \\struct Foo {
900902 \\ int field;
901903 \\};
......@@ -911,7 +913,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
911913 \\}
912914 });
913915
914 cases.add("null statements",
916 cases.addC("null statements",
915917 \\void foo(void) {
916918 \\ ;;;;;
917919 \\}
......@@ -931,7 +933,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
931933 \\pub var array: [100]c_int = undefined;
932934 });
933935
934 cases.add("array access",
936 cases.addC("array access",
935937 \\int array[100];
936938 \\int foo(int index) {
937939 \\ return array[index];
......@@ -943,7 +945,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
943945 \\}
944946 });
945947
946 cases.add("c style cast",
948 cases.addC("c style cast",
947949 \\int float_to_int(float a) {
948950 \\ return (int)a;
949951 \\}
......@@ -953,7 +955,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
953955 \\}
954956 });
955957
956 cases.add("void cast",
958 cases.addC("void cast",
957959 \\void foo(int a) {
958960 \\ (void) a;
959961 \\}
......@@ -963,7 +965,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
963965 \\}
964966 });
965967
966 cases.add("implicit cast to void *",
968 cases.addC("implicit cast to void *",
967969 \\void *foo(unsigned short *x) {
968970 \\ return x;
969971 \\}
......@@ -973,7 +975,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
973975 \\}
974976 });
975977
976 cases.add("sizeof",
978 cases.addC("sizeof",
977979 \\#include <stddef.h>
978980 \\size_t size_of(void) {
979981 \\ return sizeof(int);
......@@ -984,7 +986,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
984986 \\}
985987 });
986988
987 cases.add("null pointer implicit cast",
989 cases.addC("null pointer implicit cast",
988990 \\int* foo(void) {
989991 \\ return 0;
990992 \\}
......@@ -994,7 +996,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
994996 \\}
995997 });
996998
997 cases.add("comma operator",
999 cases.addC("comma operator",
9981000 \\int foo(void) {
9991001 \\ return 1, 2;
10001002 \\}
......@@ -1007,7 +1009,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10071009 \\}
10081010 });
10091011
1010 cases.add("statement expression",
1012 cases.addC("statement expression",
10111013 \\int foo(void) {
10121014 \\ return ({
10131015 \\ int a = 1;
......@@ -1023,7 +1025,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10231025 \\}
10241026 });
10251027
1026 cases.add("__extension__ cast",
1028 cases.addC("__extension__ cast",
10271029 \\int foo(void) {
10281030 \\ return __extension__ 1;
10291031 \\}
......@@ -1033,7 +1035,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10331035 \\}
10341036 });
10351037
1036 cases.add("bitshift",
1038 cases.addC("bitshift",
10371039 \\int foo(void) {
10381040 \\ return (1 << 2) >> 1;
10391041 \\}
......@@ -1043,7 +1045,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10431045 \\}
10441046 });
10451047
1046 cases.add("compound assignment operators",
1048 cases.addC("compound assignment operators",
10471049 \\void foo(void) {
10481050 \\ int a = 0;
10491051 \\ a += (a += 1);
......@@ -1101,7 +1103,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11011103 \\}
11021104 });
11031105
1104 cases.add("compound assignment operators unsigned",
1106 cases.addC("compound assignment operators unsigned",
11051107 \\void foo(void) {
11061108 \\ unsigned a = 0;
11071109 \\ a += (a += 1);
......@@ -1159,7 +1161,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11591161 \\}
11601162 });
11611163
1162 cases.add("post increment/decrement",
1164 cases.addC("post increment/decrement",
11631165 \\void foo(void) {
11641166 \\ int i = 0;
11651167 \\ unsigned u = 0;
......@@ -1207,7 +1209,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12071209 \\}
12081210 });
12091211
1210 cases.add("pre increment/decrement",
1212 cases.addC("pre increment/decrement",
12111213 \\void foo(void) {
12121214 \\ int i = 0;
12131215 \\ unsigned u = 0;
......@@ -1251,7 +1253,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12511253 \\}
12521254 });
12531255
1254 cases.add("do loop",
1256 cases.addC("do loop",
12551257 \\void foo(void) {
12561258 \\ int a = 2;
12571259 \\ do {
......@@ -1278,7 +1280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12781280 \\}
12791281 });
12801282
1281 cases.add("deref function pointer",
1283 cases.addC("deref function pointer",
12821284 \\void foo(void) {}
12831285 \\int baz(void) { return 0; }
12841286 \\void bar(void) {
......@@ -1308,7 +1310,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13081310 \\}
13091311 });
13101312
1311 cases.add("normal deref",
1313 cases.addC("normal deref",
13121314 \\void foo(int *x) {
13131315 \\ *x = 1;
13141316 \\}
......@@ -1339,7 +1341,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13391341 \\ return *ptr;
13401342 \\}
13411343 , &[_][]const u8{
1342 \\pub export fn foo() c_int {
1344 \\pub fn foo() c_int {
13431345 \\ var x: c_int = 1234;
13441346 \\ var ptr: [*c]c_int = &x;
13451347 \\ return ptr.?.*;
......@@ -1351,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13511353 \\ return "bar";
13521354 \\}
13531355 , &[_][]const u8{
1354 \\pub export fn foo() [*c]const u8 {
1356 \\pub fn foo() [*c]const u8 {
13551357 \\ return "bar";
13561358 \\}
13571359 });
......@@ -1361,7 +1363,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13611363 \\ return;
13621364 \\}
13631365 , &[_][]const u8{
1364 \\pub export fn foo() void {
1366 \\pub fn foo() void {
13651367 \\ return;
13661368 \\}
13671369 });
......@@ -1371,7 +1373,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13711373 \\ for (int i = 0; i < 10; i += 1) { }
13721374 \\}
13731375 , &[_][]const u8{
1374 \\pub export fn foo() void {
1376 \\pub fn foo() void {
13751377 \\ {
13761378 \\ var i: c_int = 0;
13771379 \\ while (i < 10) : (i += 1) {}
......@@ -1384,7 +1386,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13841386 \\ for (;;) { }
13851387 \\}
13861388 , &[_][]const u8{
1387 \\pub export fn foo() void {
1389 \\pub fn foo() void {
13881390 \\ while (true) {}
13891391 \\}
13901392 });
......@@ -1396,7 +1398,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13961398 \\ }
13971399 \\}
13981400 , &[_][]const u8{
1399 \\pub export fn foo() void {
1401 \\pub fn foo() void {
14001402 \\ while (true) {
14011403 \\ break;
14021404 \\ }
......@@ -1410,7 +1412,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14101412 \\ }
14111413 \\}
14121414 , &[_][]const u8{
1413 \\pub export fn foo() void {
1415 \\pub fn foo() void {
14141416 \\ while (true) {
14151417 \\ continue;
14161418 \\ }
......@@ -1465,7 +1467,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14651467 \\ return x;
14661468 \\}
14671469 , &[_][]const u8{
1468 \\pub export fn foo() c_int {
1470 \\pub fn foo() c_int {
14691471 \\ var x: c_int = 1;
14701472 \\ {
14711473 \\ var x_0: c_int = 2;
......@@ -1490,7 +1492,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14901492 \\ return ~x;
14911493 \\}
14921494 , &[_][]const u8{
1493 \\pub export fn foo(x: c_int) c_int {
1495 \\pub fn foo(x: c_int) c_int {
14941496 \\ return ~x;
14951497 \\}
14961498 });
......@@ -1503,7 +1505,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15031505 \\ return !c;
15041506 \\}
15051507 , &[_][]const u8{
1506 \\pub export fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
1508 \\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
15071509 \\ return !(a == 0);
15081510 \\ return !(a != 0);
15091511 \\ return !(b != 0);
......@@ -1516,7 +1518,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15161518 \\ return u32;
15171519 \\}
15181520 , &[_][]const u8{
1519 \\pub export fn foo(u32_0: c_int) c_int {
1521 \\pub fn foo(u32_0: c_int) c_int {
15201522 \\ return u32_0;
15211523 \\}
15221524 });
......@@ -1545,7 +1547,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15451547 \\ B,
15461548 \\ C,
15471549 \\};
1548 \\pub export fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int {
1550 \\pub fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int {
15491551 \\ if (a != 0) return 0;
15501552 \\ if (b != 0) return 1;
15511553 \\ if (c != null) return 2;
......@@ -1562,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15621564 \\ return 3;
15631565 \\}
15641566 , &[_][]const u8{
1565 \\pub export fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
1567 \\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
15661568 \\ while (a != 0) return 0;
15671569 \\ while (b != 0) return 1;
15681570 \\ while (c != null) return 2;
......@@ -1578,7 +1580,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15781580 \\ return 3;
15791581 \\}
15801582 , &[_][]const u8{
1581 \\pub export fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
1583 \\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
15821584 \\ while (a != 0) return 0;
15831585 \\ while (b != 0) return 1;
15841586 \\ while (c != null) return 2;
......@@ -1602,7 +1604,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16021604 \\ }
16031605 \\}
16041606 , &[_][]const u8{
1605 \\pub export fn switch_fn(i: c_int) c_int {
1607 \\pub fn switch_fn(i: c_int) c_int {
16061608 \\ var res: c_int = 0;
16071609 \\ __switch: {
16081610 \\ __case_2: {
......@@ -1628,7 +1630,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16281630 \\}
16291631 });
16301632
1631 cases.add(
1633 cases.addC(
16321634 "u integer suffix after 0 (zero) in macro definition",
16331635 "#define ZERO 0U",
16341636 &[_][]const u8{
......@@ -1636,7 +1638,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16361638 },
16371639 );
16381640
1639 cases.add(
1641 cases.addC(
16401642 "l integer suffix after 0 (zero) in macro definition",
16411643 "#define ZERO 0L",
16421644 &[_][]const u8{
......@@ -1644,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16441646 },
16451647 );
16461648
1647 cases.add(
1649 cases.addC(
16481650 "ul integer suffix after 0 (zero) in macro definition",
16491651 "#define ZERO 0UL",
16501652 &[_][]const u8{
......@@ -1652,7 +1654,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16521654 },
16531655 );
16541656
1655 cases.add(
1657 cases.addC(
16561658 "lu integer suffix after 0 (zero) in macro definition",
16571659 "#define ZERO 0LU",
16581660 &[_][]const u8{
......@@ -1660,7 +1662,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16601662 },
16611663 );
16621664
1663 cases.add(
1665 cases.addC(
16641666 "ll integer suffix after 0 (zero) in macro definition",
16651667 "#define ZERO 0LL",
16661668 &[_][]const u8{
......@@ -1668,7 +1670,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16681670 },
16691671 );
16701672
1671 cases.add(
1673 cases.addC(
16721674 "ull integer suffix after 0 (zero) in macro definition",
16731675 "#define ZERO 0ULL",
16741676 &[_][]const u8{
......@@ -1676,7 +1678,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16761678 },
16771679 );
16781680
1679 cases.add(
1681 cases.addC(
16801682 "llu integer suffix after 0 (zero) in macro definition",
16811683 "#define ZERO 0LLU",
16821684 &[_][]const u8{
......@@ -1684,7 +1686,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16841686 },
16851687 );
16861688
1687 cases.add(
1689 cases.addC(
16881690 "bitwise not on u-suffixed 0 (zero) in macro definition",
16891691 "#define NOT_ZERO (~0U)",
16901692 &[_][]const u8{
......@@ -1692,7 +1694,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16921694 },
16931695 );
16941696
1695 cases.add("implicit casts",
1697 cases.addC("implicit casts",
16961698 \\#include <stdbool.h>
16971699 \\
16981700 \\void fn_int(int x);
......@@ -1747,7 +1749,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17471749 \\}
17481750 });
17491751
1750 cases.add("pointer conversion with different alignment",
1752 cases.addC("pointer conversion with different alignment",
17511753 \\void test_ptr_cast() {
17521754 \\ void *p;
17531755 \\ {
......@@ -1781,7 +1783,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17811783 \\}
17821784 });
17831785
1784 cases.add("escape sequences",
1786 cases.addC("escape sequences",
17851787 \\const char *escapes() {
17861788 \\char a = '\'',
17871789 \\ b = '\\',
......@@ -1825,7 +1827,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18251827 }
18261828
18271829 /////////////// Cases for only stage1 because stage2 behavior is better ////////////////
1828 cases.add("Parameterless function prototypes",
1830 cases.addC("Parameterless function prototypes",
18291831 \\void foo() {}
18301832 \\void bar(void) {}
18311833 , &[_][]const u8{