| author | |
| committer | |
| log | a1a16a941e6e04c0f6f0d17c4c9f13d2ba32a9a1 |
| tree | a83e67808b7695158e4bfb6c55f9e9778ab6a792 |
| parent | c9551652b01bf47a94c139846f22c5df85d07283 |
| parent | 79549e0ac188ffd92b8959c8160d9a4a27d0eb30 |
| signature |
Translate-c: fix macro functions with no arguments2 files changed, 8 insertions(+), 5 deletions(-)
src/translate_c.zig+3-5| ... | ... | @@ -5437,9 +5437,8 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void { |
| 5437 | 5437 | defer fn_params.deinit(); |
| 5438 | 5438 | |
| 5439 | 5439 | while (true) { |
| 5440 | if (m.next().? != .Identifier) { | |
| 5441 | return m.fail(c, "unable to translate C expr: expected identifier", .{}); | |
| 5442 | } | |
| 5440 | if (m.peek().? != .Identifier) break; | |
| 5441 | _ = m.next(); | |
| 5443 | 5442 | |
| 5444 | 5443 | const mangled_name = try block_scope.makeMangledName(c, m.slice()); |
| 5445 | 5444 | const param_name_tok = try appendIdentifier(c, mangled_name); |
| ... | ... | @@ -5459,8 +5458,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void { |
| 5459 | 5458 | .param_type = .{ .any_type = &any_type.base }, |
| 5460 | 5459 | }; |
| 5461 | 5460 | |
| 5462 | if (m.peek().? != .Comma) | |
| 5463 | break; | |
| 5461 | if (m.peek().? != .Comma) break; | |
| 5464 | 5462 | _ = m.next(); |
| 5465 | 5463 | _ = try appendToken(c, .Comma, ","); |
| 5466 | 5464 | } |
test/translate_c.zig+5| ... | ... | @@ -1589,6 +1589,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1589 | 1589 | \\extern int c; |
| 1590 | 1590 | \\#define BASIC(c) (c*2) |
| 1591 | 1591 | \\#define FOO(L,b) (L + b) |
| 1592 | \\#define BAR() (c*c) | |
| 1592 | 1593 | , &[_][]const u8{ |
| 1593 | 1594 | \\pub extern var c: c_int; |
| 1594 | 1595 | , |
| ... | ... | @@ -1599,6 +1600,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1599 | 1600 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { |
| 1600 | 1601 | \\ return L + b; |
| 1601 | 1602 | \\} |
| 1603 | , | |
| 1604 | \\pub inline fn BAR() @TypeOf(c * c) { | |
| 1605 | \\ return c * c; | |
| 1606 | \\} | |
| 1602 | 1607 | }); |
| 1603 | 1608 | |
| 1604 | 1609 | cases.add("macro defines string literal with hex", |