| ... | ... | @@ -1458,7 +1458,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1458 | 1458 | cases.add("macro pointer cast", |
| 1459 | 1459 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1460 | 1460 | , &[_][]const u8{ |
| 1461 | | \\pub const NRF_GPIO = (if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Int and @typeInfo([*c]NRF_GPIO_Type) == .Pointer) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE)); |
| 1461 | \\pub const NRF_GPIO = (if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, @alignCast(@alignOf([*c]NRF_GPIO_Type.Child), NRF_GPIO_BASE)) else if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Int and @typeInfo([*c]NRF_GPIO_Type) == .Pointer) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE)); |
| 1462 | 1462 | }); |
| 1463 | 1463 | |
| 1464 | 1464 | cases.add("basic macro function", |
| ... | ... | @@ -2668,11 +2668,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2668 | 2668 | \\#define FOO(bar) baz((void *)(baz)) |
| 2669 | 2669 | \\#define BAR (void*) a |
| 2670 | 2670 | , &[_][]const u8{ |
| 2671 | | \\pub inline fn FOO(bar: var) @TypeOf(baz((if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, baz) else @as(*c_void, baz)))) { |
| 2672 | | \\ return baz((if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, baz) else @as(*c_void, baz))); |
| 2671 | \\pub inline fn FOO(bar: var) @TypeOf(baz((if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, @alignCast(@alignOf(*c_void.Child), baz)) else if (@typeInfo(@TypeOf(baz)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, baz) else @as(*c_void, baz)))) { |
| 2672 | \\ return baz((if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, @alignCast(@alignOf(*c_void.Child), baz)) else if (@typeInfo(@TypeOf(baz)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, baz) else @as(*c_void, baz))); |
| 2673 | 2673 | \\} |
| 2674 | 2674 | , |
| 2675 | | \\pub const BAR = (if (@typeInfo(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeInfo(@TypeOf(a)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, a) else @as(*c_void, a)); |
| 2675 | \\pub const BAR = (if (@typeInfo(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, @alignCast(@alignOf(*c_void.Child), a)) else if (@typeInfo(@TypeOf(a)) == .Int and @typeInfo(*c_void) == .Pointer) @intToPtr(*c_void, a) else @as(*c_void, a)); |
| 2676 | 2676 | }); |
| 2677 | 2677 | |
| 2678 | 2678 | cases.add("macro conditional operator", |
| ... | ... | @@ -2879,4 +2879,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2879 | 2879 | , &[_][]const u8{ |
| 2880 | 2880 | \\pub const FOO = 0x61626364; |
| 2881 | 2881 | }); |
| 2882 | |
| 2883 | cases.add("Make sure casts are grouped", |
| 2884 | \\typedef struct |
| 2885 | \\{ |
| 2886 | \\ int i; |
| 2887 | \\} |
| 2888 | \\*_XPrivDisplay; |
| 2889 | \\typedef struct _XDisplay Display; |
| 2890 | \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) |
| 2891 | \\ |
| 2892 | , &[_][]const u8{ |
| 2893 | \\pub inline fn DefaultScreen(dpy: var) @TypeOf((if (@typeInfo(@TypeOf(dpy)) == .Pointer) @ptrCast(_XPrivDisplay, @alignCast(@alignOf(_XPrivDisplay.Child), dpy)) else if (@typeInfo(@TypeOf(dpy)) == .Int and @typeInfo(_XPrivDisplay) == .Pointer) @intToPtr(_XPrivDisplay, dpy) else @as(_XPrivDisplay, dpy)).*.default_screen) { |
| 2894 | \\ return (if (@typeInfo(@TypeOf(dpy)) == .Pointer) @ptrCast(_XPrivDisplay, @alignCast(@alignOf(_XPrivDisplay.Child), dpy)) else if (@typeInfo(@TypeOf(dpy)) == .Int and @typeInfo(_XPrivDisplay) == .Pointer) @intToPtr(_XPrivDisplay, dpy) else @as(_XPrivDisplay, dpy)).*.default_screen; |
| 2895 | \\} |
| 2896 | }); |
| 2882 | 2897 | } |