| ... | ... | @@ -228,6 +228,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 228 | 228 | }); |
| 229 | 229 | |
| 230 | 230 | cases.add("macro expressions respect C operator precedence", |
| 231 | \\int *foo = 0; |
| 231 | 232 | \\#define FOO *((foo) + 2) |
| 232 | 233 | \\#define VALUE (1 + 2 * 3 + 4 * 5 + 6 << 7 | 8 == 9) |
| 233 | 234 | \\#define _AL_READ3BYTES(p) ((*(unsigned char *)(p)) \ |
| ... | ... | @@ -459,6 +460,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 459 | 460 | }); |
| 460 | 461 | |
| 461 | 462 | cases.add("macro line continuation", |
| 463 | \\int BAR = 0; |
| 462 | 464 | \\#define FOO -\ |
| 463 | 465 | \\BAR |
| 464 | 466 | , &[_][]const u8{ |
| ... | ... | @@ -1833,6 +1835,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1833 | 1835 | }); |
| 1834 | 1836 | |
| 1835 | 1837 | cases.add("macro pointer cast", |
| 1838 | \\#define NRF_GPIO_BASE 0 |
| 1836 | 1839 | \\typedef struct { int dummy; } NRF_GPIO_Type; |
| 1837 | 1840 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1838 | 1841 | , &[_][]const u8{ |
| ... | ... | @@ -1873,6 +1876,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1873 | 1876 | }); |
| 1874 | 1877 | |
| 1875 | 1878 | cases.add("macro add", |
| 1879 | \\#define D3_AHB1PERIPH_BASE 0 |
| 1876 | 1880 | \\#define PERIPH_BASE (0x40000000UL) /*!< Base address of : AHB/APB Peripherals */ |
| 1877 | 1881 | \\#define D3_APB1PERIPH_BASE (PERIPH_BASE + 0x18000000UL) |
| 1878 | 1882 | \\#define RCC_BASE (D3_AHB1PERIPH_BASE + 0x4400UL) |
| ... | ... | @@ -3138,6 +3142,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3138 | 3142 | \\#define FOO(bar) baz((void *)(baz)) |
| 3139 | 3143 | \\#define BAR (void*) a |
| 3140 | 3144 | \\#define BAZ (uint32_t)(2) |
| 3145 | \\#define a 2 |
| 3141 | 3146 | , &[_][]const u8{ |
| 3142 | 3147 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*c_void, baz))) { |
| 3143 | 3148 | \\ _ = bar; |
| ... | ... | @@ -3160,6 +3165,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3160 | 3165 | }); |
| 3161 | 3166 | |
| 3162 | 3167 | cases.add("macro conditional operator", |
| 3168 | \\ int a, b, c; |
| 3163 | 3169 | \\#define FOO a ? b : c |
| 3164 | 3170 | , &[_][]const u8{ |
| 3165 | 3171 | \\pub const FOO = if (a) b else c; |
| ... | ... | @@ -3649,4 +3655,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3649 | 3655 | , |
| 3650 | 3656 | \\_ = p[@intCast(c_uint, @as(c_int, 1))]; |
| 3651 | 3657 | }); |
| 3658 | |
| 3659 | cases.add("Undefined macro identifier", |
| 3660 | \\#define FOO BAR |
| 3661 | , &[_][]const u8{ |
| 3662 | \\pub const FOO = @compileError("unable to translate macro: undefined identifier `BAR`"); |
| 3663 | }); |
| 3652 | 3664 | } |