Add is method to ConstantPool.Info
This commit is contained in:
parent
146d90ccec
commit
cb43efcbb1
1 changed files with 8 additions and 4 deletions
|
|
@ -165,15 +165,15 @@ pub const Info = union(Info.Tag) {
|
|||
const info = try constant_pool.get(self.reference_index);
|
||||
return switch (self.reference_kind) {
|
||||
.get_field, .get_static, .put_field, .put_static => blk: {
|
||||
if (@as(Tag, info) != .field_ref) break :blk ResolveError.InvalidConstantType;
|
||||
if (!info.is(.field_ref)) break :blk ResolveError.InvalidConstantType;
|
||||
break :blk info;
|
||||
},
|
||||
.invoke_virtual, .invoke_static, .invoke_special, .new_invoke_special => blk: {
|
||||
if (@as(Tag, info) != .method_ref) break :blk ResolveError.InvalidConstantType;
|
||||
if (!info.is(.method_ref)) break :blk ResolveError.InvalidConstantType;
|
||||
break :blk info;
|
||||
},
|
||||
.invoke_interface => blk: {
|
||||
if (@as(Tag, info) != .interface_method_ref) break :blk ResolveError.InvalidConstantType;
|
||||
if (!info.is(.interface_method_ref)) break :blk ResolveError.InvalidConstantType;
|
||||
break :blk info;
|
||||
},
|
||||
};
|
||||
|
|
@ -496,6 +496,10 @@ pub const Info = union(Info.Tag) {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is(self: *const Info, tag: Tag) bool {
|
||||
return @as(Tag, self.*) == tag;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
||||
|
|
@ -546,7 +550,7 @@ pub fn getOptional(self: *const Self, index: u16) ResolveError!?Info {
|
|||
|
||||
pub fn getTag(self: *const Self, index: u16, expected_tag: Info.Tag) ResolveError!Info {
|
||||
const info = try self.get(index);
|
||||
if (@as(Info.Tag, info) != expected_tag) return ResolveError.InvalidConstantType;
|
||||
if (!info.is(expected_tag)) return ResolveError.InvalidConstantType;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue