| author | |
| committer | |
| log | 7b32062775cca303d8a2fc72b17545b0246f9f9a |
| tree | 48df9a255d8a064c677a1ec3e402f6f466571f0a |
| parent | 234ccb4a5088cd6fa06144d7ba1aceab0596f1cc |
| signature |
3 files changed, 23 insertions(+), 0 deletions(-)
src/translate_c.zig+2| ... | ... | @@ -5110,6 +5110,7 @@ const PatternList = struct { |
| 5110 | 5110 | [2][]const u8{ "ULL_SUFFIX(X) (X ## ULL)", "ULL_SUFFIX" }, |
| 5111 | 5111 | |
| 5112 | 5112 | [2][]const u8{ "CAST_OR_CALL(X, Y) (X)(Y)", "CAST_OR_CALL" }, |
| 5113 | [2][]const u8{ "CAST_OR_CALL(X, Y) ((X)(Y))", "CAST_OR_CALL" }, | |
| 5113 | 5114 | |
| 5114 | 5115 | [2][]const u8{ |
| 5115 | 5116 | \\wl_container_of(ptr, sample, member) \ |
| ... | ... | @@ -5303,6 +5304,7 @@ test "Macro matching" { |
| 5303 | 5304 | |
| 5304 | 5305 | try helper.checkMacro(allocator, pattern_list, "NO_MATCH(X, Y) (X + Y)", null); |
| 5305 | 5306 | try helper.checkMacro(allocator, pattern_list, "CAST_OR_CALL(X, Y) (X)(Y)", "CAST_OR_CALL"); |
| 5307 | try helper.checkMacro(allocator, pattern_list, "CAST_OR_CALL(X, Y) ((X)(Y))", "CAST_OR_CALL"); | |
| 5306 | 5308 | try helper.checkMacro(allocator, pattern_list, "IGNORE_ME(X) (void)(X)", "DISCARD"); |
| 5307 | 5309 | try helper.checkMacro(allocator, pattern_list, "IGNORE_ME(X) ((void)(X))", "DISCARD"); |
| 5308 | 5310 | try helper.checkMacro(allocator, pattern_list, "IGNORE_ME(X) (const void)(X)", "DISCARD"); |
test/behavior/translate_c_macros.h+1| ... | ... | @@ -37,5 +37,6 @@ union U { |
| 37 | 37 | #define IGNORE_ME_10(x) (volatile const void)(x) |
| 38 | 38 | |
| 39 | 39 | #define UNION_CAST(X) (union U)(X) |
| 40 | #define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val)) | |
| 40 | 41 | |
| 41 | 42 | #define NESTED_COMMA_OPERATOR (1, (2, 3)) |
test/behavior/translate_c_macros.zig+20| ... | ... | @@ -70,6 +70,26 @@ test "casting to union with a macro" { |
| 70 | 70 | try expect(d == casted.d); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | test "casting or calling a value with a paren-surrounded macro" { | |
| 74 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 75 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 76 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 77 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 78 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 79 | ||
| 80 | const l: c_long = 42; | |
| 81 | const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l); | |
| 82 | try expect(casted == @intCast(c_int, l)); | |
| 83 | ||
| 84 | const Helper = struct { | |
| 85 | fn foo(n: c_int) !void { | |
| 86 | try expect(n == 42); | |
| 87 | } | |
| 88 | }; | |
| 89 | ||
| 90 | try h.CAST_OR_CALL_WITH_PARENS(Helper.foo, 42); | |
| 91 | } | |
| 92 | ||
| 73 | 93 | test "nested comma operator" { |
| 74 | 94 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 75 | 95 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |