1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::access_flags::{InnerClassAccessFlag, ParameterAccessFlag};
use crate::opcode::Instruction;

#[derive(Debug)]
pub struct ExceptionTableEntry {
    pub start_pc: u16,
    pub end_pc: u16,
    pub handler_pc: u16,
    pub catch_type: u16
}

#[derive(Debug)]
pub struct LineNumberTableEntry {
    pub start_pc: u16,
    pub line_number: u16
}

#[derive(Debug)]
pub struct InnerClassAttribute {
    pub inner_class_info_index: u16,
    pub outer_class_info_index: u16,
    pub inner_name_index: u16,
    pub inner_class_access_flags: InnerClassAccessFlag
}

#[derive(Debug)]
pub struct ParameterAttribute {
    pub name_index: u16,
    pub access_flags: ParameterAccessFlag
}

#[derive(Debug)]
pub struct BootstrapMethodAttribute {
    pub bootstrap_method_ref: u16,
    pub num_bootstrap_arguments: u16,
    pub bootstrap_arguments: Vec<u16>
}

#[derive(Debug)]
pub enum Attribute {
    ConstantValue {
        attribute_name_index: u16,
        attribute_length: u32,
        constantvalue_index: u16
    },
    Code {
        attribute_name_index: u16,
        attribute_length: u32,
        max_stack: u16,
        max_locals: u16,
        code_length: u32,
        code: Vec<Instruction>,
        exception_table_length: u16,
        exception_table: Vec<ExceptionTableEntry>,
        attributes_count: u16,
        attributes: Vec<Attribute>
    },
    InnerClasses {
        attribute_name_index: u16,
        attribute_length: u32,
        number_of_classes: u16,
        classes: Vec<InnerClassAttribute>
    },
    SourceFile {
        attribute_name_index: u16,
        attribute_length: u32,
        sourcefile_index: u16
    },
    LineNumberTable {
        attribute_name_index: u16,
        attribute_length: u32,
        line_number_table_length: u16,
        line_number_table: Vec<LineNumberTableEntry>
    },
    BootstrapMethods {
        attribute_name_index: u16,
        attribute_length: u32,
        num_bootstrap_methods: u16,
        bootstrap_methods: Vec<BootstrapMethodAttribute>
    },
    MethodParameters {
        attribute_name_index: u16,
        attribute_length: u32,
        parameters_count: u8,
        parameters: Vec<ParameterAttribute>
    },
    NestMembers {
        attribute_name_index: u16,
        attribute_length: u32,
        number_of_classes: u16,
        classes: Vec<u16>
    }
}