authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-31 12:21:49+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-31 12:21:49+02:00
log28a0583b844654bec108a456eb619efb2af201a1
tree0fbaff0af723dcf6a8d4c0188519ada762468b73
parent3ff381385aad13955360973d1604410335f2ddff
signaturelock-open Commit is signed but in an unrecognized format.

run zig fmt on src/ and test/


4 files changed, 68 insertions(+), 69 deletions(-)

src/codegen/c.zig+1-1
...@@ -91,7 +91,7 @@ fn genArray(file: *C, decl: *Decl) !void {...@@ -91,7 +91,7 @@ fn genArray(file: *C, decl: *Decl) !void {
91 if (tv.val.cast(Value.Payload.Bytes)) |payload|91 if (tv.val.cast(Value.Payload.Bytes)) |payload|
92 if (tv.ty.sentinel()) |sentinel|92 if (tv.ty.sentinel()) |sentinel|
93 if (sentinel.toUnsignedInt() == 0)93 if (sentinel.toUnsignedInt() == 0)
94 // TODO: static by default94 // TODO: static by default
95 try file.constants.writer().print("const char *const {} = \"{}\";\n", .{ name, payload.data })95 try file.constants.writer().print("const char *const {} = \"{}\";\n", .{ name, payload.data })
96 else96 else
97 return file.fail(decl.src(), "TODO byte arrays with non-zero sentinels", .{})97 return file.fail(decl.src(), "TODO byte arrays with non-zero sentinels", .{})
test/gen_h.zig+8-8
...@@ -10,7 +10,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -10,7 +10,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
10 \\ B = 1,10 \\ B = 1,
11 \\ C = 211 \\ C = 2
12 \\};12 \\};
13 ,13 ,
14 \\void entry(enum Foo foo);14 \\void entry(enum Foo foo);
15 });15 });
1616
...@@ -33,7 +33,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -33,7 +33,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
33 \\ uint64_t E;33 \\ uint64_t E;
34 \\ uint64_t F;34 \\ uint64_t F;
35 \\};35 \\};
36 ,36 ,
37 \\void entry(struct Foo foo);37 \\void entry(struct Foo foo);
38 \\38 \\
39 });39 });
...@@ -68,7 +68,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -68,7 +68,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
68 \\ bool C;68 \\ bool C;
69 \\ struct Big D;69 \\ struct Big D;
70 \\};70 \\};
71 ,71 ,
72 \\void entry(union Foo foo);72 \\void entry(union Foo foo);
73 \\73 \\
74 });74 });
...@@ -79,7 +79,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -79,7 +79,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
79 \\export fn entry(foo: ?*Foo) void { }79 \\export fn entry(foo: ?*Foo) void { }
80 , &[_][]const u8{80 , &[_][]const u8{
81 \\struct Foo;81 \\struct Foo;
82 ,82 ,
83 \\void entry(struct Foo * foo);83 \\void entry(struct Foo * foo);
84 });84 });
8585
...@@ -94,7 +94,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -94,7 +94,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
94 \\ int32_t A[2];94 \\ int32_t A[2];
95 \\ uint32_t * B[4];95 \\ uint32_t * B[4];
96 \\};96 \\};
97 ,97 ,
98 \\void entry(struct Foo foo, uint8_t bar[]);98 \\void entry(struct Foo foo, uint8_t bar[]);
99 \\99 \\
100 });100 });
...@@ -109,7 +109,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -109,7 +109,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
109 \\}109 \\}
110 , &[_][]const u8{110 , &[_][]const u8{
111 \\struct S;111 \\struct S;
112 ,112 ,
113 \\uint8_t a(struct S * s);113 \\uint8_t a(struct S * s);
114 \\114 \\
115 });115 });
...@@ -125,7 +125,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -125,7 +125,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
125 \\}125 \\}
126 , &[_][]const u8{126 , &[_][]const u8{
127 \\union U;127 \\union U;
128 ,128 ,
129 \\uint8_t a(union U * s);129 \\uint8_t a(union U * s);
130 \\130 \\
131 });131 });
...@@ -141,7 +141,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -141,7 +141,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
141 \\}141 \\}
142 , &[_][]const u8{142 , &[_][]const u8{
143 \\enum E;143 \\enum E;
144 ,144 ,
145 \\uint8_t a(enum E * s);145 \\uint8_t a(enum E * s);
146 \\146 \\
147 });147 });
test/stage2/zir.zig+1-1
...@@ -156,7 +156,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -156,7 +156,7 @@ pub fn addCases(ctx: *TestContext) !void {
156 \\ %0 = call(@a, [])156 \\ %0 = call(@a, [])
157 \\ %1 = returnvoid()157 \\ %1 = returnvoid()
158 \\})158 \\})
159 ,159 ,
160 &[_][]const u8{160 &[_][]const u8{
161 ":18:21: error: message",161 ":18:21: error: message",
162 },162 },
test/translate_c.zig+58-59
...@@ -13,7 +13,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -13,7 +13,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13 \\} Bar;13 \\} Bar;
14 , &[_][]const u8{14 , &[_][]const u8{
15 \\const struct_unnamed_1 = //15 \\const struct_unnamed_1 = //
16 ,16 ,
17 \\warning: unsupported type: 'Atomic'17 \\warning: unsupported type: 'Atomic'
18 \\ opaque {}; //18 \\ opaque {}; //
19 ,19 ,
...@@ -31,9 +31,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -31,9 +31,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31 \\ | (*((unsigned char *)(p) + 2) << 16))31 \\ | (*((unsigned char *)(p) + 2) << 16))
32 , &[_][]const u8{32 , &[_][]const u8{
33 \\pub const FOO = (foo + 2).*;33 \\pub const FOO = (foo + 2).*;
34 ,34 ,
35 \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);35 \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);
36 ,36 ,
37 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf(((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16)) {37 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf(((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16)) {
38 \\ return ((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16);38 \\ return ((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16);
39 \\}39 \\}
...@@ -101,11 +101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -101,11 +101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
101 \\ a: u8,101 \\ a: u8,
102 \\};102 \\};
103 \\pub const Color = struct_Color;103 \\pub const Color = struct_Color;
104 ,104 ,
105 \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {105 \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {
106 \\ return type_1;106 \\ return type_1;
107 \\}107 \\}
108 ,108 ,
109 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 });109 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 });
110 });110 });
111111
...@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
139 \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {139 \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {
140 \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0);140 \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0);
141 \\}141 \\}
142 ,142 ,
143 \\pub const BAR = (1 != 0) and (2 > 4);143 \\pub const BAR = (1 != 0) and (2 > 4);
144 });144 });
145145
...@@ -158,7 +158,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -158,7 +158,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
158 \\struct bar { int x; int y[0]; };158 \\struct bar { int x; int y[0]; };
159 , &[_][]const u8{159 , &[_][]const u8{
160 \\pub const struct_foo = opaque {};160 \\pub const struct_foo = opaque {};
161 ,161 ,
162 \\pub const struct_bar = opaque {};162 \\pub const struct_bar = opaque {};
163 });163 });
164164
...@@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
186 \\ _ = foo;186 \\ _ = foo;
187 \\ break :blk bar;187 \\ break :blk bar;
188 \\};188 \\};
189 ,189 ,
190 \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) {190 \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) {
191 \\ return blk: {191 \\ return blk: {
192 \\ _ = &x;192 \\ _ = &x;
...@@ -205,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -205,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
205 \\#define inline 2205 \\#define inline 2
206 , &[_][]const u8{206 , &[_][]const u8{
207 \\pub const foo = 1;207 \\pub const foo = 1;
208 ,208 ,
209 \\pub const @"inline" = 2;209 \\pub const @"inline" = 2;
210 });210 });
211211
...@@ -225,12 +225,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -225,12 +225,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
225 \\};225 \\};
226 , &[_][]const u8{226 , &[_][]const u8{
227 \\pub const struct_arcan_shmif_page = //227 \\pub const struct_arcan_shmif_page = //
228 ,228 ,
229 \\warning: unsupported type: 'Atomic'229 \\warning: unsupported type: 'Atomic'
230 \\ opaque {}; //230 \\ opaque {}; //
231 ,231 ,
232 \\ warning: struct demoted to opaque type - unable to translate type of field abufused232 \\ warning: struct demoted to opaque type - unable to translate type of field abufused
233 , // TODO should be `addr: *struct_arcan_shmif_page`233 , // TODO should be `addr: *struct_arcan_shmif_page`
234 \\pub const struct_arcan_shmif_cont = extern struct {234 \\pub const struct_arcan_shmif_cont = extern struct {
235 \\ addr: [*c]struct_arcan_shmif_page,235 \\ addr: [*c]struct_arcan_shmif_page,
236 \\};236 \\};
...@@ -549,7 +549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -549,7 +549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
549 \\Foo fun(Foo *a);549 \\Foo fun(Foo *a);
550 , &[_][]const u8{550 , &[_][]const u8{
551 \\pub const Foo = c_void;551 \\pub const Foo = c_void;
552 ,552 ,
553 \\pub extern fn fun(a: ?*Foo) Foo;553 \\pub extern fn fun(a: ?*Foo) Foo;
554 });554 });
555555
...@@ -649,7 +649,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -649,7 +649,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
649 \\};649 \\};
650 , &[_][]const u8{650 , &[_][]const u8{
651 \\pub const struct_Foo = opaque {};651 \\pub const struct_Foo = opaque {};
652 ,652 ,
653 \\pub const struct_Bar = extern struct {653 \\pub const struct_Bar = extern struct {
654 \\ foo: ?*struct_Foo,654 \\ foo: ?*struct_Foo,
655 \\};655 \\};
...@@ -666,7 +666,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -666,7 +666,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
666 \\#define FLASH_BANK_SIZE (FLASH_SIZE >> 1) /* 1 MB */666 \\#define FLASH_BANK_SIZE (FLASH_SIZE >> 1) /* 1 MB */
667 , &[_][]const u8{667 , &[_][]const u8{
668 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);668 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);
669 ,669 ,
670 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;670 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;
671 });671 });
672672
...@@ -685,13 +685,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -685,13 +685,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
685 \\pub const struct_Foo = extern struct {685 \\pub const struct_Foo = extern struct {
686 \\ a: [*c]Foo,686 \\ a: [*c]Foo,
687 \\};687 \\};
688 ,688 ,
689 \\pub const Foo = struct_Foo;689 \\pub const Foo = struct_Foo;
690 ,690 ,
691 \\pub const struct_Bar = extern struct {691 \\pub const struct_Bar = extern struct {
692 \\ a: [*c]Foo,692 \\ a: [*c]Foo,
693 \\};693 \\};
694 ,694 ,
695 \\pub const Bar = struct_Bar;695 \\pub const Bar = struct_Bar;
696 });696 });
697697
...@@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
705 \\ x: c_int,705 \\ x: c_int,
706 \\ y: [*c]u8,706 \\ y: [*c]u8,
707 \\};707 \\};
708 ,708 ,
709 \\pub const Foo = struct_Foo;709 \\pub const Foo = struct_Foo;
710 });710 });
711711
...@@ -717,7 +717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -717,7 +717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
717 \\pub const struct_Foo = extern struct {717 \\pub const struct_Foo = extern struct {
718 \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void,718 \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void,
719 \\};719 \\};
720 ,720 ,
721 \\pub const Foo = struct_Foo;721 \\pub const Foo = struct_Foo;
722 });722 });
723723
...@@ -726,9 +726,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -726,9 +726,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
726 \\struct Foo *some_func(struct Foo *foo, int x);726 \\struct Foo *some_func(struct Foo *foo, int x);
727 , &[_][]const u8{727 , &[_][]const u8{
728 \\pub const struct_Foo = opaque {};728 \\pub const struct_Foo = opaque {};
729 ,729 ,
730 \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;730 \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
731 ,731 ,
732 \\pub const Foo = struct_Foo;732 \\pub const Foo = struct_Foo;
733 });733 });
734734
...@@ -743,7 +743,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -743,7 +743,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
743 \\#define THING1 1234743 \\#define THING1 1234
744 , &[_][]const u8{744 , &[_][]const u8{
745 \\pub const THING1 = 1234;745 \\pub const THING1 = 1234;
746 ,746 ,
747 \\pub const THING2 = THING1;747 \\pub const THING2 = THING1;
748 });748 });
749749
...@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
761 \\pub const struct_Bar = extern struct {761 \\pub const struct_Bar = extern struct {
762 \\ next: [*c]struct_Foo,762 \\ next: [*c]struct_Foo,
763 \\};763 \\};
764 ,764 ,
765 \\pub const struct_Foo = extern struct {765 \\pub const struct_Foo = extern struct {
766 \\ next: [*c]struct_Bar,766 \\ next: [*c]struct_Bar,
767 \\};767 \\};
...@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
781 \\pub const struct_comptime = extern struct {781 \\pub const struct_comptime = extern struct {
782 \\ @"defer": c_int,782 \\ @"defer": c_int,
783 \\};783 \\};
784 ,784 ,
785 \\pub const @"comptime" = struct_comptime;785 \\pub const @"comptime" = struct_comptime;
786 });786 });
787787
...@@ -1023,7 +1023,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1023,7 +1023,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1023 \\ x: c_int,1023 \\ x: c_int,
1024 \\ y: f64,1024 \\ y: f64,
1025 \\};1025 \\};
1026 ,1026 ,
1027 \\pub const Foo = union_Foo;1027 \\pub const Foo = union_Foo;
1028 });1028 });
10291029
...@@ -1466,7 +1466,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1466,7 +1466,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1466 \\ p,1466 \\ p,
1467 \\ _,1467 \\ _,
1468 \\};1468 \\};
1469 ,1469 ,
1470 \\pub const Baz = struct_Baz;1470 \\pub const Baz = struct_Baz;
1471 });1471 });
14721472
...@@ -1532,13 +1532,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1532,13 +1532,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1532 \\#define bar fn_ptr21532 \\#define bar fn_ptr2
1533 , &[_][]const u8{1533 , &[_][]const u8{
1534 \\pub extern var fn_ptr: ?fn () callconv(.C) void;1534 \\pub extern var fn_ptr: ?fn () callconv(.C) void;
1535 ,1535 ,
1536 \\pub inline fn foo() void {1536 \\pub inline fn foo() void {
1537 \\ return fn_ptr.?();1537 \\ return fn_ptr.?();
1538 \\}1538 \\}
1539 ,1539 ,
1540 \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;1540 \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;
1541 ,1541 ,
1542 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {1542 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
1543 \\ return fn_ptr2.?(arg_1, arg_2);1543 \\ return fn_ptr2.?(arg_1, arg_2);
1544 \\}1544 \\}
...@@ -1569,13 +1569,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1569,13 +1569,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1569 \\ gl: struct_unnamed_1,1569 \\ gl: struct_unnamed_1,
1570 \\};1570 \\};
1571 \\pub extern var glProcs: union_OpenGLProcs;1571 \\pub extern var glProcs: union_OpenGLProcs;
1572 ,1572 ,
1573 \\pub const glClearPFN = PFNGLCLEARPROC;1573 \\pub const glClearPFN = PFNGLCLEARPROC;
1574 ,1574 ,
1575 \\pub inline fn glClearUnion(arg_2: GLbitfield) void {1575 \\pub inline fn glClearUnion(arg_2: GLbitfield) void {
1576 \\ return glProcs.gl.Clear.?(arg_2);1576 \\ return glProcs.gl.Clear.?(arg_2);
1577 \\}1577 \\}
1578 ,1578 ,
1579 \\pub const OpenGLProcs = union_OpenGLProcs;1579 \\pub const OpenGLProcs = union_OpenGLProcs;
1580 });1580 });
15811581
...@@ -1591,11 +1591,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1591,11 +1591,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1591 \\#define FOO(L,b) (L + b)1591 \\#define FOO(L,b) (L + b)
1592 , &[_][]const u8{1592 , &[_][]const u8{
1593 \\pub extern var c: c_int;1593 \\pub extern var c: c_int;
1594 ,1594 ,
1595 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) {1595 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) {
1596 \\ return c_1 * 2;1596 \\ return c_1 * 2;
1597 \\}1597 \\}
1598 ,1598 ,
1599 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {1599 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
1600 \\ return L + b;1600 \\ return L + b;
1601 \\}1601 \\}
...@@ -1607,9 +1607,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1607,9 +1607,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1607 \\#define FOO_CHAR '\xfF'1607 \\#define FOO_CHAR '\xfF'
1608 , &[_][]const u8{1608 , &[_][]const u8{
1609 \\pub const FOO = "aoeu\xab derp";1609 \\pub const FOO = "aoeu\xab derp";
1610 ,1610 ,
1611 \\pub const FOO2 = "aoeu\x7a derp";1611 \\pub const FOO2 = "aoeu\x7a derp";
1612 ,1612 ,
1613 \\pub const FOO_CHAR = '\xff';1613 \\pub const FOO_CHAR = '\xff';
1614 });1614 });
16151615
...@@ -1619,9 +1619,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1619,9 +1619,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1619 \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL)1619 \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL)
1620 , &[_][]const u8{1620 , &[_][]const u8{
1621 \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000);1621 \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000);
1622 ,1622 ,
1623 \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000);1623 \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000);
1624 ,1624 ,
1625 \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400);1625 \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400);
1626 });1626 });
16271627
...@@ -1758,7 +1758,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1758,7 +1758,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1758 , &[_][]const u8{1758 , &[_][]const u8{
1759 \\pub export var anyerror_1: c_uint = @bitCast(c_uint, @as(c_int, 2));1759 \\pub export var anyerror_1: c_uint = @bitCast(c_uint, @as(c_int, 2));
1760 ,1760 ,
1761
1762 \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");1761 \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");
1763 });1762 });
17641763
...@@ -2031,7 +2030,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2031,7 +2030,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2031 \\ var p: c_int = @boolToInt(((c != null) and (td != 0)));2030 \\ var p: c_int = @boolToInt(((c != null) and (td != 0)));
2032 \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);2031 \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
2033 \\}2032 \\}
2034 ,2033 ,
2035 \\pub const Foo = enum_Foo;2034 \\pub const Foo = enum_Foo;
2036 });2035 });
20372036
...@@ -2050,14 +2049,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2050,14 +2049,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2050 \\ x: c_int,2049 \\ x: c_int,
2051 \\ y: c_int,2050 \\ y: c_int,
2052 \\};2051 \\};
2053 ,2052 ,
2054 \\pub const enum_Bar = extern enum(c_int) {2053 \\pub const enum_Bar = extern enum(c_int) {
2055 \\ A,2054 \\ A,
2056 \\ B,2055 \\ B,
2057 \\ _,2056 \\ _,
2058 \\};2057 \\};
2059 \\pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;2058 \\pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;
2060 ,2059 ,
2061 \\pub const Foo = struct_Foo;2060 \\pub const Foo = struct_Foo;
2062 \\pub const Bar = enum_Bar;2061 \\pub const Bar = enum_Bar;
2063 });2062 });
...@@ -2173,9 +2172,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2173,9 +2172,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2173 \\ _ = a.b;2172 \\ _ = a.b;
2174 \\ _ = c.*.b;2173 \\ _ = c.*.b;
2175 \\}2174 \\}
2176 ,2175 ,
2177 \\pub const DOT = a.b;2176 \\pub const DOT = a.b;
2178 ,2177 ,
2179 \\pub const ARROW = a.*.b;2178 \\pub const ARROW = a.*.b;
2180 });2179 });
21812180
...@@ -2191,7 +2190,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2191,7 +2190,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2191 \\ var index = arg_index;2190 \\ var index = arg_index;
2192 \\ return array[@intCast(c_uint, index)];2191 \\ return array[@intCast(c_uint, index)];
2193 \\}2192 \\}
2194 ,2193 ,
2195 \\pub const ACCESS = array[2];2194 \\pub const ACCESS = array[2];
2196 });2195 });
21972196
...@@ -2768,9 +2767,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2768,9 +2767,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2768 \\#define FOO_CHAR '\077'2767 \\#define FOO_CHAR '\077'
2769 , &[_][]const u8{2768 , &[_][]const u8{
2770 \\pub const FOO = "aoeu\x13 derp";2769 \\pub const FOO = "aoeu\x13 derp";
2771 ,2770 ,
2772 \\pub const FOO2 = "aoeu\x134 derp";2771 \\pub const FOO2 = "aoeu\x134 derp";
2773 ,2772 ,
2774 \\pub const FOO_CHAR = '\x3f';2773 \\pub const FOO_CHAR = '\x3f';
2775 });2774 });
27762775
...@@ -2790,7 +2789,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2790,7 +2789,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2790 \\ @"1" = 6,2789 \\ @"1" = 6,
2791 \\ _,2790 \\ _,
2792 \\};2791 \\};
2793 ,2792 ,
2794 \\pub const Foo = enum_Foo;2793 \\pub const Foo = enum_Foo;
2795 });2794 });
27962795
...@@ -2802,9 +2801,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2802,9 +2801,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2802 \\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {2801 \\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {
2803 \\ return baz((@import("std").meta.cast(?*c_void, baz)));2802 \\ return baz((@import("std").meta.cast(?*c_void, baz)));
2804 \\}2803 \\}
2805 ,2804 ,
2806 \\pub const BAR = (@import("std").meta.cast(?*c_void, a));2805 \\pub const BAR = (@import("std").meta.cast(?*c_void, a));
2807 ,2806 ,
2808 \\pub const BAZ = (@import("std").meta.cast(u32, 2));2807 \\pub const BAZ = (@import("std").meta.cast(u32, 2));
2809 });2808 });
28102809
...@@ -2844,7 +2843,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2844,7 +2843,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2844 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {2843 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {
2845 \\ return if (b < a) b else a;2844 \\ return if (b < a) b else a;
2846 \\}2845 \\}
2847 ,2846 ,
2848 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {2847 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {
2849 \\ return if (b > a) b else a;2848 \\ return if (b > a) b else a;
2850 \\}2849 \\}
...@@ -2912,7 +2911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2912,7 +2911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2912 \\ var bar_1 = arg_bar_1;2911 \\ var bar_1 = arg_bar_1;
2913 \\ bar_1 = 2;2912 \\ bar_1 = 2;
2914 \\}2913 \\}
2915 ,2914 ,
2916 \\pub const bar = 4;2915 \\pub const bar = 4;
2917 });2916 });
29182917
...@@ -2984,9 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2984,9 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2984 \\#define BAZ "oh, " FOO2983 \\#define BAZ "oh, " FOO
2985 , &[_][]const u8{2984 , &[_][]const u8{
2986 \\pub const FOO = "hello";2985 \\pub const FOO = "hello";
2987 ,2986 ,
2988 \\pub const BAR = FOO ++ " world";2987 \\pub const BAR = FOO ++ " world";
2989 ,2988 ,
2990 \\pub const BAZ = "oh, " ++ FOO;2989 \\pub const BAZ = "oh, " ++ FOO;
2991 });2990 });
29922991
...@@ -2996,9 +2995,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2996,9 +2995,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2996 \\#define BAR FOO BAZ2995 \\#define BAR FOO BAZ
2997 , &[_][]const u8{2996 , &[_][]const u8{
2998 \\pub const FOO = "hello";2997 \\pub const FOO = "hello";
2999 ,2998 ,
3000 \\pub const BAZ = " world";2999 \\pub const BAZ = " world";
3001 ,3000 ,
3002 \\pub const BAR = FOO ++ BAZ;3001 \\pub const BAR = FOO ++ BAZ;
3003 });3002 });
30043003
...@@ -3007,7 +3006,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3007,7 +3006,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3007 \\#define BAR FOO "c"3006 \\#define BAR FOO "c"
3008 , &[_][]const u8{3007 , &[_][]const u8{
3009 \\pub const FOO = "a" ++ "b";3008 \\pub const FOO = "a" ++ "b";
3010 ,3009 ,
3011 \\pub const BAR = FOO ++ "c";3010 \\pub const BAR = FOO ++ "c";
3012 });3011 });
30133012
...@@ -3043,7 +3042,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3043,7 +3042,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3043 \\#define FOO ((int)0x8000)3042 \\#define FOO ((int)0x8000)
3044 , &[_][]const u8{3043 , &[_][]const u8{
3045 \\pub const NULL = (@import("std").meta.cast(?*c_void, 0));3044 \\pub const NULL = (@import("std").meta.cast(?*c_void, 0));
3046 ,3045 ,
3047 \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000));3046 \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000));
3048 });3047 });
30493048