Add EnumFlags.from

This commit is contained in:
ktkk 2026-07-14 10:13:26 +00:00
parent 5ff7a358f9
commit 39fcd51a7c
5 changed files with 15 additions and 9 deletions

View file

@ -57,7 +57,7 @@ pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) (ParseError ||
var constant_pool: ConstantPool = try .parse(input, allocator);
errdefer constant_pool.deinit(allocator);
const access_flags: ClassAccessFlags = .{ .mask = try input.takeInt(u16, .big) };
const access_flags: ClassAccessFlags = .from(try input.takeInt(u16, .big));
const this_class = try input.takeInt(u16, .big);
const super_class = try input.takeInt(u16, .big);

View file

@ -1200,7 +1200,7 @@ pub const InnerClasses = struct {
.inner_class_info_index = try input.takeInt(u16, .big),
.outer_class_info_index = try input.takeInt(u16, .big),
.inner_name_index = try input.takeInt(u16, .big),
.inner_class_access_flags = .{ .mask = try input.takeInt(u16, .big) },
.inner_class_access_flags = .from(try input.takeInt(u16, .big)),
};
}
@ -2491,7 +2491,7 @@ pub const MethodParameters = struct {
for (parameters) |*parameter| {
parameter.* = .{
.name_index = try input.takeInt(u16, .big),
.access_flags = .{ .mask = try input.takeInt(u16, .big) },
.access_flags = .from(try input.takeInt(u16, .big)),
};
}
@ -2695,7 +2695,7 @@ pub const Module = struct {
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
const module_name_index = try input.takeInt(u16, .big);
const module_flags: ModuleFlags = .{ .mask = try input.takeInt(u16, .big) };
const module_flags: ModuleFlags = .from(try input.takeInt(u16, .big));
const module_version_index = try input.takeInt(u16, .big);
const requires_count = try input.takeInt(u16, .big);
@ -2703,7 +2703,7 @@ pub const Module = struct {
errdefer allocator.free(requires);
for (requires) |*r| {
const requires_index = try input.takeInt(u16, .big);
const requires_flags: Requires.RequiresFlags = .{ .mask = try input.takeInt(u16, .big) };
const requires_flags: Requires.RequiresFlags = .from(try input.takeInt(u16, .big));
const requires_version_index = try input.takeInt(u16, .big);
r.* = .{
.requires_index = requires_index,
@ -2717,7 +2717,7 @@ pub const Module = struct {
errdefer allocator.free(exports);
for (exports) |*e| {
const exports_index = try input.takeInt(u16, .big);
const exports_flags: Exports.ExportsFlags = .{ .mask = try input.takeInt(u16, .big) };
const exports_flags: Exports.ExportsFlags = .from(try input.takeInt(u16, .big));
const exports_to_count = try input.takeInt(u16, .big);
const exports_to_indeces = try allocator.alloc(u16, exports_to_count);
errdefer allocator.free(exports_to_indeces);
@ -2736,7 +2736,7 @@ pub const Module = struct {
errdefer allocator.free(opens);
for (opens) |*o| {
const opens_index = try input.takeInt(u16, .big);
const opens_flags: Opens.OpensFlags = .{ .mask = try input.takeInt(u16, .big) };
const opens_flags: Opens.OpensFlags = .from(try input.takeInt(u16, .big));
const opens_to_count = try input.takeInt(u16, .big);
const opens_to_indeces = try allocator.alloc(u16, opens_to_count);
errdefer allocator.free(opens_to_indeces);

View file

@ -27,7 +27,7 @@ pub const FieldAccessFlags = EnumFlags(enum(u16) {
});
pub fn parse(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: std.mem.Allocator) !Self {
const access_flags: FieldAccessFlags = .{ .mask = try input.takeInt(u16, .big) };
const access_flags: FieldAccessFlags = .from(try input.takeInt(u16, .big));
const name_index = try input.takeInt(u16, .big);
const descriptor_index = try input.takeInt(u16, .big);
const attributes = try Class.parseAttributes(input, constant_pool, allocator);

View file

@ -30,7 +30,7 @@ pub const MethodAccessFlags = EnumFlags(enum(u16) {
});
pub fn parse(input: *std.Io.Reader, constant_pool: ConstantPool, allocator: std.mem.Allocator) !Self {
const access_flags: MethodAccessFlags = .{ .mask = try input.takeInt(u16, .big) };
const access_flags: MethodAccessFlags = .from(try input.takeInt(u16, .big));
const name_index = try input.takeInt(u16, .big);
const descriptor_index = try input.takeInt(u16, .big);
const attributes = try Class.parseAttributes(input, constant_pool, allocator);

View file

@ -10,6 +10,12 @@ pub fn EnumFlags(comptime E: type) type {
pub const empty: Self = .{ .data = 0 };
pub fn from(mask: BackingInt) Self {
return .{
.mask = mask,
};
}
pub fn contains(self: Self, flag: E) bool {
return (self.mask & @intFromEnum(flag)) != 0;
}