Extract some helper functions

This commit is contained in:
Patrick O'Connell
2024-06-23 10:22:24 -07:00
parent ff4cff5f64
commit e9199a0abc

View File

@@ -1585,15 +1585,12 @@ fn Renderer(comptime WriterType: type) type {
proxy, proxy,
}; };
fn renderWrapperPrototype( fn renderWrapperName(
self: *Self, self: *Self,
name: []const u8, name: []const u8,
command: reg.Command,
returns: []const ReturnValue,
dispatch_handle: []const u8, dispatch_handle: []const u8,
kind: WrapperKind, kind: WrapperKind,
) !void { ) !void {
try self.writer.writeAll("pub fn ");
const trimmed_name = switch (kind) { const trimmed_name = switch (kind) {
.wrapper => trimVkNamespace(name), .wrapper => trimVkNamespace(name),
.proxy => blk: { .proxy => blk: {
@@ -1608,7 +1605,25 @@ fn Renderer(comptime WriterType: type) type {
}, },
}; };
try self.writeIdentifierWithCase(.camel, trimmed_name); try self.writeIdentifierWithCase(.camel, trimmed_name);
}
fn renderWrapperParam(self: *Self, param: reg.Command.Param) !void {
try self.writeIdentifierWithCase(.snake, param.name);
try self.writer.writeAll(": ");
try self.renderTypeInfo(param.param_type);
try self.writer.writeAll(", ");
}
fn renderWrapperPrototype(
self: *Self,
name: []const u8,
command: reg.Command,
returns: []const ReturnValue,
dispatch_handle: []const u8,
kind: WrapperKind,
) !void {
try self.writer.writeAll("pub fn ");
try self.renderWrapperName(name, dispatch_handle, kind);
try self.writer.writeAll("(self: Self, "); try self.writer.writeAll("(self: Self, ");
for (command.params) |param| { for (command.params) |param| {
@@ -1623,10 +1638,7 @@ fn Renderer(comptime WriterType: type) type {
continue; continue;
} }
try self.writeIdentifierWithCase(.snake, param.name); try self.renderWrapperParam(param);
try self.writer.writeAll(": ");
try self.renderTypeInfo(param.param_type);
try self.writer.writeAll(", ");
} }
try self.writer.writeAll(") "); try self.writer.writeAll(") ");