forked from mirror/vulkan-zig
Merge pull request #176 from Snektron/vulkan-video-flags
default initialize packed flag structs to false
This commit is contained in:
@@ -199,7 +199,13 @@ pub const Api = reg.Api;
|
||||
/// and the resulting binding is written to `writer`. `allocator` will be used to allocate temporary
|
||||
/// internal datastructures - mostly via an ArenaAllocator, but sometimes a hashmap uses this allocator
|
||||
/// directly. `api` is the API to generate the bindings for, usually `.vulkan`.
|
||||
pub fn generate(allocator: Allocator, api: Api, spec_xml: []const u8, maybe_video_spec_xml: ?[]const u8, writer: anytype) !void {
|
||||
pub fn generate(
|
||||
allocator: Allocator,
|
||||
api: Api,
|
||||
spec_xml: []const u8,
|
||||
maybe_video_spec_xml: ?[]const u8,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
const spec = xml.parse(allocator, spec_xml) catch |err| switch (err) {
|
||||
error.InvalidDocument,
|
||||
error.UnexpectedEof,
|
||||
|
||||
@@ -417,7 +417,12 @@ fn parseEnumAlias(elem: *xml.Element) !?registry.Declaration {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn parseEnums(allocator: Allocator, root: *xml.Element, api: registry.Api, decls: *std.ArrayListUnmanaged(registry.Declaration)) !void {
|
||||
fn parseEnums(
|
||||
allocator: Allocator,
|
||||
root: *xml.Element,
|
||||
api: registry.Api,
|
||||
decls: *std.ArrayListUnmanaged(registry.Declaration),
|
||||
) !void {
|
||||
var it = root.findChildrenByTag("enums");
|
||||
while (it.next()) |enums| {
|
||||
const name = enums.getAttribute("name") orelse return error.InvalidRegistry;
|
||||
|
||||
@@ -993,11 +993,16 @@ fn Renderer(comptime WriterType: type) type {
|
||||
|
||||
fn renderSimpleBitContainer(self: *Self, container: reg.Container) !bool {
|
||||
var total_bits: usize = 0;
|
||||
var is_flags_container = true;
|
||||
for (container.fields) |field| {
|
||||
total_bits += field.bits orelse {
|
||||
const bits = field.bits orelse {
|
||||
// C abi type - not a packed struct.
|
||||
return false;
|
||||
};
|
||||
total_bits += bits;
|
||||
if (bits != 1) {
|
||||
is_flags_container = false;
|
||||
}
|
||||
}
|
||||
|
||||
try self.writer.writeAll("packed struct(u32) {");
|
||||
@@ -1012,7 +1017,11 @@ fn Renderer(comptime WriterType: type) type {
|
||||
try self.writer.print(" u{} = 0,\n", .{field.bits.?});
|
||||
} else if (bits == 1) {
|
||||
// Assume its a flag.
|
||||
try self.writer.writeAll(" bool,\n");
|
||||
if (is_flags_container) {
|
||||
try self.writer.writeAll(" bool = false,\n");
|
||||
} else {
|
||||
try self.writer.writeAll(" bool,\n");
|
||||
}
|
||||
} else {
|
||||
try self.writer.print(" u{},\n", .{field.bits.?});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user