authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-04-04 00:15:22+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-04-04 20:43:13+03:00
loge4563860feba97626630d15f481c6ad19348b81f
tree358b23802c470530d7ab2844852219a0c857b73a
parent74fd7107e85e19412c4b5d2c55d230844f22f372

translate-c: fix calls with no args in macros


2 files changed, 26 insertions(+), 13 deletions(-)

src/translate_c.zig+18-13
......@@ -5211,21 +5211,26 @@ fn parseCPostfixExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
52115211 }
52125212 },
52135213 .LParen => {
5214 var args = std.ArrayList(Node).init(c.gpa);
5215 defer args.deinit();
5216 while (true) {
5217 const arg = try parseCCondExpr(c, m, scope);
5218 try args.append(arg);
5219 switch (m.next().?) {
5220 .Comma => {},
5221 .RParen => break,
5222 else => {
5223 try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});
5224 return error.ParseError;
5225 },
5214 if (m.peek().? == .RParen) {
5215 m.i += 1;
5216 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &[0]Node{} });
5217 } else {
5218 var args = std.ArrayList(Node).init(c.gpa);
5219 defer args.deinit();
5220 while (true) {
5221 const arg = try parseCCondExpr(c, m, scope);
5222 try args.append(arg);
5223 switch (m.next().?) {
5224 .Comma => {},
5225 .RParen => break,
5226 else => {
5227 try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});
5228 return error.ParseError;
5229 },
5230 }
52265231 }
5232 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
52275233 }
5228 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
52295234 },
52305235 .LBrace => {
52315236 var init_vals = std.ArrayList(Node).init(c.gpa);
test/translate_c.zig+8
......@@ -2529,6 +2529,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25292529 \\}
25302530 });
25312531
2532 cases.add("macro call with no args",
2533 \\#define CALL(arg) bar()
2534 , &[_][]const u8{
2535 \\pub fn CALL(arg: anytype) callconv(.Inline) @TypeOf(bar()) {
2536 \\ return bar();
2537 \\}
2538 });
2539
25322540 cases.add("logical and, logical or",
25332541 \\int max(int a, int b) {
25342542 \\ if (a < b || a == b)