classfile_parser/attribute_info/
types.rs

1#[derive(Clone, Debug)]
2pub struct AttributeInfo {
3    pub attribute_name_index: u16,
4    pub attribute_length: u32,
5    pub info: Vec<u8>,
6}
7
8#[derive(Clone, Debug)]
9pub struct ExceptionEntry {
10    pub start_pc: u16,
11    pub end_pc: u16,
12    pub handler_pc: u16,
13    pub catch_type: u16,
14}
15
16#[derive(Clone, Debug)]
17pub struct CodeAttribute {
18    pub max_stack: u16,
19    pub max_locals: u16,
20    pub code_length: u32,
21    pub code: Vec<u8>,
22    pub exception_table_length: u16,
23    pub exception_table: Vec<ExceptionEntry>,
24    pub attributes_count: u16,
25    pub attributes: Vec<AttributeInfo>,
26}
27
28#[derive(Clone, Debug)]
29pub struct MethodParametersAttribute {
30    pub parameters_count: u8,
31    pub parameters: Vec<ParameterAttribute>,
32}
33
34#[derive(Clone, Debug)]
35pub struct ParameterAttribute {
36    pub name_index: u16,
37    pub access_flags: u16,
38}
39
40#[derive(Clone, Debug)]
41pub enum VerificationTypeInfo {
42    Top,
43    Integer,
44    Float,
45    Double,
46    Long,
47    Null,
48    UninitializedThis,
49    Object {
50        /// An index into the constant pool for the class of the object
51        class: u16,
52    },
53    Uninitialized {
54        /// Offset into associated code array of a new instruction
55        /// that created the object being stored here.
56        offset: u16,
57    },
58}
59
60#[derive(Clone, Debug)]
61pub enum StackMapFrame {
62    SameFrame {
63        frame_type: u8,
64    },
65    SameLocals1StackItemFrame {
66        frame_type: u8,
67        stack: VerificationTypeInfo,
68    },
69    SameLocals1StackItemFrameExtended {
70        frame_type: u8,
71        offset_delta: u16,
72        stack: VerificationTypeInfo,
73    },
74    ChopFrame {
75        frame_type: u8,
76        offset_delta: u16,
77    },
78    SameFrameExtended {
79        frame_type: u8,
80        offset_delta: u16,
81    },
82    AppendFrame {
83        frame_type: u8,
84        offset_delta: u16,
85        locals: Vec<VerificationTypeInfo>,
86    },
87    FullFrame {
88        frame_type: u8,
89        offset_delta: u16,
90        number_of_locals: u16,
91        locals: Vec<VerificationTypeInfo>,
92        number_of_stack_items: u16,
93        stack: Vec<VerificationTypeInfo>,
94    },
95}
96
97#[derive(Clone, Debug)]
98pub struct StackMapTableAttribute {
99    pub number_of_entries: u16,
100    pub entries: Vec<StackMapFrame>,
101}
102
103#[derive(Clone, Debug)]
104pub struct ExceptionsAttribute {
105    pub exception_table_length: u16,
106    pub exception_table: Vec<u16>,
107}
108
109#[derive(Clone, Debug)]
110pub struct ConstantValueAttribute {
111    pub constant_value_index: u16,
112}
113
114#[derive(Clone, Debug)]
115pub struct BootstrapMethod {
116    pub bootstrap_method_ref: u16,
117    pub num_bootstrap_arguments: u16,
118    pub bootstrap_arguments: Vec<u16>,
119}
120
121#[derive(Clone, Debug)]
122pub struct BootstrapMethodsAttribute {
123    pub num_bootstrap_methods: u16,
124    pub bootstrap_methods: Vec<BootstrapMethod>,
125}
126
127/// The SourceFile attribute is an optional fixed-length attribute in the attributes table of a ClassFile structure (ยง4.1).
128///
129/// There may be at most one SourceFile attribute in the attributes table of a ClassFile structure.
130/// [see more](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.10)
131#[derive(Copy, Clone, Debug, Eq, PartialEq)]
132pub struct SourceFileAttribute {
133    /// The value of the attribute_name_index item must be a valid index into the constant_pool table.
134    /// The constant_pool entry at that index must be a CONSTANT_Utf8_info structure
135    /// representing the string "SourceFile".
136    pub attribute_name_index: u16,
137    /// The value of the attribute_length item must be two.
138    pub attribute_length: u32,
139    /// The value of the sourcefile_index item must be a valid index into the constant_pool table.
140    /// The constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing a string.
141    pub sourcefile_index: u16,
142}