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 {...@@ -5211,21 +5211,26 @@ fn parseCPostfixExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5211 }5211 }
5212 },5212 },
5213 .LParen => {5213 .LParen => {
5214 var args = std.ArrayList(Node).init(c.gpa);5214 if (m.peek().? == .RParen) {
5215 defer args.deinit();5215 m.i += 1;
5216 while (true) {5216 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &[0]Node{} });
5217 const arg = try parseCCondExpr(c, m, scope);5217 } else {
5218 try args.append(arg);5218 var args = std.ArrayList(Node).init(c.gpa);
5219 switch (m.next().?) {5219 defer args.deinit();
5220 .Comma => {},5220 while (true) {
5221 .RParen => break,5221 const arg = try parseCCondExpr(c, m, scope);
5222 else => {5222 try args.append(arg);
5223 try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});5223 switch (m.next().?) {
5224 return error.ParseError;5224 .Comma => {},
5225 },5225 .RParen => break,
5226 else => {
5227 try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});
5228 return error.ParseError;
5229 },
5230 }
5226 }5231 }
5232 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
5227 }5233 }
5228 node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
5229 },5234 },
5230 .LBrace => {5235 .LBrace => {
5231 var init_vals = std.ArrayList(Node).init(c.gpa);5236 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 {...@@ -2529,6 +2529,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2529 \\}2529 \\}
2530 });2530 });
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
2532 cases.add("logical and, logical or",2540 cases.add("logical and, logical or",
2533 \\int max(int a, int b) {2541 \\int max(int a, int b) {
2534 \\ if (a < b || a == b)2542 \\ if (a < b || a == b)