| ... | @@ -3,6 +3,26 @@ const std = @import("std"); | ... | @@ -3,6 +3,26 @@ 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("pointer to opaque demoted struct", |
| | 7 | \\typedef struct { |
| | 8 | \\ _Atomic int foo; |
| | 9 | \\} Foo; |
| | 10 | \\ |
| | 11 | \\typedef struct { |
| | 12 | \\ Foo *bar; |
| | 13 | \\} Bar; |
| | 14 | , &[_][]const u8{ |
| | 15 | \\const struct_unnamed_1 = // |
| | 16 | , |
| | 17 | \\warning: unsupported type: 'Atomic' |
| | 18 | \\ opaque {}; // |
| | 19 | , |
| | 20 | \\pub const Foo = struct_unnamed_1; |
| | 21 | \\const struct_unnamed_2 = extern struct { |
| | 22 | \\ bar: ?*Foo, |
| | 23 | \\}; |
| | 24 | }); |
| | 25 | |
| 6 | cases.add("macro expressions respect C operator precedence", | 26 | cases.add("macro expressions respect C operator precedence", |
| 7 | \\#define FOO *((foo) + 2) | 27 | \\#define FOO *((foo) + 2) |
| 8 | \\#define VALUE (1 + 2 * 3 + 4 * 5 + 6 << 7 | 8 == 9) | 28 | \\#define VALUE (1 + 2 * 3 + 4 * 5 + 6 << 7 | 8 == 9) |
| ... | @@ -11,9 +31,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -11,9 +31,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 11 | \\ | (*((unsigned char *)(p) + 2) << 16)) | 31 | \\ | (*((unsigned char *)(p) + 2) << 16)) |
| 12 | , &[_][]const u8{ | 32 | , &[_][]const u8{ |
| 13 | \\pub const FOO = (foo + 2).*; | 33 | \\pub const FOO = (foo + 2).*; |
| 14 | , | 34 | , |
| 15 | \\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); |
| 16 | , | 36 | , |
| 17 | \\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)) { |
| 18 | \\ 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); |
| 19 | \\} | 39 | \\} |
| ... | @@ -81,11 +101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -81,11 +101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 81 | \\ a: u8, | 101 | \\ a: u8, |
| 82 | \\}; | 102 | \\}; |
| 83 | \\pub const Color = struct_Color; | 103 | \\pub const Color = struct_Color; |
| 84 | , | 104 | , |
| 85 | \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) { | 105 | \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) { |
| 86 | \\ return type_1; | 106 | \\ return type_1; |
| 87 | \\} | 107 | \\} |
| 88 | , | 108 | , |
| 89 | \\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 }); |
| 90 | }); | 110 | }); |
| 91 | | 111 | |
| ... | @@ -119,7 +139,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -119,7 +139,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 119 | \\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)) { |
| 120 | \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0); | 140 | \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0); |
| 121 | \\} | 141 | \\} |
| 122 | , | 142 | , |
| 123 | \\pub const BAR = (1 != 0) and (2 > 4); | 143 | \\pub const BAR = (1 != 0) and (2 > 4); |
| 124 | }); | 144 | }); |
| 125 | | 145 | |
| ... | @@ -138,7 +158,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -138,7 +158,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 138 | \\struct bar { int x; int y[0]; }; | 158 | \\struct bar { int x; int y[0]; }; |
| 139 | , &[_][]const u8{ | 159 | , &[_][]const u8{ |
| 140 | \\pub const struct_foo = opaque {}; | 160 | \\pub const struct_foo = opaque {}; |
| 141 | , | 161 | , |
| 142 | \\pub const struct_bar = opaque {}; | 162 | \\pub const struct_bar = opaque {}; |
| 143 | }); | 163 | }); |
| 144 | | 164 | |
| ... | @@ -166,7 +186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -166,7 +186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 166 | \\ _ = foo; | 186 | \\ _ = foo; |
| 167 | \\ break :blk bar; | 187 | \\ break :blk bar; |
| 168 | \\}; | 188 | \\}; |
| 169 | , | 189 | , |
| 170 | \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) { | 190 | \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) { |
| 171 | \\ return blk: { | 191 | \\ return blk: { |
| 172 | \\ _ = &x; | 192 | \\ _ = &x; |
| ... | @@ -185,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -185,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 185 | \\#define inline 2 | 205 | \\#define inline 2 |
| 186 | , &[_][]const u8{ | 206 | , &[_][]const u8{ |
| 187 | \\pub const foo = 1; | 207 | \\pub const foo = 1; |
| 188 | , | 208 | , |
| 189 | \\pub const @"inline" = 2; | 209 | \\pub const @"inline" = 2; |
| 190 | }); | 210 | }); |
| 191 | | 211 | |
| ... | @@ -205,12 +225,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -205,12 +225,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 205 | \\}; | 225 | \\}; |
| 206 | , &[_][]const u8{ | 226 | , &[_][]const u8{ |
| 207 | \\pub const struct_arcan_shmif_page = // | 227 | \\pub const struct_arcan_shmif_page = // |
| 208 | , | 228 | , |
| 209 | \\warning: unsupported type: 'Atomic' | 229 | \\warning: unsupported type: 'Atomic' |
| 210 | \\ opaque {}; // | 230 | \\ opaque {}; // |
| 211 | , | 231 | , |
| 212 | \\ warning: struct demoted to opaque type - unable to translate type of field abufused | 232 | \\ warning: struct demoted to opaque type - unable to translate type of field abufused |
| 213 | , // TODO should be `addr: *struct_arcan_shmif_page` | 233 | , // TODO should be `addr: *struct_arcan_shmif_page` |
| 214 | \\pub const struct_arcan_shmif_cont = extern struct { | 234 | \\pub const struct_arcan_shmif_cont = extern struct { |
| 215 | \\ addr: [*c]struct_arcan_shmif_page, | 235 | \\ addr: [*c]struct_arcan_shmif_page, |
| 216 | \\}; | 236 | \\}; |
| ... | @@ -529,7 +549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -529,7 +549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 529 | \\Foo fun(Foo *a); | 549 | \\Foo fun(Foo *a); |
| 530 | , &[_][]const u8{ | 550 | , &[_][]const u8{ |
| 531 | \\pub const Foo = c_void; | 551 | \\pub const Foo = c_void; |
| 532 | , | 552 | , |
| 533 | \\pub extern fn fun(a: ?*Foo) Foo; | 553 | \\pub extern fn fun(a: ?*Foo) Foo; |
| 534 | }); | 554 | }); |
| 535 | | 555 | |
| ... | @@ -629,7 +649,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -629,7 +649,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 629 | \\}; | 649 | \\}; |
| 630 | , &[_][]const u8{ | 650 | , &[_][]const u8{ |
| 631 | \\pub const struct_Foo = opaque {}; | 651 | \\pub const struct_Foo = opaque {}; |
| 632 | , | 652 | , |
| 633 | \\pub const struct_Bar = extern struct { | 653 | \\pub const struct_Bar = extern struct { |
| 634 | \\ foo: ?*struct_Foo, | 654 | \\ foo: ?*struct_Foo, |
| 635 | \\}; | 655 | \\}; |
| ... | @@ -646,7 +666,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -646,7 +666,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 646 | \\#define FLASH_BANK_SIZE (FLASH_SIZE >> 1) /* 1 MB */ | 666 | \\#define FLASH_BANK_SIZE (FLASH_SIZE >> 1) /* 1 MB */ |
| 647 | , &[_][]const u8{ | 667 | , &[_][]const u8{ |
| 648 | \\pub const FLASH_SIZE = @as(c_ulong, 0x200000); | 668 | \\pub const FLASH_SIZE = @as(c_ulong, 0x200000); |
| 649 | , | 669 | , |
| 650 | \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1; | 670 | \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1; |
| 651 | }); | 671 | }); |
| 652 | | 672 | |
| ... | @@ -665,13 +685,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -665,13 +685,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 665 | \\pub const struct_Foo = extern struct { | 685 | \\pub const struct_Foo = extern struct { |
| 666 | \\ a: [*c]Foo, | 686 | \\ a: [*c]Foo, |
| 667 | \\}; | 687 | \\}; |
| 668 | , | 688 | , |
| 669 | \\pub const Foo = struct_Foo; | 689 | \\pub const Foo = struct_Foo; |
| 670 | , | 690 | , |
| 671 | \\pub const struct_Bar = extern struct { | 691 | \\pub const struct_Bar = extern struct { |
| 672 | \\ a: [*c]Foo, | 692 | \\ a: [*c]Foo, |
| 673 | \\}; | 693 | \\}; |
| 674 | , | 694 | , |
| 675 | \\pub const Bar = struct_Bar; | 695 | \\pub const Bar = struct_Bar; |
| 676 | }); | 696 | }); |
| 677 | | 697 | |
| ... | @@ -685,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -685,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 685 | \\ x: c_int, | 705 | \\ x: c_int, |
| 686 | \\ y: [*c]u8, | 706 | \\ y: [*c]u8, |
| 687 | \\}; | 707 | \\}; |
| 688 | , | 708 | , |
| 689 | \\pub const Foo = struct_Foo; | 709 | \\pub const Foo = struct_Foo; |
| 690 | }); | 710 | }); |
| 691 | | 711 | |
| ... | @@ -697,7 +717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -697,7 +717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 697 | \\pub const struct_Foo = extern struct { | 717 | \\pub const struct_Foo = extern struct { |
| 698 | \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void, | 718 | \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void, |
| 699 | \\}; | 719 | \\}; |
| 700 | , | 720 | , |
| 701 | \\pub const Foo = struct_Foo; | 721 | \\pub const Foo = struct_Foo; |
| 702 | }); | 722 | }); |
| 703 | | 723 | |
| ... | @@ -706,9 +726,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -706,9 +726,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 706 | \\struct Foo *some_func(struct Foo *foo, int x); | 726 | \\struct Foo *some_func(struct Foo *foo, int x); |
| 707 | , &[_][]const u8{ | 727 | , &[_][]const u8{ |
| 708 | \\pub const struct_Foo = opaque {}; | 728 | \\pub const struct_Foo = opaque {}; |
| 709 | , | 729 | , |
| 710 | \\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; |
| 711 | , | 731 | , |
| 712 | \\pub const Foo = struct_Foo; | 732 | \\pub const Foo = struct_Foo; |
| 713 | }); | 733 | }); |
| 714 | | 734 | |
| ... | @@ -723,7 +743,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -723,7 +743,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 723 | \\#define THING1 1234 | 743 | \\#define THING1 1234 |
| 724 | , &[_][]const u8{ | 744 | , &[_][]const u8{ |
| 725 | \\pub const THING1 = 1234; | 745 | \\pub const THING1 = 1234; |
| 726 | , | 746 | , |
| 727 | \\pub const THING2 = THING1; | 747 | \\pub const THING2 = THING1; |
| 728 | }); | 748 | }); |
| 729 | | 749 | |
| ... | @@ -741,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -741,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 741 | \\pub const struct_Bar = extern struct { | 761 | \\pub const struct_Bar = extern struct { |
| 742 | \\ next: [*c]struct_Foo, | 762 | \\ next: [*c]struct_Foo, |
| 743 | \\}; | 763 | \\}; |
| 744 | , | 764 | , |
| 745 | \\pub const struct_Foo = extern struct { | 765 | \\pub const struct_Foo = extern struct { |
| 746 | \\ next: [*c]struct_Bar, | 766 | \\ next: [*c]struct_Bar, |
| 747 | \\}; | 767 | \\}; |
| ... | @@ -761,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -761,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 761 | \\pub const struct_comptime = extern struct { | 781 | \\pub const struct_comptime = extern struct { |
| 762 | \\ @"defer": c_int, | 782 | \\ @"defer": c_int, |
| 763 | \\}; | 783 | \\}; |
| 764 | , | 784 | , |
| 765 | \\pub const @"comptime" = struct_comptime; | 785 | \\pub const @"comptime" = struct_comptime; |
| 766 | }); | 786 | }); |
| 767 | | 787 | |
| ... | @@ -1003,7 +1023,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1003,7 +1023,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1003 | \\ x: c_int, | 1023 | \\ x: c_int, |
| 1004 | \\ y: f64, | 1024 | \\ y: f64, |
| 1005 | \\}; | 1025 | \\}; |
| 1006 | , | 1026 | , |
| 1007 | \\pub const Foo = union_Foo; | 1027 | \\pub const Foo = union_Foo; |
| 1008 | }); | 1028 | }); |
| 1009 | | 1029 | |
| ... | @@ -1446,7 +1466,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1446,7 +1466,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1446 | \\ p, | 1466 | \\ p, |
| 1447 | \\ _, | 1467 | \\ _, |
| 1448 | \\}; | 1468 | \\}; |
| 1449 | , | 1469 | , |
| 1450 | \\pub const Baz = struct_Baz; | 1470 | \\pub const Baz = struct_Baz; |
| 1451 | }); | 1471 | }); |
| 1452 | | 1472 | |
| ... | @@ -1512,13 +1532,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1512,13 +1532,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1512 | \\#define bar fn_ptr2 | 1532 | \\#define bar fn_ptr2 |
| 1513 | , &[_][]const u8{ | 1533 | , &[_][]const u8{ |
| 1514 | \\pub extern var fn_ptr: ?fn () callconv(.C) void; | 1534 | \\pub extern var fn_ptr: ?fn () callconv(.C) void; |
| 1515 | , | 1535 | , |
| 1516 | \\pub inline fn foo() void { | 1536 | \\pub inline fn foo() void { |
| 1517 | \\ return fn_ptr.?(); | 1537 | \\ return fn_ptr.?(); |
| 1518 | \\} | 1538 | \\} |
| 1519 | , | 1539 | , |
| 1520 | \\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; |
| 1521 | , | 1541 | , |
| 1522 | \\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 { |
| 1523 | \\ return fn_ptr2.?(arg_1, arg_2); | 1543 | \\ return fn_ptr2.?(arg_1, arg_2); |
| 1524 | \\} | 1544 | \\} |
| ... | @@ -1549,13 +1569,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1549,13 +1569,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1549 | \\ gl: struct_unnamed_1, | 1569 | \\ gl: struct_unnamed_1, |
| 1550 | \\}; | 1570 | \\}; |
| 1551 | \\pub extern var glProcs: union_OpenGLProcs; | 1571 | \\pub extern var glProcs: union_OpenGLProcs; |
| 1552 | , | 1572 | , |
| 1553 | \\pub const glClearPFN = PFNGLCLEARPROC; | 1573 | \\pub const glClearPFN = PFNGLCLEARPROC; |
| 1554 | , | 1574 | , |
| 1555 | \\pub inline fn glClearUnion(arg_2: GLbitfield) void { | 1575 | \\pub inline fn glClearUnion(arg_2: GLbitfield) void { |
| 1556 | \\ return glProcs.gl.Clear.?(arg_2); | 1576 | \\ return glProcs.gl.Clear.?(arg_2); |
| 1557 | \\} | 1577 | \\} |
| 1558 | , | 1578 | , |
| 1559 | \\pub const OpenGLProcs = union_OpenGLProcs; | 1579 | \\pub const OpenGLProcs = union_OpenGLProcs; |
| 1560 | }); | 1580 | }); |
| 1561 | | 1581 | |
| ... | @@ -1571,11 +1591,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1571,11 +1591,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1571 | \\#define FOO(L,b) (L + b) | 1591 | \\#define FOO(L,b) (L + b) |
| 1572 | , &[_][]const u8{ | 1592 | , &[_][]const u8{ |
| 1573 | \\pub extern var c: c_int; | 1593 | \\pub extern var c: c_int; |
| 1574 | , | 1594 | , |
| 1575 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) { | 1595 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) { |
| 1576 | \\ return c_1 * 2; | 1596 | \\ return c_1 * 2; |
| 1577 | \\} | 1597 | \\} |
| 1578 | , | 1598 | , |
| 1579 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { | 1599 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { |
| 1580 | \\ return L + b; | 1600 | \\ return L + b; |
| 1581 | \\} | 1601 | \\} |
| ... | @@ -1587,9 +1607,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1587,9 +1607,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1587 | \\#define FOO_CHAR '\xfF' | 1607 | \\#define FOO_CHAR '\xfF' |
| 1588 | , &[_][]const u8{ | 1608 | , &[_][]const u8{ |
| 1589 | \\pub const FOO = "aoeu\xab derp"; | 1609 | \\pub const FOO = "aoeu\xab derp"; |
| 1590 | , | 1610 | , |
| 1591 | \\pub const FOO2 = "aoeu\x7a derp"; | 1611 | \\pub const FOO2 = "aoeu\x7a derp"; |
| 1592 | , | 1612 | , |
| 1593 | \\pub const FOO_CHAR = '\xff'; | 1613 | \\pub const FOO_CHAR = '\xff'; |
| 1594 | }); | 1614 | }); |
| 1595 | | 1615 | |
| ... | @@ -1599,9 +1619,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1599,9 +1619,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1599 | \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL) | 1619 | \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL) |
| 1600 | , &[_][]const u8{ | 1620 | , &[_][]const u8{ |
| 1601 | \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000); | 1621 | \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000); |
| 1602 | , | 1622 | , |
| 1603 | \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000); | 1623 | \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000); |
| 1604 | , | 1624 | , |
| 1605 | \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400); | 1625 | \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400); |
| 1606 | }); | 1626 | }); |
| 1607 | | 1627 | |
| ... | @@ -1738,7 +1758,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1738,7 +1758,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1738 | , &[_][]const u8{ | 1758 | , &[_][]const u8{ |
| 1739 | \\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)); |
| 1740 | , | 1760 | , |
| 1741 | | | |
| 1742 | \\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"); |
| 1743 | }); | 1762 | }); |
| 1744 | | 1763 | |
| ... | @@ -2011,7 +2030,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2011,7 +2030,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2011 | \\ var p: c_int = @boolToInt(((c != null) and (td != 0))); | 2030 | \\ var p: c_int = @boolToInt(((c != null) and (td != 0))); |
| 2012 | \\ 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); |
| 2013 | \\} | 2032 | \\} |
| 2014 | , | 2033 | , |
| 2015 | \\pub const Foo = enum_Foo; | 2034 | \\pub const Foo = enum_Foo; |
| 2016 | }); | 2035 | }); |
| 2017 | | 2036 | |
| ... | @@ -2030,14 +2049,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2030,14 +2049,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2030 | \\ x: c_int, | 2049 | \\ x: c_int, |
| 2031 | \\ y: c_int, | 2050 | \\ y: c_int, |
| 2032 | \\}; | 2051 | \\}; |
| 2033 | , | 2052 | , |
| 2034 | \\pub const enum_Bar = extern enum(c_int) { | 2053 | \\pub const enum_Bar = extern enum(c_int) { |
| 2035 | \\ A, | 2054 | \\ A, |
| 2036 | \\ B, | 2055 | \\ B, |
| 2037 | \\ _, | 2056 | \\ _, |
| 2038 | \\}; | 2057 | \\}; |
| 2039 | \\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; |
| 2040 | , | 2059 | , |
| 2041 | \\pub const Foo = struct_Foo; | 2060 | \\pub const Foo = struct_Foo; |
| 2042 | \\pub const Bar = enum_Bar; | 2061 | \\pub const Bar = enum_Bar; |
| 2043 | }); | 2062 | }); |
| ... | @@ -2153,9 +2172,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2153,9 +2172,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2153 | \\ _ = a.b; | 2172 | \\ _ = a.b; |
| 2154 | \\ _ = c.*.b; | 2173 | \\ _ = c.*.b; |
| 2155 | \\} | 2174 | \\} |
| 2156 | , | 2175 | , |
| 2157 | \\pub const DOT = a.b; | 2176 | \\pub const DOT = a.b; |
| 2158 | , | 2177 | , |
| 2159 | \\pub const ARROW = a.*.b; | 2178 | \\pub const ARROW = a.*.b; |
| 2160 | }); | 2179 | }); |
| 2161 | | 2180 | |
| ... | @@ -2171,7 +2190,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2171,7 +2190,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2171 | \\ var index = arg_index; | 2190 | \\ var index = arg_index; |
| 2172 | \\ return array[@intCast(c_uint, index)]; | 2191 | \\ return array[@intCast(c_uint, index)]; |
| 2173 | \\} | 2192 | \\} |
| 2174 | , | 2193 | , |
| 2175 | \\pub const ACCESS = array[2]; | 2194 | \\pub const ACCESS = array[2]; |
| 2176 | }); | 2195 | }); |
| 2177 | | 2196 | |
| ... | @@ -2748,9 +2767,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2748,9 +2767,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2748 | \\#define FOO_CHAR '\077' | 2767 | \\#define FOO_CHAR '\077' |
| 2749 | , &[_][]const u8{ | 2768 | , &[_][]const u8{ |
| 2750 | \\pub const FOO = "aoeu\x13 derp"; | 2769 | \\pub const FOO = "aoeu\x13 derp"; |
| 2751 | , | 2770 | , |
| 2752 | \\pub const FOO2 = "aoeu\x134 derp"; | 2771 | \\pub const FOO2 = "aoeu\x134 derp"; |
| 2753 | , | 2772 | , |
| 2754 | \\pub const FOO_CHAR = '\x3f'; | 2773 | \\pub const FOO_CHAR = '\x3f'; |
| 2755 | }); | 2774 | }); |
| 2756 | | 2775 | |
| ... | @@ -2770,7 +2789,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2770,7 +2789,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2770 | \\ @"1" = 6, | 2789 | \\ @"1" = 6, |
| 2771 | \\ _, | 2790 | \\ _, |
| 2772 | \\}; | 2791 | \\}; |
| 2773 | , | 2792 | , |
| 2774 | \\pub const Foo = enum_Foo; | 2793 | \\pub const Foo = enum_Foo; |
| 2775 | }); | 2794 | }); |
| 2776 | | 2795 | |
| ... | @@ -2782,9 +2801,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2782,9 +2801,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2782 | \\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)))) { |
| 2783 | \\ return baz((@import("std").meta.cast(?*c_void, baz))); | 2802 | \\ return baz((@import("std").meta.cast(?*c_void, baz))); |
| 2784 | \\} | 2803 | \\} |
| 2785 | , | 2804 | , |
| 2786 | \\pub const BAR = (@import("std").meta.cast(?*c_void, a)); | 2805 | \\pub const BAR = (@import("std").meta.cast(?*c_void, a)); |
| 2787 | , | 2806 | , |
| 2788 | \\pub const BAZ = (@import("std").meta.cast(u32, 2)); | 2807 | \\pub const BAZ = (@import("std").meta.cast(u32, 2)); |
| 2789 | }); | 2808 | }); |
| 2790 | | 2809 | |
| ... | @@ -2824,7 +2843,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2824,7 +2843,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2824 | \\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) { |
| 2825 | \\ return if (b < a) b else a; | 2844 | \\ return if (b < a) b else a; |
| 2826 | \\} | 2845 | \\} |
| 2827 | , | 2846 | , |
| 2828 | \\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) { |
| 2829 | \\ return if (b > a) b else a; | 2848 | \\ return if (b > a) b else a; |
| 2830 | \\} | 2849 | \\} |
| ... | @@ -2892,7 +2911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2892,7 +2911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2892 | \\ var bar_1 = arg_bar_1; | 2911 | \\ var bar_1 = arg_bar_1; |
| 2893 | \\ bar_1 = 2; | 2912 | \\ bar_1 = 2; |
| 2894 | \\} | 2913 | \\} |
| 2895 | , | 2914 | , |
| 2896 | \\pub const bar = 4; | 2915 | \\pub const bar = 4; |
| 2897 | }); | 2916 | }); |
| 2898 | | 2917 | |
| ... | @@ -2964,9 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2964,9 +2983,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2964 | \\#define BAZ "oh, " FOO | 2983 | \\#define BAZ "oh, " FOO |
| 2965 | , &[_][]const u8{ | 2984 | , &[_][]const u8{ |
| 2966 | \\pub const FOO = "hello"; | 2985 | \\pub const FOO = "hello"; |
| 2967 | , | 2986 | , |
| 2968 | \\pub const BAR = FOO ++ " world"; | 2987 | \\pub const BAR = FOO ++ " world"; |
| 2969 | , | 2988 | , |
| 2970 | \\pub const BAZ = "oh, " ++ FOO; | 2989 | \\pub const BAZ = "oh, " ++ FOO; |
| 2971 | }); | 2990 | }); |
| 2972 | | 2991 | |
| ... | @@ -2976,9 +2995,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2976,9 +2995,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2976 | \\#define BAR FOO BAZ | 2995 | \\#define BAR FOO BAZ |
| 2977 | , &[_][]const u8{ | 2996 | , &[_][]const u8{ |
| 2978 | \\pub const FOO = "hello"; | 2997 | \\pub const FOO = "hello"; |
| 2979 | , | 2998 | , |
| 2980 | \\pub const BAZ = " world"; | 2999 | \\pub const BAZ = " world"; |
| 2981 | , | 3000 | , |
| 2982 | \\pub const BAR = FOO ++ BAZ; | 3001 | \\pub const BAR = FOO ++ BAZ; |
| 2983 | }); | 3002 | }); |
| 2984 | | 3003 | |
| ... | @@ -2987,7 +3006,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2987,7 +3006,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2987 | \\#define BAR FOO "c" | 3006 | \\#define BAR FOO "c" |
| 2988 | , &[_][]const u8{ | 3007 | , &[_][]const u8{ |
| 2989 | \\pub const FOO = "a" ++ "b"; | 3008 | \\pub const FOO = "a" ++ "b"; |
| 2990 | , | 3009 | , |
| 2991 | \\pub const BAR = FOO ++ "c"; | 3010 | \\pub const BAR = FOO ++ "c"; |
| 2992 | }); | 3011 | }); |
| 2993 | | 3012 | |
| ... | @@ -3023,7 +3042,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3023,7 +3042,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3023 | \\#define FOO ((int)0x8000) | 3042 | \\#define FOO ((int)0x8000) |
| 3024 | , &[_][]const u8{ | 3043 | , &[_][]const u8{ |
| 3025 | \\pub const NULL = (@import("std").meta.cast(?*c_void, 0)); | 3044 | \\pub const NULL = (@import("std").meta.cast(?*c_void, 0)); |
| 3026 | , | 3045 | , |
| 3027 | \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000)); | 3046 | \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000)); |
| 3028 | }); | 3047 | }); |
| 3029 | | 3048 | |