From a451327a6a6cfe4ec3a608018f63fb363c7d9e05 Mon Sep 17 00:00:00 2001 From: ktkk Date: Mon, 6 Jul 2026 15:19:00 +0000 Subject: [PATCH] Add annotation attribute constant pool info getters --- src/Class/AttributeInfo.zig | 39 ++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Class/AttributeInfo.zig b/src/Class/AttributeInfo.zig index 5814295..6bbf7b5 100644 --- a/src/Class/AttributeInfo.zig +++ b/src/Class/AttributeInfo.zig @@ -730,6 +730,11 @@ pub const StackMapTable = struct { .offset_delta = try input.takeInt(u16, .big), }, }, + 251 => .{ + .same_frame_extended = .{ + .offset_delta = try input.takeInt(u16, .big), + }, + }, 252...254 => blk: { const offset_delta = try input.takeInt(u16, .big); @@ -796,12 +801,8 @@ pub const StackMapTable = struct { long, null, uninitialized_this, - object: struct { - cpool_index: u16, - }, - uninitialized: struct { - cpool_index: u16, - }, + object: Object, + uninitialized: Uninitialized, pub const Tag = enum(u8) { top = 0, @@ -815,6 +816,18 @@ pub const StackMapTable = struct { uninitialized = 8, }; + pub const Object = struct { + cpool_index: u16, + + pub fn class(self: *const Object, constant_pool: ConstantPool) ResolveError!ConstantPool.Info { + return constant_pool.getTag(self.cpool_index, .class); + } + }; + + pub const Uninitialized = struct { + offset: u16, + }; + pub fn parse(input: *std.Io.Reader) ParseError!VerificationTypeInfo { const tag_byte = try input.takeByte(); const tag = std.enums.fromInt(StackMapTable.VerificationTypeInfo.Tag, tag_byte) orelse return ParseError.InvalidTag; @@ -834,7 +847,7 @@ pub const StackMapTable = struct { }, .uninitialized => .{ .uninitialized = .{ - .cpool_index = try input.takeInt(u16, .big), + .offset = try input.takeInt(u16, .big), }, }, }; @@ -1301,12 +1314,20 @@ pub const ElementValue = union(enum) { pub const ElementValuePair = struct { element_name_index: u16, value: ElementValue, + + const Self = @This(); + + pub fn elementName(self: *const Self, constant_pool: ConstantPool) ResolveError!ConstantPool.Info { + return constant_pool.getTag(self.element_name_index, .utf8); + } }; pub const Annotation = struct { type_index: u16, element_value_pairs: []ElementValuePair, + const Self = @This(); + pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Annotation { const type_index = try input.takeInt(u16, .big); @@ -1332,6 +1353,10 @@ pub const Annotation = struct { } allocator.free(self.element_value_pairs); } + + pub fn @"type"(self: *const Self, constant_pool: ConstantPool) ResolveError!ConstantPool.Info { + return constant_pool.getTag(self.type_index, .utf8); + } }; pub const RuntimeVisibleAnnotations = struct {