Format local variable table attribute
This commit is contained in:
parent
5c816759bb
commit
b8c63f726e
1 changed files with 54 additions and 1 deletions
|
|
@ -411,7 +411,20 @@ pub const AttributeInfo = union(enum) {
|
|||
try line_number.indentedFormat(w, depth, line_number_indent + 1);
|
||||
}
|
||||
},
|
||||
//.local_variable_table,
|
||||
.local_variable_table => |attr| {
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("local_variable_table:\n");
|
||||
var local_variable_indent = indent;
|
||||
for (attr.local_variable_table, 0..) |*local_variable, i| {
|
||||
local_variable_indent += 1;
|
||||
defer local_variable_indent -= 1;
|
||||
|
||||
try w.splatByteAll(' ', depth * local_variable_indent);
|
||||
try w.print("{d}:\n", .{ i });
|
||||
|
||||
try local_variable.indentedFormat(w, depth, local_variable_indent + 1, constant_pool);
|
||||
}
|
||||
},
|
||||
//.local_variable_type_table,
|
||||
.deprecated => {},
|
||||
//.runtime_visible_annotations,
|
||||
|
|
@ -1128,6 +1141,46 @@ pub const LocalVariableTable = struct {
|
|||
name_index: u16,
|
||||
descriptor_index: u16,
|
||||
index: u16,
|
||||
|
||||
pub fn indentedFormat(
|
||||
self: *const LocalVariable,
|
||||
w: *std.Io.Writer,
|
||||
depth: usize,
|
||||
indent: u8,
|
||||
constant_pool: []const ?ConstantPoolInfo,
|
||||
) std.Io.Writer.Error!void {
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
try w.print("start_pc: {d}\n", .{ self.start_pc });
|
||||
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
try w.print("length: {d}\n", .{ self.length });
|
||||
|
||||
const name_ = self.name(constant_pool) catch return error.WriteFailed;
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("name:\n");
|
||||
try name_.indentedFormat(w, depth, indent + 1, constant_pool);
|
||||
|
||||
const descriptor_ = self.descriptor(constant_pool) catch return error.WriteFailed;
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("descriptor:\n");
|
||||
try descriptor_.indentedFormat(w, depth, indent + 1, constant_pool);
|
||||
}
|
||||
|
||||
pub fn name(self: *const LocalVariable, constant_pool: []const ?ConstantPoolInfo) ResolveError!ConstantPoolInfo {
|
||||
const name_index = self.name_index - 1;
|
||||
if (name_index >= constant_pool.len) return ResolveError.InvalidConstantPoolIndex;
|
||||
const cp_info = constant_pool[name_index];
|
||||
if (cp_info == null or @as(ConstantPoolInfo.Tag, cp_info.?) != .utf8) return ResolveError.InvalidConstantType;
|
||||
return cp_info.?;
|
||||
}
|
||||
|
||||
pub fn descriptor(self: *const LocalVariable, constant_pool: []const ?ConstantPoolInfo) ResolveError!ConstantPoolInfo {
|
||||
const descriptor_index = self.descriptor_index - 1;
|
||||
if (descriptor_index >= constant_pool.len) return ResolveError.InvalidConstantPoolIndex;
|
||||
const cp_info = constant_pool[descriptor_index];
|
||||
if (cp_info == null or @as(ConstantPoolInfo.Tag, cp_info.?) != .utf8) return ResolveError.InvalidConstantType;
|
||||
return cp_info.?;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue