From d1dcc64d5118a64b79170d899b8d44906d610d2f Mon Sep 17 00:00:00 2001 From: Anders Elfgren Date: Sun, 10 Dec 2023 12:10:25 +0100 Subject: [PATCH] Adds support for unnamed arguments in functions. --- src/Transpiler.zig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Transpiler.zig b/src/Transpiler.zig index 6c5b8e5..72bf93c 100644 --- a/src/Transpiler.zig +++ b/src/Transpiler.zig @@ -1448,7 +1448,10 @@ fn visitFunctionTemplateDecl(self: *Self, node: *const json.Value) !void { var body = std.ArrayList(u8).init(self.allocator); defer body.deinit(); - for (f_items) |*f_item| { + var unused_arg_names = try std.ArrayList(u8).initCapacity(self.allocator, 16); + defer unused_arg_names.deinit(); + + for (f_items, 0..) |*f_item, i_item| { const arg_kind = f_item.object.get("kind").?.string; if (mem.eql(u8, arg_kind, "ParmVarDecl")) { // todo: obsolete @@ -1462,7 +1465,16 @@ fn visitFunctionTemplateDecl(self: *Self, node: *const json.Value) !void { } comma = true; - const arg_name = f_item.object.get("name").?.string; + const arg_name_opt = f_item.object.get("name"); + const arg_name = blk: { + if (arg_name_opt) |an| + break :blk an.string + else { + unused_arg_names.resize(0) catch unreachable; + try unused_arg_names.writer().print("arg_{}", .{i_item}); + break :blk unused_arg_names.items; + } + }; const arg_type = try self.transpileType(qual); defer self.allocator.free(arg_type);