| ... | @@ -3,6 +3,14 @@ const std = @import("std"); | ... | @@ -3,6 +3,14 @@ const std = @import("std"); |
| 3 | const CrossTarget = std.zig.CrossTarget; | 3 | const CrossTarget = std.zig.CrossTarget; |
| 4 | | 4 | |
| 5 | pub fn addCases(cases: *tests.TranslateCContext) void { | 5 | pub fn addCases(cases: *tests.TranslateCContext) void { |
| | 6 | cases.add("use cast param as macro fn return type", |
| | 7 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((u32)(x) + SYS_BASE_CACHED) |
| | 8 | , &[_][]const u8{ |
| | 9 | \\pub fn MEM_PHYSICAL_TO_K0(x: anytype) callconv(.Inline) ?*c_void { |
| | 10 | \\ return @import("std").meta.cast(?*c_void, @import("std").meta.cast(u32, x) + SYS_BASE_CACHED); |
| | 11 | \\} |
| | 12 | }); |
| | 13 | |
| 6 | cases.add("variadic function demoted to prototype", | 14 | cases.add("variadic function demoted to prototype", |
| 7 | \\int foo(int bar, ...) { | 15 | \\int foo(int bar, ...) { |
| 8 | \\ return 1; | 16 | \\ return 1; |
| ... | @@ -21,11 +29,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -21,11 +29,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 21 | \\ Foo *bar; | 29 | \\ Foo *bar; |
| 22 | \\} Bar; | 30 | \\} Bar; |
| 23 | , &[_][]const u8{ | 31 | , &[_][]const u8{ |
| 24 | \\const struct_unnamed_1 = // | 32 | \\source.h:1:9: warning: struct demoted to opaque type - unable to translate type of field foo |
| 25 | , | 33 | \\const struct_unnamed_1 = opaque {}; |
| 26 | \\warning: unsupported type: 'Atomic' | | |
| 27 | \\ opaque {}; // | | |
| 28 | , | | |
| 29 | \\pub const Foo = struct_unnamed_1; | 34 | \\pub const Foo = struct_unnamed_1; |
| 30 | \\const struct_unnamed_2 = extern struct { | 35 | \\const struct_unnamed_2 = extern struct { |
| 31 | \\ bar: ?*Foo, | 36 | \\ bar: ?*Foo, |
| ... | @@ -43,8 +48,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -43,8 +48,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 43 | , | 48 | , |
| 44 | \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9); | 49 | \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9); |
| 45 | , | 50 | , |
| 46 | \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @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)) { | 51 | \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @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)) { |
| 47 | \\ 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); | 52 | \\ 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); |
| 48 | \\} | 53 | \\} |
| 49 | }); | 54 | }); |
| 50 | | 55 | |
| ... | @@ -107,7 +112,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -107,7 +112,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 107 | \\ int i1; | 112 | \\ int i1; |
| 108 | \\} boom_t; | 113 | \\} boom_t; |
| 109 | \\#define FOO ((boom_t){1}) | 114 | \\#define FOO ((boom_t){1}) |
| 110 | , &[_][]const u8{ // TODO properly translate this | 115 | , &[_][]const u8{ |
| 111 | \\pub const struct_Color = extern struct { | 116 | \\pub const struct_Color = extern struct { |
| 112 | \\ r: u8, | 117 | \\ r: u8, |
| 113 | \\ g: u8, | 118 | \\ g: u8, |
| ... | @@ -127,7 +132,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -127,7 +132,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 127 | \\}; | 132 | \\}; |
| 128 | \\pub const boom_t = struct_boom_t; | 133 | \\pub const boom_t = struct_boom_t; |
| 129 | , | 134 | , |
| 130 | \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{ 1 }); | 135 | \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{1}); |
| 131 | }); | 136 | }); |
| 132 | | 137 | |
| 133 | cases.add("complex switch", | 138 | cases.add("complex switch", |
| ... | @@ -142,14 +147,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -142,14 +147,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 142 | \\ } | 147 | \\ } |
| 143 | \\} | 148 | \\} |
| 144 | , &[_][]const u8{ // TODO properly translate this | 149 | , &[_][]const u8{ // TODO properly translate this |
| 145 | \\pub const main = @compileError("unable to translate function"); | 150 | \\pub export fn main() c_int { |
| | 151 | \\ var i: c_int = 2; |
| | 152 | \\ @"switch": { |
| | 153 | \\ case_1: { |
| | 154 | \\ case: { |
| | 155 | \\ switch (i) { |
| | 156 | \\ @as(c_int, 0) => break :case, |
| | 157 | \\ @as(c_int, 2) => break :case_1, |
| | 158 | \\ else => break :@"switch", |
| | 159 | \\ } |
| | 160 | \\ } |
| | 161 | \\ } |
| | 162 | \\ { |
| | 163 | \\ { |
| | 164 | \\ i += @as(c_int, 2); |
| | 165 | \\ } |
| | 166 | \\ i += @as(c_int, 1); |
| | 167 | \\ } |
| | 168 | \\ } |
| | 169 | \\ return 0; |
| | 170 | \\} |
| 146 | }); | 171 | }); |
| 147 | | 172 | |
| 148 | cases.add("correct semicolon after infixop", | 173 | cases.add("correct semicolon after infixop", |
| 149 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) | 174 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) |
| 150 | , &[_][]const u8{ | 175 | , &[_][]const u8{ |
| 151 | \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) { | 176 | \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != 0) { |
| 152 | \\ return ((_fp.*._flags) & _IO_ERR_SEEN) != 0; | 177 | \\ return (_fp.*._flags & _IO_ERR_SEEN) != 0; |
| 153 | \\} | 178 | \\} |
| 154 | }); | 179 | }); |
| 155 | | 180 | |
| ... | @@ -194,7 +219,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -194,7 +219,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 194 | \\ while (false) while (false) {}; | 219 | \\ while (false) while (false) {}; |
| 195 | \\ while (true) while (false) {}; | 220 | \\ while (true) while (false) {}; |
| 196 | \\ while (true) while (true) { | 221 | \\ while (true) while (true) { |
| 197 | \\ if (!false) break; | 222 | \\ break; |
| 198 | \\ }; | 223 | \\ }; |
| 199 | \\} | 224 | \\} |
| 200 | }); | 225 | }); |
| ... | @@ -245,15 +270,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -245,15 +270,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 245 | \\ volatile _Atomic int abufused[12]; | 270 | \\ volatile _Atomic int abufused[12]; |
| 246 | \\}; | 271 | \\}; |
| 247 | , &[_][]const u8{ | 272 | , &[_][]const u8{ |
| 248 | \\pub const struct_arcan_shmif_page = // | 273 | \\source.h:4:8: warning: struct demoted to opaque type - unable to translate type of field abufused |
| 249 | , | 274 | \\pub const struct_arcan_shmif_page = opaque {}; |
| 250 | \\warning: unsupported type: 'Atomic' | | |
| 251 | \\ opaque {}; // | | |
| 252 | , | | |
| 253 | \\ warning: struct demoted to opaque type - unable to translate type of field abufused | | |
| 254 | , // TODO should be `addr: *struct_arcan_shmif_page` | | |
| 255 | \\pub const struct_arcan_shmif_cont = extern struct { | 275 | \\pub const struct_arcan_shmif_cont = extern struct { |
| 256 | \\ addr: [*c]struct_arcan_shmif_page, | 276 | \\ addr: ?*struct_arcan_shmif_page, |
| 257 | \\}; | 277 | \\}; |
| 258 | }); | 278 | }); |
| 259 | | 279 | |
| ... | @@ -514,8 +534,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -514,8 +534,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 514 | \\ var a: c_int = undefined; | 534 | \\ var a: c_int = undefined; |
| 515 | \\ _ = @as(c_int, 1); | 535 | \\ _ = @as(c_int, 1); |
| 516 | \\ _ = "hey"; | 536 | \\ _ = "hey"; |
| 517 | \\ _ = (@as(c_int, 1) + @as(c_int, 1)); | 537 | \\ _ = @as(c_int, 1) + @as(c_int, 1); |
| 518 | \\ _ = (@as(c_int, 1) - @as(c_int, 1)); | 538 | \\ _ = @as(c_int, 1) - @as(c_int, 1); |
| 519 | \\ a = 1; | 539 | \\ a = 1; |
| 520 | \\} | 540 | \\} |
| 521 | }); | 541 | }); |
| ... | @@ -634,9 +654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -634,9 +654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 634 | \\ var a: c_int = undefined; | 654 | \\ var a: c_int = undefined; |
| 635 | \\ var b: c_int = undefined; | 655 | \\ var b: c_int = undefined; |
| 636 | \\ var c: c_int = undefined; | 656 | \\ var c: c_int = undefined; |
| 637 | \\ c = (a + b); | 657 | \\ c = a + b; |
| 638 | \\ c = (a - b); | 658 | \\ c = a - b; |
| 639 | \\ c = (a * b); | 659 | \\ c = a * b; |
| 640 | \\ c = @divTrunc(a, b); | 660 | \\ c = @divTrunc(a, b); |
| 641 | \\ c = @rem(a, b); | 661 | \\ c = @rem(a, b); |
| 642 | \\ return 0; | 662 | \\ return 0; |
| ... | @@ -645,11 +665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -645,11 +665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 645 | \\ var a: c_uint = undefined; | 665 | \\ var a: c_uint = undefined; |
| 646 | \\ var b: c_uint = undefined; | 666 | \\ var b: c_uint = undefined; |
| 647 | \\ var c: c_uint = undefined; | 667 | \\ var c: c_uint = undefined; |
| 648 | \\ c = (a +% b); | 668 | \\ c = a +% b; |
| 649 | \\ c = (a -% b); | 669 | \\ c = a -% b; |
| 650 | \\ c = (a *% b); | 670 | \\ c = a *% b; |
| 651 | \\ c = (a / b); | 671 | \\ c = a / b; |
| 652 | \\ c = (a % b); | 672 | \\ c = a % b; |
| 653 | \\ return 0; | 673 | \\ return 0; |
| 654 | \\} | 674 | \\} |
| 655 | }); | 675 | }); |
| ... | @@ -1639,7 +1659,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1639,7 +1659,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1639 | cases.add("macro pointer cast", | 1659 | cases.add("macro pointer cast", |
| 1640 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) | 1660 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1641 | , &[_][]const u8{ | 1661 | , &[_][]const u8{ |
| 1642 | \\pub const NRF_GPIO = (@import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE)); | 1662 | \\pub const NRF_GPIO = @import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE); |
| 1643 | }); | 1663 | }); |
| 1644 | | 1664 | |
| 1645 | cases.add("basic macro function", | 1665 | cases.add("basic macro function", |
| ... | @@ -1723,17 +1743,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1723,17 +1743,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1723 | \\} | 1743 | \\} |
| 1724 | , &[_][]const u8{ | 1744 | , &[_][]const u8{ |
| 1725 | \\pub export fn foo() c_int { | 1745 | \\pub export fn foo() c_int { |
| 1726 | \\ _ = (blk: { | 1746 | \\ _ = blk: { |
| 1727 | \\ _ = @as(c_int, 2); | 1747 | \\ _ = @as(c_int, 2); |
| 1728 | \\ break :blk @as(c_int, 4); | 1748 | \\ break :blk @as(c_int, 4); |
| 1729 | \\ }); | 1749 | \\ }; |
| 1730 | \\ return (blk: { | 1750 | \\ return blk: { |
| 1731 | \\ _ = (blk_1: { | 1751 | \\ _ = blk_1: { |
| 1732 | \\ _ = @as(c_int, 2); | 1752 | \\ _ = @as(c_int, 2); |
| 1733 | \\ break :blk_1 @as(c_int, 4); | 1753 | \\ break :blk_1 @as(c_int, 4); |
| 1734 | \\ }); | 1754 | \\ }; |
| 1735 | \\ break :blk @as(c_int, 6); | 1755 | \\ break :blk @as(c_int, 6); |
| 1736 | \\ }); | 1756 | \\ }; |
| 1737 | \\} | 1757 | \\} |
| 1738 | }); | 1758 | }); |
| 1739 | | 1759 | |
| ... | @@ -1780,20 +1800,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1780,20 +1800,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1780 | \\ while (true) { | 1800 | \\ while (true) { |
| 1781 | \\ var a_1: c_int = 4; | 1801 | \\ var a_1: c_int = 4; |
| 1782 | \\ a_1 = 9; | 1802 | \\ a_1 = 9; |
| 1783 | \\ return (blk: { | 1803 | \\ return blk: { |
| 1784 | \\ _ = @as(c_int, 6); | 1804 | \\ _ = @as(c_int, 6); |
| 1785 | \\ break :blk a_1; | 1805 | \\ break :blk a_1; |
| 1786 | \\ }); | 1806 | \\ }; |
| 1787 | \\ } | 1807 | \\ } |
| 1788 | \\ while (true) { | 1808 | \\ while (true) { |
| 1789 | \\ var a_1: c_int = 2; | 1809 | \\ var a_1: c_int = 2; |
| 1790 | \\ a_1 = 12; | 1810 | \\ a_1 = 12; |
| 1791 | \\ if (!true) break; | | |
| 1792 | \\ } | | |
| 1793 | \\ while (true) { | | |
| 1794 | \\ a = 7; | | |
| 1795 | \\ if (!true) break; | | |
| 1796 | \\ } | 1811 | \\ } |
| | 1812 | \\ while (true) a = 7; |
| 1797 | \\ return 0; | 1813 | \\ return 0; |
| 1798 | \\} | 1814 | \\} |
| 1799 | }); | 1815 | }); |
| ... | @@ -1813,13 +1829,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1813,13 +1829,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1813 | \\ var b: c_int = 4; | 1829 | \\ var b: c_int = 4; |
| 1814 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { | 1830 | \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { |
| 1815 | \\ var a: c_int = 2; | 1831 | \\ var a: c_int = 2; |
| 1816 | \\ _ = (blk: { | 1832 | \\ _ = blk: { |
| 1817 | \\ _ = (blk_1: { | 1833 | \\ _ = blk_1: { |
| 1818 | \\ a = 6; | 1834 | \\ a = 6; |
| 1819 | \\ break :blk_1 @as(c_int, 5); | 1835 | \\ break :blk_1 @as(c_int, 5); |
| 1820 | \\ }); | 1836 | \\ }; |
| 1821 | \\ break :blk @as(c_int, 7); | 1837 | \\ break :blk @as(c_int, 7); |
| 1822 | \\ }); | 1838 | \\ }; |
| 1823 | \\ } | 1839 | \\ } |
| 1824 | \\ } | 1840 | \\ } |
| 1825 | \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2))); | 1841 | \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2))); |
| ... | @@ -1854,7 +1870,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1854,7 +1870,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1854 | \\} | 1870 | \\} |
| 1855 | , &[_][]const u8{ | 1871 | , &[_][]const u8{ |
| 1856 | \\pub export fn bar() c_int { | 1872 | \\pub export fn bar() c_int { |
| 1857 | \\ if ((if (true) @as(c_int, 5) else (if (true) @as(c_int, 4) else @as(c_int, 6))) != 0) _ = @as(c_int, 2); | 1873 | \\ if ((if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6)) != 0) _ = @as(c_int, 2); |
| 1858 | \\ return if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6); | 1874 | \\ return if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6); |
| 1859 | \\} | 1875 | \\} |
| 1860 | }); | 1876 | }); |
| ... | @@ -1894,7 +1910,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1894,7 +1910,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1894 | \\ } | 1910 | \\ } |
| 1895 | \\ res = 2; | 1911 | \\ res = 2; |
| 1896 | \\ } | 1912 | \\ } |
| 1897 | \\ res = (@as(c_int, 3) * i); | 1913 | \\ res = @as(c_int, 3) * i; |
| 1898 | \\ break :@"switch"; | 1914 | \\ break :@"switch"; |
| 1899 | \\ } | 1915 | \\ } |
| 1900 | \\ res = 5; | 1916 | \\ res = 5; |
| ... | @@ -2043,12 +2059,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2043,12 +2059,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2043 | \\pub export fn foo() void { | 2059 | \\pub export fn foo() void { |
| 2044 | \\ var a: c_int = 2; | 2060 | \\ var a: c_int = 2; |
| 2045 | \\ while (true) { | 2061 | \\ while (true) { |
| 2046 | \\ a = (a - @as(c_int, 1)); | 2062 | \\ a = a - @as(c_int, 1); |
| 2047 | \\ if (!(a != 0)) break; | 2063 | \\ if (!(a != 0)) break; |
| 2048 | \\ } | 2064 | \\ } |
| 2049 | \\ var b: c_int = 2; | 2065 | \\ var b: c_int = 2; |
| 2050 | \\ while (true) { | 2066 | \\ while (true) { |
| 2051 | \\ b = (b - @as(c_int, 1)); | 2067 | \\ b = b - @as(c_int, 1); |
| 2052 | \\ if (!(b != 0)) break; | 2068 | \\ if (!(b != 0)) break; |
| 2053 | \\ } | 2069 | \\ } |
| 2054 | \\} | 2070 | \\} |
| ... | @@ -2078,6 +2094,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2078,6 +2094,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2078 | \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p); | 2094 | \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p); |
| 2079 | \\} | 2095 | \\} |
| 2080 | , &[_][]const u8{ | 2096 | , &[_][]const u8{ |
| | 2097 | \\pub const FooA = @enumToInt(enum_Foo.A); |
| | 2098 | \\pub const FooB = @enumToInt(enum_Foo.B); |
| | 2099 | \\pub const FooC = @enumToInt(enum_Foo.C); |
| 2081 | \\pub const enum_Foo = extern enum(c_int) { | 2100 | \\pub const enum_Foo = extern enum(c_int) { |
| 2082 | \\ A, | 2101 | \\ A, |
| 2083 | \\ B, | 2102 | \\ B, |
| ... | @@ -2090,19 +2109,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2090,19 +2109,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2090 | \\ var b = arg_b; | 2109 | \\ var b = arg_b; |
| 2091 | \\ var c = arg_c; | 2110 | \\ var c = arg_c; |
| 2092 | \\ var d: enum_Foo = @intToEnum(enum_Foo, FooA); | 2111 | \\ var d: enum_Foo = @intToEnum(enum_Foo, FooA); |
| 2093 | \\ var e: c_int = @boolToInt(((a != 0) and (b != 0))); | 2112 | \\ var e: c_int = @boolToInt((a != 0) and (b != 0)); |
| 2094 | \\ var f: c_int = @boolToInt(((b != 0) and (c != null))); | 2113 | \\ var f: c_int = @boolToInt((b != 0) and (c != null)); |
| 2095 | \\ var g: c_int = @boolToInt(((a != 0) and (c != null))); | 2114 | \\ var g: c_int = @boolToInt((a != 0) and (c != null)); |
| 2096 | \\ var h: c_int = @boolToInt(((a != 0) or (b != 0))); | 2115 | \\ var h: c_int = @boolToInt((a != 0) or (b != 0)); |
| 2097 | \\ var i: c_int = @boolToInt(((b != 0) or (c != null))); | 2116 | \\ var i: c_int = @boolToInt((b != 0) or (c != null)); |
| 2098 | \\ var j: c_int = @boolToInt(((a != 0) or (c != null))); | 2117 | \\ var j: c_int = @boolToInt((a != 0) or (c != null)); |
| 2099 | \\ var k: c_int = @boolToInt(((a != 0) or (@bitCast(c_int, @enumToInt(d)) != 0))); | 2118 | \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, @enumToInt(d)) != 0)); |
| 2100 | \\ var l: c_int = @boolToInt(((@bitCast(c_int, @enumToInt(d)) != 0) and (b != 0))); | 2119 | \\ var l: c_int = @boolToInt((@bitCast(c_int, @enumToInt(d)) != 0) and (b != 0)); |
| 2101 | \\ var m: c_int = @boolToInt(((c != null) or (@bitCast(c_uint, @enumToInt(d)) != 0))); | 2120 | \\ var m: c_int = @boolToInt((c != null) or (@bitCast(c_uint, @enumToInt(d)) != 0)); |
| 2102 | \\ var td: SomeTypedef = 44; | 2121 | \\ var td: SomeTypedef = 44; |
| 2103 | \\ var o: c_int = @boolToInt(((td != 0) or (b != 0))); | 2122 | \\ var o: c_int = @boolToInt((td != 0) or (b != 0)); |
| 2104 | \\ var p: c_int = @boolToInt(((c != null) and (td != 0))); | 2123 | \\ var p: c_int = @boolToInt((c != null) and (td != 0)); |
| 2105 | \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p); | 2124 | \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; |
| 2106 | \\} | 2125 | \\} |
| 2107 | , | 2126 | , |
| 2108 | \\pub const Foo = enum_Foo; | 2127 | \\pub const Foo = enum_Foo; |
| ... | @@ -2143,7 +2162,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2143,7 +2162,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2143 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { | 2162 | \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { |
| 2144 | \\ var a = arg_a; | 2163 | \\ var a = arg_a; |
| 2145 | \\ var b = arg_b; | 2164 | \\ var b = arg_b; |
| 2146 | \\ return ((a & b) ^ (a | b)); | 2165 | \\ return (a & b) ^ (a | b); |
| 2147 | \\} | 2166 | \\} |
| 2148 | }); | 2167 | }); |
| 2149 | | 2168 | |
| ... | @@ -2162,13 +2181,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2162,13 +2181,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2162 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { | 2181 | \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { |
| 2163 | \\ var a = arg_a; | 2182 | \\ var a = arg_a; |
| 2164 | \\ var b = arg_b; | 2183 | \\ var b = arg_b; |
| 2165 | \\ var c: c_int = @boolToInt((a < b)); | 2184 | \\ var c: c_int = @boolToInt(a < b); |
| 2166 | \\ var d: c_int = @boolToInt((a > b)); | 2185 | \\ var d: c_int = @boolToInt(a > b); |
| 2167 | \\ var e: c_int = @boolToInt((a <= b)); | 2186 | \\ var e: c_int = @boolToInt(a <= b); |
| 2168 | \\ var f: c_int = @boolToInt((a >= b)); | 2187 | \\ var f: c_int = @boolToInt(a >= b); |
| 2169 | \\ var g: c_int = @boolToInt((c < d)); | 2188 | \\ var g: c_int = @boolToInt(c < d); |
| 2170 | \\ var h: c_int = @boolToInt((e < f)); | 2189 | \\ var h: c_int = @boolToInt(e < f); |
| 2171 | \\ var i: c_int = @boolToInt((g < h)); | 2190 | \\ var i: c_int = @boolToInt(g < h); |
| 2172 | \\ return i; | 2191 | \\ return i; |
| 2173 | \\} | 2192 | \\} |
| 2174 | }); | 2193 | }); |
| ... | @@ -2215,11 +2234,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2215,11 +2234,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2215 | \\} | 2234 | \\} |
| 2216 | , &[_][]const u8{ | 2235 | , &[_][]const u8{ |
| 2217 | \\pub export fn foo() c_int { | 2236 | \\pub export fn foo() c_int { |
| 2218 | \\ return (blk: { | 2237 | \\ return blk: { |
| 2219 | \\ var a: c_int = 1; | 2238 | \\ var a: c_int = 1; |
| 2220 | \\ _ = a; | 2239 | \\ _ = a; |
| 2221 | \\ break :blk a; | 2240 | \\ break :blk a; |
| 2222 | \\ }); | 2241 | \\ }; |
| 2223 | \\} | 2242 | \\} |
| 2224 | }); | 2243 | }); |
| 2225 | | 2244 | |
| ... | @@ -2371,9 +2390,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2371,9 +2390,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2371 | \\ var a: c_int = 2; | 2390 | \\ var a: c_int = 2; |
| 2372 | \\ } | 2391 | \\ } |
| 2373 | \\ if ((blk: { | 2392 | \\ if ((blk: { |
| 2374 | \\ _ = @as(c_int, 2); | 2393 | \\ _ = @as(c_int, 2); |
| 2375 | \\ break :blk @as(c_int, 5); | 2394 | \\ break :blk @as(c_int, 5); |
| 2376 | \\ }) != 0) { | 2395 | \\ }) != 0) { |
| 2377 | \\ var a: c_int = 2; | 2396 | \\ var a: c_int = 2; |
| 2378 | \\ } | 2397 | \\ } |
| 2379 | \\} | 2398 | \\} |
| ... | @@ -2484,10 +2503,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2484,10 +2503,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2484 | \\ var f: ?fn () callconv(.C) void = foo; | 2503 | \\ var f: ?fn () callconv(.C) void = foo; |
| 2485 | \\ var b: ?fn () callconv(.C) c_int = baz; | 2504 | \\ var b: ?fn () callconv(.C) c_int = baz; |
| 2486 | \\ f.?(); | 2505 | \\ f.?(); |
| 2487 | \\ (f).?(); | 2506 | \\ f.?(); |
| 2488 | \\ foo(); | 2507 | \\ foo(); |
| 2489 | \\ _ = b.?(); | 2508 | \\ _ = b.?(); |
| 2490 | \\ _ = (b).?(); | 2509 | \\ _ = b.?(); |
| 2491 | \\ _ = baz(); | 2510 | \\ _ = baz(); |
| 2492 | \\} | 2511 | \\} |
| 2493 | }); | 2512 | }); |
| ... | @@ -2513,26 +2532,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2513,26 +2532,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2513 | \\ i -= 1; | 2532 | \\ i -= 1; |
| 2514 | \\ u +%= 1; | 2533 | \\ u +%= 1; |
| 2515 | \\ u -%= 1; | 2534 | \\ u -%= 1; |
| 2516 | \\ i = (blk: { | 2535 | \\ i = blk: { |
| 2517 | \\ const ref = &i; | 2536 | \\ const ref = &i; |
| 2518 | \\ ref.* += 1; | 2537 | \\ ref.* += 1; |
| 2519 | \\ break :blk ref.*; | 2538 | \\ break :blk ref.*; |
| 2520 | \\ }); | 2539 | \\ }; |
| 2521 | \\ i = (blk: { | 2540 | \\ i = blk: { |
| 2522 | \\ const ref = &i; | 2541 | \\ const ref = &i; |
| 2523 | \\ ref.* -= 1; | 2542 | \\ ref.* -= 1; |
| 2524 | \\ break :blk ref.*; | 2543 | \\ break :blk ref.*; |
| 2525 | \\ }); | 2544 | \\ }; |
| 2526 | \\ u = (blk: { | 2545 | \\ u = blk: { |
| 2527 | \\ const ref = &u; | 2546 | \\ const ref = &u; |
| 2528 | \\ ref.* +%= 1; | 2547 | \\ ref.* +%= 1; |
| 2529 | \\ break :blk ref.*; | 2548 | \\ break :blk ref.*; |
| 2530 | \\ }); | 2549 | \\ }; |
| 2531 | \\ u = (blk: { | 2550 | \\ u = blk: { |
| 2532 | \\ const ref = &u; | 2551 | \\ const ref = &u; |
| 2533 | \\ ref.* -%= 1; | 2552 | \\ ref.* -%= 1; |
| 2534 | \\ break :blk ref.*; | 2553 | \\ break :blk ref.*; |
| 2535 | \\ }); | 2554 | \\ }; |
| 2536 | \\} | 2555 | \\} |
| 2537 | }); | 2556 | }); |
| 2538 | | 2557 | |
| ... | @@ -2596,66 +2615,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2596,66 +2615,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2596 | \\pub export fn foo() void { | 2615 | \\pub export fn foo() void { |
| 2597 | \\ var a: c_int = 0; | 2616 | \\ var a: c_int = 0; |
| 2598 | \\ var b: c_uint = @bitCast(c_uint, @as(c_int, 0)); | 2617 | \\ var b: c_uint = @bitCast(c_uint, @as(c_int, 0)); |
| 2599 | \\ a += (blk: { | 2618 | \\ a += blk: { |
| 2600 | \\ const ref = &a; | 2619 | \\ const ref = &a; |
| 2601 | \\ ref.* = ref.* + @as(c_int, 1); | 2620 | \\ ref.* += @as(c_int, 1); |
| 2602 | \\ break :blk ref.*; | 2621 | \\ break :blk ref.*; |
| 2603 | \\ }); | 2622 | \\ }; |
| 2604 | \\ a -= (blk: { | 2623 | \\ a -= blk: { |
| 2605 | \\ const ref = &a; | 2624 | \\ const ref = &a; |
| 2606 | \\ ref.* = ref.* - @as(c_int, 1); | 2625 | \\ ref.* -= @as(c_int, 1); |
| 2607 | \\ break :blk ref.*; | 2626 | \\ break :blk ref.*; |
| 2608 | \\ }); | 2627 | \\ }; |
| 2609 | \\ a *= (blk: { | 2628 | \\ a *= blk: { |
| 2610 | \\ const ref = &a; | 2629 | \\ const ref = &a; |
| 2611 | \\ ref.* = ref.* * @as(c_int, 1); | 2630 | \\ ref.* *= @as(c_int, 1); |
| 2612 | \\ break :blk ref.*; | 2631 | \\ break :blk ref.*; |
| 2613 | \\ }); | 2632 | \\ }; |
| 2614 | \\ a &= (blk: { | 2633 | \\ a &= blk: { |
| 2615 | \\ const ref = &a; | 2634 | \\ const ref = &a; |
| 2616 | \\ ref.* = ref.* & @as(c_int, 1); | 2635 | \\ ref.* &= @as(c_int, 1); |
| 2617 | \\ break :blk ref.*; | 2636 | \\ break :blk ref.*; |
| 2618 | \\ }); | 2637 | \\ }; |
| 2619 | \\ a |= (blk: { | 2638 | \\ a |= blk: { |
| 2620 | \\ const ref = &a; | 2639 | \\ const ref = &a; |
| 2621 | \\ ref.* = ref.* | @as(c_int, 1); | 2640 | \\ ref.* |= @as(c_int, 1); |
| 2622 | \\ break :blk ref.*; | 2641 | \\ break :blk ref.*; |
| 2623 | \\ }); | 2642 | \\ }; |
| 2624 | \\ a ^= (blk: { | 2643 | \\ a ^= blk: { |
| 2625 | \\ const ref = &a; | 2644 | \\ const ref = &a; |
| 2626 | \\ ref.* = ref.* ^ @as(c_int, 1); | 2645 | \\ ref.* ^= @as(c_int, 1); |
| 2627 | \\ break :blk ref.*; | 2646 | \\ break :blk ref.*; |
| 2628 | \\ }); | 2647 | \\ }; |
| 2629 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), (blk: { | 2648 | \\ a >>= @intCast(@import("std").math.Log2Int(c_int), blk: { |
| 2630 | \\ const ref = &a; | 2649 | \\ const ref = &a; |
| 2631 | \\ ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2650 | \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2632 | \\ break :blk ref.*; | 2651 | \\ break :blk ref.*; |
| 2633 | \\ })); | 2652 | \\ }); |
| 2634 | \\ a <<= @intCast(@import("std").math.Log2Int(c_int), (blk: { | 2653 | \\ a <<= @intCast(@import("std").math.Log2Int(c_int), blk: { |
| 2635 | \\ const ref = &a; | 2654 | \\ const ref = &a; |
| 2636 | \\ ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2655 | \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2637 | \\ break :blk ref.*; | 2656 | \\ break :blk ref.*; |
| 2638 | \\ })); | 2657 | \\ }); |
| 2639 | \\ a = @divTrunc(a, (blk: { | 2658 | \\ a = @divTrunc(a, blk: { |
| 2640 | \\ const ref = &a; | 2659 | \\ const ref = &a; |
| 2641 | \\ ref.* = @divTrunc(ref.*, @as(c_int, 1)); | 2660 | \\ ref.* = @divTrunc(ref.*, @as(c_int, 1)); |
| 2642 | \\ break :blk ref.*; | 2661 | \\ break :blk ref.*; |
| 2643 | \\ })); | 2662 | \\ }); |
| 2644 | \\ a = @rem(a, (blk: { | 2663 | \\ a = @rem(a, blk: { |
| 2645 | \\ const ref = &a; | 2664 | \\ const ref = &a; |
| 2646 | \\ ref.* = @rem(ref.*, @as(c_int, 1)); | 2665 | \\ ref.* = @rem(ref.*, @as(c_int, 1)); |
| 2647 | \\ break :blk ref.*; | 2666 | \\ break :blk ref.*; |
| 2648 | \\ })); | 2667 | \\ }); |
| 2649 | \\ b /= (blk: { | 2668 | \\ b /= blk: { |
| 2650 | \\ const ref = &b; | 2669 | \\ const ref = &b; |
| 2651 | \\ ref.* = ref.* / @bitCast(c_uint, @as(c_int, 1)); | 2670 | \\ ref.* /= @bitCast(c_uint, @as(c_int, 1)); |
| 2652 | \\ break :blk ref.*; | 2671 | \\ break :blk ref.*; |
| 2653 | \\ }); | 2672 | \\ }; |
| 2654 | \\ b %= (blk: { | 2673 | \\ b %= blk: { |
| 2655 | \\ const ref = &b; | 2674 | \\ const ref = &b; |
| 2656 | \\ ref.* = ref.* % @bitCast(c_uint, @as(c_int, 1)); | 2675 | \\ ref.* %= @bitCast(c_uint, @as(c_int, 1)); |
| 2657 | \\ break :blk ref.*; | 2676 | \\ break :blk ref.*; |
| 2658 | \\ }); | 2677 | \\ }; |
| 2659 | \\} | 2678 | \\} |
| 2660 | }); | 2679 | }); |
| 2661 | | 2680 | |
| ... | @@ -2674,46 +2693,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2674,46 +2693,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2674 | , &[_][]const u8{ | 2693 | , &[_][]const u8{ |
| 2675 | \\pub export fn foo() void { | 2694 | \\pub export fn foo() void { |
| 2676 | \\ var a: c_uint = @bitCast(c_uint, @as(c_int, 0)); | 2695 | \\ var a: c_uint = @bitCast(c_uint, @as(c_int, 0)); |
| 2677 | \\ a +%= (blk: { | 2696 | \\ a +%= blk: { |
| 2678 | \\ const ref = &a; | 2697 | \\ const ref = &a; |
| 2679 | \\ ref.* = ref.* +% @bitCast(c_uint, @as(c_int, 1)); | 2698 | \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1)); |
| 2680 | \\ break :blk ref.*; | 2699 | \\ break :blk ref.*; |
| 2681 | \\ }); | 2700 | \\ }; |
| 2682 | \\ a -%= (blk: { | 2701 | \\ a -%= blk: { |
| 2683 | \\ const ref = &a; | 2702 | \\ const ref = &a; |
| 2684 | \\ ref.* = ref.* -% @bitCast(c_uint, @as(c_int, 1)); | 2703 | \\ ref.* -%= @bitCast(c_uint, @as(c_int, 1)); |
| 2685 | \\ break :blk ref.*; | 2704 | \\ break :blk ref.*; |
| 2686 | \\ }); | 2705 | \\ }; |
| 2687 | \\ a *%= (blk: { | 2706 | \\ a *%= blk: { |
| 2688 | \\ const ref = &a; | 2707 | \\ const ref = &a; |
| 2689 | \\ ref.* = ref.* *% @bitCast(c_uint, @as(c_int, 1)); | 2708 | \\ ref.* *%= @bitCast(c_uint, @as(c_int, 1)); |
| 2690 | \\ break :blk ref.*; | 2709 | \\ break :blk ref.*; |
| 2691 | \\ }); | 2710 | \\ }; |
| 2692 | \\ a &= (blk: { | 2711 | \\ a &= blk: { |
| 2693 | \\ const ref = &a; | 2712 | \\ const ref = &a; |
| 2694 | \\ ref.* = ref.* & @bitCast(c_uint, @as(c_int, 1)); | 2713 | \\ ref.* &= @bitCast(c_uint, @as(c_int, 1)); |
| 2695 | \\ break :blk ref.*; | 2714 | \\ break :blk ref.*; |
| 2696 | \\ }); | 2715 | \\ }; |
| 2697 | \\ a |= (blk: { | 2716 | \\ a |= blk: { |
| 2698 | \\ const ref = &a; | 2717 | \\ const ref = &a; |
| 2699 | \\ ref.* = ref.* | @bitCast(c_uint, @as(c_int, 1)); | 2718 | \\ ref.* |= @bitCast(c_uint, @as(c_int, 1)); |
| 2700 | \\ break :blk ref.*; | 2719 | \\ break :blk ref.*; |
| 2701 | \\ }); | 2720 | \\ }; |
| 2702 | \\ a ^= (blk: { | 2721 | \\ a ^= blk: { |
| 2703 | \\ const ref = &a; | 2722 | \\ const ref = &a; |
| 2704 | \\ ref.* = ref.* ^ @bitCast(c_uint, @as(c_int, 1)); | 2723 | \\ ref.* ^= @bitCast(c_uint, @as(c_int, 1)); |
| 2705 | \\ break :blk ref.*; | 2724 | \\ break :blk ref.*; |
| 2706 | \\ }); | 2725 | \\ }; |
| 2707 | \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), (blk: { | 2726 | \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), blk: { |
| 2708 | \\ const ref = &a; | 2727 | \\ const ref = &a; |
| 2709 | \\ ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2728 | \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2710 | \\ break :blk ref.*; | 2729 | \\ break :blk ref.*; |
| 2711 | \\ })); | 2730 | \\ }); |
| 2712 | \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), (blk: { | 2731 | \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), blk: { |
| 2713 | \\ const ref = &a; | 2732 | \\ const ref = &a; |
| 2714 | \\ ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); | 2733 | \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); |
| 2715 | \\ break :blk ref.*; | 2734 | \\ break :blk ref.*; |
| 2716 | \\ })); | 2735 | \\ }); |
| 2717 | \\} | 2736 | \\} |
| 2718 | }); | 2737 | }); |
| 2719 | | 2738 | |
| ... | @@ -2738,30 +2757,30 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2738,30 +2757,30 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2738 | \\ i -= 1; | 2757 | \\ i -= 1; |
| 2739 | \\ u +%= 1; | 2758 | \\ u +%= 1; |
| 2740 | \\ u -%= 1; | 2759 | \\ u -%= 1; |
| 2741 | \\ i = (blk: { | 2760 | \\ i = blk: { |
| 2742 | \\ const ref = &i; | 2761 | \\ const ref = &i; |
| 2743 | \\ const tmp = ref.*; | 2762 | \\ const tmp = ref.*; |
| 2744 | \\ ref.* += 1; | 2763 | \\ ref.* += 1; |
| 2745 | \\ break :blk tmp; | 2764 | \\ break :blk tmp; |
| 2746 | \\ }); | 2765 | \\ }; |
| 2747 | \\ i = (blk: { | 2766 | \\ i = blk: { |
| 2748 | \\ const ref = &i; | 2767 | \\ const ref = &i; |
| 2749 | \\ const tmp = ref.*; | 2768 | \\ const tmp = ref.*; |
| 2750 | \\ ref.* -= 1; | 2769 | \\ ref.* -= 1; |
| 2751 | \\ break :blk tmp; | 2770 | \\ break :blk tmp; |
| 2752 | \\ }); | 2771 | \\ }; |
| 2753 | \\ u = (blk: { | 2772 | \\ u = blk: { |
| 2754 | \\ const ref = &u; | 2773 | \\ const ref = &u; |
| 2755 | \\ const tmp = ref.*; | 2774 | \\ const tmp = ref.*; |
| 2756 | \\ ref.* +%= 1; | 2775 | \\ ref.* +%= 1; |
| 2757 | \\ break :blk tmp; | 2776 | \\ break :blk tmp; |
| 2758 | \\ }); | 2777 | \\ }; |
| 2759 | \\ u = (blk: { | 2778 | \\ u = blk: { |
| 2760 | \\ const ref = &u; | 2779 | \\ const ref = &u; |
| 2761 | \\ const tmp = ref.*; | 2780 | \\ const tmp = ref.*; |
| 2762 | \\ ref.* -%= 1; | 2781 | \\ ref.* -%= 1; |
| 2763 | \\ break :blk tmp; | 2782 | \\ break :blk tmp; |
| 2764 | \\ }); | 2783 | \\ }; |
| 2765 | \\} | 2784 | \\} |
| 2766 | }); | 2785 | }); |
| 2767 | | 2786 | |
| ... | @@ -2872,13 +2891,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2872,13 +2891,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2872 | \\#define BAR (void*) a | 2891 | \\#define BAR (void*) a |
| 2873 | \\#define BAZ (uint32_t)(2) | 2892 | \\#define BAZ (uint32_t)(2) |
| 2874 | , &[_][]const u8{ | 2893 | , &[_][]const u8{ |
| 2875 | \\pub fn FOO(bar: anytype) callconv(.Inline) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) { | 2894 | \\pub fn FOO(bar: anytype) callconv(.Inline) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) { |
| 2876 | \\ return baz((@import("std").meta.cast(?*c_void, baz))); | 2895 | \\ return baz(@import("std").meta.cast(?*c_void, baz)); |
| 2877 | \\} | 2896 | \\} |
| 2878 | , | 2897 | , |
| 2879 | \\pub const BAR = (@import("std").meta.cast(?*c_void, a)); | 2898 | \\pub const BAR = @import("std").meta.cast(?*c_void, a); |
| 2880 | , | 2899 | , |
| 2881 | \\pub const BAZ = (@import("std").meta.cast(u32, 2)); | 2900 | \\pub const BAZ = @import("std").meta.cast(u32, 2); |
| 2882 | }); | 2901 | }); |
| 2883 | | 2902 | |
| 2884 | cases.add("macro with cast to unsigned short, long, and long long", | 2903 | cases.add("macro with cast to unsigned short, long, and long long", |
| ... | @@ -2886,9 +2905,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2886,9 +2905,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2886 | \\#define CURLAUTH_BASIC ((unsigned long) 1) | 2905 | \\#define CURLAUTH_BASIC ((unsigned long) 1) |
| 2887 | \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1) | 2906 | \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1) |
| 2888 | , &[_][]const u8{ | 2907 | , &[_][]const u8{ |
| 2889 | \\pub const CURLAUTH_BASIC_BUT_USHORT = (@import("std").meta.cast(c_ushort, 1)); | 2908 | \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, 1); |
| 2890 | \\pub const CURLAUTH_BASIC = (@import("std").meta.cast(c_ulong, 1)); | 2909 | \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, 1); |
| 2891 | \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = (@import("std").meta.cast(c_ulonglong, 1)); | 2910 | \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, 1); |
| 2892 | }); | 2911 | }); |
| 2893 | | 2912 | |
| 2894 | cases.add("macro conditional operator", | 2913 | cases.add("macro conditional operator", |
| ... | @@ -2905,7 +2924,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2905,7 +2924,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2905 | , &[_][]const u8{ | 2924 | , &[_][]const u8{ |
| 2906 | \\pub fn foo() callconv(.C) void { | 2925 | \\pub fn foo() callconv(.C) void { |
| 2907 | \\ if (true) while (true) { | 2926 | \\ if (true) while (true) { |
| 2908 | \\ if (!false) break; | 2927 | \\ break; |
| 2909 | \\ }; | 2928 | \\ }; |
| 2910 | \\} | 2929 | \\} |
| 2911 | }); | 2930 | }); |
| ... | @@ -2923,27 +2942,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2923,27 +2942,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2923 | \\} | 2942 | \\} |
| 2924 | }); | 2943 | }); |
| 2925 | | 2944 | |
| 2926 | // TODO: detect to use different block labels here | 2945 | // TODO fix zig fmt here |
| 2927 | cases.add("nested assignment", | 2946 | // cases.add("nested assignment", |
| 2928 | \\int foo(int *p, int x) { | 2947 | // \\int foo(int *p, int x) { |
| 2929 | \\ return *p++ = x; | 2948 | // \\ return *p++ = x; |
| 2930 | \\} | 2949 | // \\} |
| 2931 | , &[_][]const u8{ | 2950 | // , &[_][]const u8{ |
| 2932 | \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { | 2951 | // \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { |
| 2933 | \\ var p = arg_p; | 2952 | // \\ var p = arg_p; |
| 2934 | \\ var x = arg_x; | 2953 | // \\ var x = arg_x; |
| 2935 | \\ return blk: { | 2954 | // \\ return blk: { |
| 2936 | \\ const tmp = x; | 2955 | // \\ const tmp = x; |
| 2937 | \\ (blk_1: { | 2956 | // \\ (blk_1: { |
| 2938 | \\ const ref = &p; | 2957 | // \\ const ref = &p; |
| 2939 | \\ const tmp_2 = ref.*; | 2958 | // \\ const tmp_2 = ref.*; |
| 2940 | \\ ref.* += 1; | 2959 | // \\ ref.* += 1; |
| 2941 | \\ break :blk_1 tmp_2; | 2960 | // \\ break :blk_1 tmp_2; |
| 2942 | \\ }).?.* = tmp; | 2961 | // \\ }).?.* = tmp; |
| 2943 | \\ break :blk tmp; | 2962 | // \\ break :blk tmp; |
| 2944 | \\ }; | 2963 | // \\ }; |
| 2945 | \\} | 2964 | // \\} |
| 2946 | }); | 2965 | // }); |
| 2947 | | 2966 | |
| 2948 | cases.add("widening and truncating integer casting to different signedness", | 2967 | cases.add("widening and truncating integer casting to different signedness", |
| 2949 | \\unsigned long foo(void) { | 2968 | \\unsigned long foo(void) { |
| ... | @@ -3033,10 +3052,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3033,10 +3052,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3033 | , &[_][]const u8{ | 3052 | , &[_][]const u8{ |
| 3034 | \\pub export fn foo(arg_x: bool) bool { | 3053 | \\pub export fn foo(arg_x: bool) bool { |
| 3035 | \\ var x = arg_x; | 3054 | \\ var x = arg_x; |
| 3036 | \\ var a: bool = (@as(c_int, @boolToInt(x)) != @as(c_int, 1)); | 3055 | \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1); |
| 3037 | \\ var b: bool = (@as(c_int, @boolToInt(a)) != @as(c_int, 0)); | 3056 | \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0); |
| 3038 | \\ var c: bool = @ptrToInt(foo) != 0; | 3057 | \\ var c: bool = @ptrToInt(foo) != 0; |
| 3039 | \\ return foo((@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b)))); | 3058 | \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b))); |
| 3040 | \\} | 3059 | \\} |
| 3041 | }); | 3060 | }); |
| 3042 | | 3061 | |
| ... | @@ -3106,8 +3125,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3106,8 +3125,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3106 | \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) | 3125 | \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) |
| 3107 | \\ | 3126 | \\ |
| 3108 | , &[_][]const u8{ | 3127 | , &[_][]const u8{ |
| 3109 | \\pub fn DefaultScreen(dpy: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen) { | 3128 | \\pub fn DefaultScreen(dpy: anytype) callconv(.Inline) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) { |
| 3110 | \\ return (@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen; | 3129 | \\ return @import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen; |
| 3111 | \\} | 3130 | \\} |
| 3112 | }); | 3131 | }); |
| 3113 | | 3132 | |
| ... | @@ -3115,9 +3134,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3115,9 +3134,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3115 | \\#define NULL ((void*)0) | 3134 | \\#define NULL ((void*)0) |
| 3116 | \\#define FOO ((int)0x8000) | 3135 | \\#define FOO ((int)0x8000) |
| 3117 | , &[_][]const u8{ | 3136 | , &[_][]const u8{ |
| 3118 | \\pub const NULL = (@import("std").meta.cast(?*c_void, 0)); | 3137 | \\pub const NULL = @import("std").meta.cast(?*c_void, 0); |
| 3119 | , | 3138 | , |
| 3120 | \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000)); | 3139 | \\pub const FOO = @import("std").meta.cast(c_int, 0x8000); |
| 3121 | }); | 3140 | }); |
| 3122 | | 3141 | |
| 3123 | if (std.Target.current.abi == .msvc) { | 3142 | if (std.Target.current.abi == .msvc) { |