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 {
9191 if (tv.val.cast(Value.Payload.Bytes)) |payload|
9292 if (tv.ty.sentinel()) |sentinel|
9393 if (sentinel.toUnsignedInt() == 0)
94 // TODO: static by default
94 // TODO: static by default
9595 try file.constants.writer().print("const char *const {} = \"{}\";\n", .{ name, payload.data })
9696 else
9797 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 {
1010 \\ B = 1,
1111 \\ C = 2
1212 \\};
13 ,
13 ,
1414 \\void entry(enum Foo foo);
1515 });
1616
......@@ -33,7 +33,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
3333 \\ uint64_t E;
3434 \\ uint64_t F;
3535 \\};
36 ,
36 ,
3737 \\void entry(struct Foo foo);
3838 \\
3939 });
......@@ -68,7 +68,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
6868 \\ bool C;
6969 \\ struct Big D;
7070 \\};
71 ,
71 ,
7272 \\void entry(union Foo foo);
7373 \\
7474 });
......@@ -79,7 +79,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
7979 \\export fn entry(foo: ?*Foo) void { }
8080 , &[_][]const u8{
8181 \\struct Foo;
82 ,
82 ,
8383 \\void entry(struct Foo * foo);
8484 });
8585
......@@ -94,7 +94,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
9494 \\ int32_t A[2];
9595 \\ uint32_t * B[4];
9696 \\};
97 ,
97 ,
9898 \\void entry(struct Foo foo, uint8_t bar[]);
9999 \\
100100 });
......@@ -109,7 +109,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
109109 \\}
110110 , &[_][]const u8{
111111 \\struct S;
112 ,
112 ,
113113 \\uint8_t a(struct S * s);
114114 \\
115115 });
......@@ -125,7 +125,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
125125 \\}
126126 , &[_][]const u8{
127127 \\union U;
128 ,
128 ,
129129 \\uint8_t a(union U * s);
130130 \\
131131 });
......@@ -141,7 +141,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
141141 \\}
142142 , &[_][]const u8{
143143 \\enum E;
144 ,
144 ,
145145 \\uint8_t a(enum E * s);
146146 \\
147147 });
test/stage2/zir.zig+1-1
......@@ -156,7 +156,7 @@ pub fn addCases(ctx: *TestContext) !void {
156156 \\ %0 = call(@a, [])
157157 \\ %1 = returnvoid()
158158 \\})
159 ,
159 ,
160160 &[_][]const u8{
161161 ":18:21: error: message",
162162 },
test/translate_c.zig+58-59
......@@ -13,7 +13,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1313 \\} Bar;
1414 , &[_][]const u8{
1515 \\const struct_unnamed_1 = //
16 ,
16 ,
1717 \\warning: unsupported type: 'Atomic'
1818 \\ opaque {}; //
1919 ,
......@@ -31,9 +31,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3131 \\ | (*((unsigned char *)(p) + 2) << 16))
3232 , &[_][]const u8{
3333 \\pub const FOO = (foo + 2).*;
34 ,
34 ,
3535 \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);
36 ,
36 ,
3737 \\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)) {
3838 \\ 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);
3939 \\}
......@@ -101,11 +101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
101101 \\ a: u8,
102102 \\};
103103 \\pub const Color = struct_Color;
104 ,
104 ,
105105 \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {
106106 \\ return type_1;
107107 \\}
108 ,
108 ,
109109 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 });
110110 });
111111
......@@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
139139 \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {
140140 \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0);
141141 \\}
142 ,
142 ,
143143 \\pub const BAR = (1 != 0) and (2 > 4);
144144 });
145145
......@@ -158,7 +158,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
158158 \\struct bar { int x; int y[0]; };
159159 , &[_][]const u8{
160160 \\pub const struct_foo = opaque {};
161 ,
161 ,
162162 \\pub const struct_bar = opaque {};
163163 });
164164
......@@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
186186 \\ _ = foo;
187187 \\ break :blk bar;
188188 \\};
189 ,
189 ,
190190 \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) {
191191 \\ return blk: {
192192 \\ _ = &x;
......@@ -205,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
205205 \\#define inline 2
206206 , &[_][]const u8{
207207 \\pub const foo = 1;
208 ,
208 ,
209209 \\pub const @"inline" = 2;
210210 });
211211
......@@ -225,12 +225,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
225225 \\};
226226 , &[_][]const u8{
227227 \\pub const struct_arcan_shmif_page = //
228 ,
228 ,
229229 \\warning: unsupported type: 'Atomic'
230230 \\ opaque {}; //
231 ,
231 ,
232232 \\ 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`
234234 \\pub const struct_arcan_shmif_cont = extern struct {
235235 \\ addr: [*c]struct_arcan_shmif_page,
236236 \\};
......@@ -549,7 +549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
549549 \\Foo fun(Foo *a);
550550 , &[_][]const u8{
551551 \\pub const Foo = c_void;
552 ,
552 ,
553553 \\pub extern fn fun(a: ?*Foo) Foo;
554554 });
555555
......@@ -649,7 +649,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
649649 \\};
650650 , &[_][]const u8{
651651 \\pub const struct_Foo = opaque {};
652 ,
652 ,
653653 \\pub const struct_Bar = extern struct {
654654 \\ foo: ?*struct_Foo,
655655 \\};
......@@ -666,7 +666,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
666666 \\#define FLASH_BANK_SIZE (FLASH_SIZE >> 1) /* 1 MB */
667667 , &[_][]const u8{
668668 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);
669 ,
669 ,
670670 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;
671671 });
672672
......@@ -685,13 +685,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
685685 \\pub const struct_Foo = extern struct {
686686 \\ a: [*c]Foo,
687687 \\};
688 ,
688 ,
689689 \\pub const Foo = struct_Foo;
690 ,
690 ,
691691 \\pub const struct_Bar = extern struct {
692692 \\ a: [*c]Foo,
693693 \\};
694 ,
694 ,
695695 \\pub const Bar = struct_Bar;
696696 });
697697
......@@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
705705 \\ x: c_int,
706706 \\ y: [*c]u8,
707707 \\};
708 ,
708 ,
709709 \\pub const Foo = struct_Foo;
710710 });
711711
......@@ -717,7 +717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
717717 \\pub const struct_Foo = extern struct {
718718 \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void,
719719 \\};
720 ,
720 ,
721721 \\pub const Foo = struct_Foo;
722722 });
723723
......@@ -726,9 +726,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
726726 \\struct Foo *some_func(struct Foo *foo, int x);
727727 , &[_][]const u8{
728728 \\pub const struct_Foo = opaque {};
729 ,
729 ,
730730 \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
731 ,
731 ,
732732 \\pub const Foo = struct_Foo;
733733 });
734734
......@@ -743,7 +743,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
743743 \\#define THING1 1234
744744 , &[_][]const u8{
745745 \\pub const THING1 = 1234;
746 ,
746 ,
747747 \\pub const THING2 = THING1;
748748 });
749749
......@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
761761 \\pub const struct_Bar = extern struct {
762762 \\ next: [*c]struct_Foo,
763763 \\};
764 ,
764 ,
765765 \\pub const struct_Foo = extern struct {
766766 \\ next: [*c]struct_Bar,
767767 \\};
......@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
781781 \\pub const struct_comptime = extern struct {
782782 \\ @"defer": c_int,
783783 \\};
784 ,
784 ,
785785 \\pub const @"comptime" = struct_comptime;
786786 });
787787
......@@ -1023,7 +1023,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10231023 \\ x: c_int,
10241024 \\ y: f64,
10251025 \\};
1026 ,
1026 ,
10271027 \\pub const Foo = union_Foo;
10281028 });
10291029
......@@ -1466,7 +1466,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14661466 \\ p,
14671467 \\ _,
14681468 \\};
1469 ,
1469 ,
14701470 \\pub const Baz = struct_Baz;
14711471 });
14721472
......@@ -1532,13 +1532,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15321532 \\#define bar fn_ptr2
15331533 , &[_][]const u8{
15341534 \\pub extern var fn_ptr: ?fn () callconv(.C) void;
1535 ,
1535 ,
15361536 \\pub inline fn foo() void {
15371537 \\ return fn_ptr.?();
15381538 \\}
1539 ,
1539 ,
15401540 \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;
1541 ,
1541 ,
15421542 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
15431543 \\ return fn_ptr2.?(arg_1, arg_2);
15441544 \\}
......@@ -1569,13 +1569,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15691569 \\ gl: struct_unnamed_1,
15701570 \\};
15711571 \\pub extern var glProcs: union_OpenGLProcs;
1572 ,
1572 ,
15731573 \\pub const glClearPFN = PFNGLCLEARPROC;
1574 ,
1574 ,
15751575 \\pub inline fn glClearUnion(arg_2: GLbitfield) void {
15761576 \\ return glProcs.gl.Clear.?(arg_2);
15771577 \\}
1578 ,
1578 ,
15791579 \\pub const OpenGLProcs = union_OpenGLProcs;
15801580 });
15811581
......@@ -1591,11 +1591,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15911591 \\#define FOO(L,b) (L + b)
15921592 , &[_][]const u8{
15931593 \\pub extern var c: c_int;
1594 ,
1594 ,
15951595 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) {
15961596 \\ return c_1 * 2;
15971597 \\}
1598 ,
1598 ,
15991599 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
16001600 \\ return L + b;
16011601 \\}
......@@ -1607,9 +1607,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16071607 \\#define FOO_CHAR '\xfF'
16081608 , &[_][]const u8{
16091609 \\pub const FOO = "aoeu\xab derp";
1610 ,
1610 ,
16111611 \\pub const FOO2 = "aoeu\x7a derp";
1612 ,
1612 ,
16131613 \\pub const FOO_CHAR = '\xff';
16141614 });
16151615
......@@ -1619,9 +1619,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16191619 \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL)
16201620 , &[_][]const u8{
16211621 \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000);
1622 ,
1622 ,
16231623 \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000);
1624 ,
1624 ,
16251625 \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400);
16261626 });
16271627
......@@ -1758,7 +1758,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17581758 , &[_][]const u8{
17591759 \\pub export var anyerror_1: c_uint = @bitCast(c_uint, @as(c_int, 2));
17601760 ,
1761
17621761 \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");
17631762 });
17641763
......@@ -2031,7 +2030,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20312030 \\ var p: c_int = @boolToInt(((c != null) and (td != 0)));
20322031 \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
20332032 \\}
2034 ,
2033 ,
20352034 \\pub const Foo = enum_Foo;
20362035 });
20372036
......@@ -2050,14 +2049,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20502049 \\ x: c_int,
20512050 \\ y: c_int,
20522051 \\};
2053 ,
2052 ,
20542053 \\pub const enum_Bar = extern enum(c_int) {
20552054 \\ A,
20562055 \\ B,
20572056 \\ _,
20582057 \\};
20592058 \\pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;
2060 ,
2059 ,
20612060 \\pub const Foo = struct_Foo;
20622061 \\pub const Bar = enum_Bar;
20632062 });
......@@ -2173,9 +2172,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21732172 \\ _ = a.b;
21742173 \\ _ = c.*.b;
21752174 \\}
2176 ,
2175 ,
21772176 \\pub const DOT = a.b;
2178 ,
2177 ,
21792178 \\pub const ARROW = a.*.b;
21802179 });
21812180
......@@ -2191,7 +2190,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21912190 \\ var index = arg_index;
21922191 \\ return array[@intCast(c_uint, index)];
21932192 \\}
2194 ,
2193 ,
21952194 \\pub const ACCESS = array[2];
21962195 });
21972196
......@@ -2768,9 +2767,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27682767 \\#define FOO_CHAR '\077'
27692768 , &[_][]const u8{
27702769 \\pub const FOO = "aoeu\x13 derp";
2771 ,
2770 ,
27722771 \\pub const FOO2 = "aoeu\x134 derp";
2773 ,
2772 ,
27742773 \\pub const FOO_CHAR = '\x3f';
27752774 });
27762775
......@@ -2790,7 +2789,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27902789 \\ @"1" = 6,
27912790 \\ _,
27922791 \\};
2793 ,
2792 ,
27942793 \\pub const Foo = enum_Foo;
27952794 });
27962795
......@@ -2802,9 +2801,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28022801 \\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {
28032802 \\ return baz((@import("std").meta.cast(?*c_void, baz)));
28042803 \\}
2805 ,
2804 ,
28062805 \\pub const BAR = (@import("std").meta.cast(?*c_void, a));
2807 ,
2806 ,
28082807 \\pub const BAZ = (@import("std").meta.cast(u32, 2));
28092808 });
28102809
......@@ -2844,7 +2843,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28442843 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {
28452844 \\ return if (b < a) b else a;
28462845 \\}
2847 ,
2846 ,
28482847 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {
28492848 \\ return if (b > a) b else a;
28502849 \\}
......@@ -2912,7 +2911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29122911 \\ var bar_1 = arg_bar_1;
29132912 \\ bar_1 = 2;
29142913 \\}
2915 ,
2914 ,
29162915 \\pub const bar = 4;
29172916 });
29182917
......@@ -2984,9 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29842983 \\#define BAZ "oh, " FOO
29852984 , &[_][]const u8{
29862985 \\pub const FOO = "hello";
2987 ,
2986 ,
29882987 \\pub const BAR = FOO ++ " world";
2989 ,
2988 ,
29902989 \\pub const BAZ = "oh, " ++ FOO;
29912990 });
29922991
......@@ -2996,9 +2995,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29962995 \\#define BAR FOO BAZ
29972996 , &[_][]const u8{
29982997 \\pub const FOO = "hello";
2999 ,
2998 ,
30002999 \\pub const BAZ = " world";
3001 ,
3000 ,
30023001 \\pub const BAR = FOO ++ BAZ;
30033002 });
30043003
......@@ -3007,7 +3006,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30073006 \\#define BAR FOO "c"
30083007 , &[_][]const u8{
30093008 \\pub const FOO = "a" ++ "b";
3010 ,
3009 ,
30113010 \\pub const BAR = FOO ++ "c";
30123011 });
30133012
......@@ -3043,7 +3042,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30433042 \\#define FOO ((int)0x8000)
30443043 , &[_][]const u8{
30453044 \\pub const NULL = (@import("std").meta.cast(?*c_void, 0));
3046 ,
3045 ,
30473046 \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000));
30483047 });
30493048