Format code attribute exception table
This commit is contained in:
parent
0fbdea320c
commit
6971dce705
1 changed files with 43 additions and 10 deletions
|
|
@ -308,18 +308,18 @@ pub const AttributeInfo = union(enum) {
|
|||
try w.print("{d}: 0x{x}\n", .{ i, instr });
|
||||
}
|
||||
|
||||
//try w.splatByteAll(' ', depth * indent);
|
||||
//_ = try w.write("exception_table:\n");
|
||||
//var exception_indent = indent;
|
||||
//for (attr.exception_table, 0..) |*exception, i| {
|
||||
// exception_indent += 1;
|
||||
// defer exception_indent -= 1;
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("exception_table:\n");
|
||||
var exception_indent = indent;
|
||||
for (attr.exception_table, 0..) |*exception, i| {
|
||||
exception_indent += 1;
|
||||
defer exception_indent -= 1;
|
||||
|
||||
// try w.splatByteAll(' ', depth * exception_indent);
|
||||
// try w.print("{d}:\n", .{ i });
|
||||
try w.splatByteAll(' ', depth * exception_indent);
|
||||
try w.print("{d}:\n", .{ i });
|
||||
|
||||
// try self.formatExceptionHandler(w, depth, exception_indent + 1, exception);
|
||||
//}
|
||||
try exception.indentedFormat(w, depth, exception_indent + 1, constant_pool);
|
||||
}
|
||||
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("attributes:\n");
|
||||
|
|
@ -569,6 +569,39 @@ pub const Code = struct {
|
|||
end_pc: u16,
|
||||
handler_pc: u16,
|
||||
catch_type: u16,
|
||||
|
||||
pub fn indentedFormat(
|
||||
self: *const ExceptionHandler,
|
||||
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("end_pc: {d}\n", .{ self.end_pc });
|
||||
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
try w.print("handler_pc: {d}\n", .{ self.handler_pc });
|
||||
|
||||
const catch_type = self.catchType(constant_pool) catch return error.WriteFailed;
|
||||
if (catch_type) |ct| {
|
||||
try w.splatByteAll(' ', depth * indent);
|
||||
_ = try w.write("catch_type:\n");
|
||||
try ct.indentedFormat(w, depth, indent + 1, constant_pool);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn catchType(self: *const ExceptionHandler, constant_pool: []const ?ConstantPoolInfo) ResolveError!?ConstantPoolInfo {
|
||||
if (self.catch_type == 0) return null;
|
||||
const catch_type = self.catch_type - 1;
|
||||
if (catch_type >= constant_pool.len) return ResolveError.InvalidConstantPoolIndex;
|
||||
const cp_info = constant_pool[catch_type];
|
||||
if (cp_info == null or @as(ConstantPoolInfo.Tag, cp_info.?) != .class) return ResolveError.InvalidConstantType;
|
||||
return cp_info.?;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn parse(input: *std.Io.Reader, constant_pool: []const ?ConstantPoolInfo, allocator: std.mem.Allocator) (ParseError || ResolveError)!Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue