| ... | @@ -59,7 +59,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -59,7 +59,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 59 | ); | 59 | ); |
| 60 | } | 60 | } |
| 61 | | 61 | |
| 62 | cases.add("for loop with var init but empty body", | 62 | cases.add("predefined expressions", |
| 63 | \\void foo(void) { | 63 | \\void foo(void) { |
| 64 | \\ __func__; | 64 | \\ __func__; |
| 65 | \\ __FUNCTION__; | 65 | \\ __FUNCTION__; |
| ... | @@ -526,11 +526,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -526,11 +526,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 526 | \\ return b; | 526 | \\ return b; |
| 527 | \\ else | 527 | \\ else |
| 528 | \\ return a; | 528 | \\ return a; |
| | 529 | \\ |
| | 530 | \\ if (a < b) ; else ; |
| 529 | \\} | 531 | \\} |
| 530 | , | 532 | , |
| 531 | \\pub export fn max(a: c_int, b: c_int) c_int { | 533 | \\pub export fn max(a: c_int, b: c_int) c_int { |
| 532 | \\ if (a < b) return b; | 534 | \\ if (a < b) return b; |
| 533 | \\ if (a < b) return b else return a; | 535 | \\ if (a < b) return b else return a; |
| | 536 | \\ if (a < b) {} else {} |
| 534 | \\} | 537 | \\} |
| 535 | ); | 538 | ); |
| 536 | | 539 | |
| ... | @@ -772,6 +775,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -772,6 +775,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 772 | \\} | 775 | \\} |
| 773 | ); | 776 | ); |
| 774 | | 777 | |
| | 778 | cases.addC("void cast", |
| | 779 | \\void foo(int a) { |
| | 780 | \\ (void) a; |
| | 781 | \\} |
| | 782 | , |
| | 783 | \\pub export fn foo(a: c_int) void { |
| | 784 | \\ _ = a; |
| | 785 | \\} |
| | 786 | ); |
| | 787 | |
| 775 | cases.addC("implicit cast to void *", | 788 | cases.addC("implicit cast to void *", |
| 776 | \\void *foo(unsigned short *x) { | 789 | \\void *foo(unsigned short *x) { |
| 777 | \\ return x; | 790 | \\ return x; |
| ... | @@ -1472,21 +1485,53 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1472,21 +1485,53 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1472 | \\pub export fn bar() void {} | 1485 | \\pub export fn bar() void {} |
| 1473 | ); | 1486 | ); |
| 1474 | | 1487 | |
| 1475 | cases.addC("u integer suffix after 0 (zero) in macro definition", "#define ZERO 0U", "pub const ZERO = c_uint(0);"); | 1488 | cases.addC( |
| | 1489 | "u integer suffix after 0 (zero) in macro definition", |
| | 1490 | "#define ZERO 0U", |
| | 1491 | "pub const ZERO = c_uint(0);", |
| | 1492 | ); |
| 1476 | | 1493 | |
| 1477 | cases.addC("l integer suffix after 0 (zero) in macro definition", "#define ZERO 0L", "pub const ZERO = c_long(0);"); | 1494 | cases.addC( |
| | 1495 | "l integer suffix after 0 (zero) in macro definition", |
| | 1496 | "#define ZERO 0L", |
| | 1497 | "pub const ZERO = c_long(0);", |
| | 1498 | ); |
| 1478 | | 1499 | |
| 1479 | cases.addC("ul integer suffix after 0 (zero) in macro definition", "#define ZERO 0UL", "pub const ZERO = c_ulong(0);"); | 1500 | cases.addC( |
| | 1501 | "ul integer suffix after 0 (zero) in macro definition", |
| | 1502 | "#define ZERO 0UL", |
| | 1503 | "pub const ZERO = c_ulong(0);", |
| | 1504 | ); |
| 1480 | | 1505 | |
| 1481 | cases.addC("lu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LU", "pub const ZERO = c_ulong(0);"); | 1506 | cases.addC( |
| | 1507 | "lu integer suffix after 0 (zero) in macro definition", |
| | 1508 | "#define ZERO 0LU", |
| | 1509 | "pub const ZERO = c_ulong(0);", |
| | 1510 | ); |
| 1482 | | 1511 | |
| 1483 | cases.addC("ll integer suffix after 0 (zero) in macro definition", "#define ZERO 0LL", "pub const ZERO = c_longlong(0);"); | 1512 | cases.addC( |
| | 1513 | "ll integer suffix after 0 (zero) in macro definition", |
| | 1514 | "#define ZERO 0LL", |
| | 1515 | "pub const ZERO = c_longlong(0);", |
| | 1516 | ); |
| 1484 | | 1517 | |
| 1485 | cases.addC("ull integer suffix after 0 (zero) in macro definition", "#define ZERO 0ULL", "pub const ZERO = c_ulonglong(0);"); | 1518 | cases.addC( |
| | 1519 | "ull integer suffix after 0 (zero) in macro definition", |
| | 1520 | "#define ZERO 0ULL", |
| | 1521 | "pub const ZERO = c_ulonglong(0);", |
| | 1522 | ); |
| 1486 | | 1523 | |
| 1487 | cases.addC("llu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LLU", "pub const ZERO = c_ulonglong(0);"); | 1524 | cases.addC( |
| | 1525 | "llu integer suffix after 0 (zero) in macro definition", |
| | 1526 | "#define ZERO 0LLU", |
| | 1527 | "pub const ZERO = c_ulonglong(0);", |
| | 1528 | ); |
| 1488 | | 1529 | |
| 1489 | cases.addC("bitwise not on u-suffixed 0 (zero) in macro definition", "#define NOT_ZERO (~0U)", "pub const NOT_ZERO = ~c_uint(0);"); | 1530 | cases.addC( |
| | 1531 | "bitwise not on u-suffixed 0 (zero) in macro definition", |
| | 1532 | "#define NOT_ZERO (~0U)", |
| | 1533 | "pub const NOT_ZERO = ~c_uint(0);", |
| | 1534 | ); |
| 1490 | | 1535 | |
| 1491 | // cases.add("empty array with initializer", | 1536 | // cases.add("empty array with initializer", |
| 1492 | // "int a[4] = {};" | 1537 | // "int a[4] = {};" |