mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
translate-c: fix calls with no args in macros
This commit is contained in:
parent
74fd7107e8
commit
e4563860fe
@ -5211,21 +5211,26 @@ fn parseCPostfixExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
|
||||
}
|
||||
},
|
||||
.LParen => {
|
||||
var args = std.ArrayList(Node).init(c.gpa);
|
||||
defer args.deinit();
|
||||
while (true) {
|
||||
const arg = try parseCCondExpr(c, m, scope);
|
||||
try args.append(arg);
|
||||
switch (m.next().?) {
|
||||
.Comma => {},
|
||||
.RParen => break,
|
||||
else => {
|
||||
try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});
|
||||
return error.ParseError;
|
||||
},
|
||||
if (m.peek().? == .RParen) {
|
||||
m.i += 1;
|
||||
node = try Tag.call.create(c.arena, .{ .lhs = node, .args = &[0]Node{} });
|
||||
} else {
|
||||
var args = std.ArrayList(Node).init(c.gpa);
|
||||
defer args.deinit();
|
||||
while (true) {
|
||||
const arg = try parseCCondExpr(c, m, scope);
|
||||
try args.append(arg);
|
||||
switch (m.next().?) {
|
||||
.Comma => {},
|
||||
.RParen => break,
|
||||
else => {
|
||||
try m.fail(c, "unable to translate C expr: expected ',' or ')'", .{});
|
||||
return error.ParseError;
|
||||
},
|
||||
}
|
||||
}
|
||||
node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
|
||||
}
|
||||
node = try Tag.call.create(c.arena, .{ .lhs = node, .args = try c.arena.dupe(Node, args.items) });
|
||||
},
|
||||
.LBrace => {
|
||||
var init_vals = std.ArrayList(Node).init(c.gpa);
|
||||
|
||||
@ -2529,6 +2529,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\}
|
||||
});
|
||||
|
||||
cases.add("macro call with no args",
|
||||
\\#define CALL(arg) bar()
|
||||
, &[_][]const u8{
|
||||
\\pub fn CALL(arg: anytype) callconv(.Inline) @TypeOf(bar()) {
|
||||
\\ return bar();
|
||||
\\}
|
||||
});
|
||||
|
||||
cases.add("logical and, logical or",
|
||||
\\int max(int a, int b) {
|
||||
\\ if (a < b || a == b)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user