forked from mirror/vulkan-zig
format bit flags as set
This changes to format output from:
MyFlagType{ .first_bit = true, second_bit = false, _reserved_bit_0 = false, _reserved_bit_1 = false }
to the following:
MyFlagType{ first_bit }
That is, we only show bits which are `true`.
This commit is contained in:
@@ -49,6 +49,7 @@ const preamble =
|
|||||||
\\ pub fn contains(lhs: FlagsType, rhs: FlagsType) bool {
|
\\ pub fn contains(lhs: FlagsType, rhs: FlagsType) bool {
|
||||||
\\ return toInt(intersect(lhs, rhs)) == toInt(rhs);
|
\\ return toInt(intersect(lhs, rhs)) == toInt(rhs);
|
||||||
\\ }
|
\\ }
|
||||||
|
++ bit_flag_format ++
|
||||||
\\ };
|
\\ };
|
||||||
\\}
|
\\}
|
||||||
\\pub fn makeApiVersion(variant: u3, major: u7, minor: u10, patch: u12) u32 {
|
\\pub fn makeApiVersion(variant: u3, major: u7, minor: u10, patch: u12) u32 {
|
||||||
@@ -69,6 +70,31 @@ const preamble =
|
|||||||
\\
|
\\
|
||||||
;
|
;
|
||||||
|
|
||||||
|
const bit_flag_format =
|
||||||
|
\\ pub fn format(
|
||||||
|
\\ self: @This(),
|
||||||
|
\\ comptime _: []const u8,
|
||||||
|
\\ _: std.fmt.FormatOptions,
|
||||||
|
\\ writer: anytype,
|
||||||
|
\\ ) !void {
|
||||||
|
\\ try writer.writeAll(@typeName(@This()) ++ "{");
|
||||||
|
\\ var first = true;
|
||||||
|
\\ inline for (comptime std.meta.fieldNames(@This())) |name| {
|
||||||
|
\\ if (name[0] == '_') continue;
|
||||||
|
\\ if (@field(self, name)) {
|
||||||
|
\\ if (first) {
|
||||||
|
\\ try writer.writeAll(" " ++ name);
|
||||||
|
\\ first = false;
|
||||||
|
\\ } else {
|
||||||
|
\\ try writer.writeAll(", " ++ name);
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\ if (!first) try writer.writeAll(" ");
|
||||||
|
\\ try writer.writeAll("}");
|
||||||
|
\\ }
|
||||||
|
;
|
||||||
|
|
||||||
const builtin_types = std.ComptimeStringMap([]const u8, .{
|
const builtin_types = std.ComptimeStringMap([]const u8, .{
|
||||||
.{ "void", @typeName(void) },
|
.{ "void", @typeName(void) },
|
||||||
.{ "char", @typeName(u8) },
|
.{ "char", @typeName(u8) },
|
||||||
@@ -1060,6 +1086,7 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
\\ }
|
\\ }
|
||||||
\\ return true;
|
\\ return true;
|
||||||
\\ }
|
\\ }
|
||||||
|
++ bit_flag_format ++
|
||||||
\\ };
|
\\ };
|
||||||
\\}
|
\\}
|
||||||
\\
|
\\
|
||||||
|
|||||||
Reference in New Issue
Block a user