1use crate::structs::{
2 Annotation, BootstrapMethod, ExceptionTableEntry, InnerClass, LineNumber, LocalVar,
3 LocalVariable, LocalVariableType, MethodParameter, ModuleExports, ModuleOpens, ModuleProvides,
4 ModuleRequires, RecordComponent, StackMapFrame, TypeAnnotation,
5};
6
7mod instructions;
8pub use instructions::Instruction;
9
10#[derive(Debug, Clone, Copy, PartialEq)]
11pub enum AccessFlag {
12 Abstract,
16 Annotation,
19 Bridge,
21 Enum,
25 Final,
31 Interface,
34 Mandated,
38 Module,
40 Native,
42 Open,
44 Public,
48 Private,
51 Protected,
54 Static,
57 StaticPhase,
59 Strict,
61 Super,
63 Synchronized,
65 Synthetic,
67 Transient,
69 Transitive,
71 VarArgs,
73 Volatile,
75}
76
77#[derive(Debug, Clone)]
78pub enum Constant {
79 Class {
80 name_index: u16,
81 },
82 Double(f64),
83 Dynamic {
84 bootstrap_method_attr_index: u16,
85 name_and_type_index: u16,
86 },
87 Fieldref {
88 class_index: u16,
89 name_and_type_index: u16,
90 },
91 Float(f32),
92 Integer(i32),
93 InterfaceMethodref {
94 class_index: u16,
95 name_and_type_index: u16,
96 },
97 Invalid,
99 InvokeDynamic {
100 bootstrap_method_attr_index: u16,
101 name_and_type_index: u16,
102 },
103 Long(i64),
104 MethodHandle {
105 reference_kind: u8,
106 reference_index: u16,
107 },
108 Methodref {
109 class_index: u16,
110 name_and_type_index: u16,
111 },
112 MethodType {
113 descriptor_index: u16,
114 },
115 Module {
116 name_index: u16,
117 },
118 NameAndType {
119 name_index: u16,
120 descriptor_index: u16,
121 },
122 Package {
123 name_index: u16,
124 },
125 String {
126 string_index: u16,
127 },
128 Utf8(String),
130}
131
132impl std::fmt::Display for Constant {
133 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
134 match self {
135 Constant::Class { name_index } => write!(f, "Constant::Class #{name_index}"),
136 Constant::Double(double) => write!(f, "Constant::Double {double}"),
137 Constant::Dynamic {
138 bootstrap_method_attr_index,
139 name_and_type_index,
140 } => write!(
141 f,
142 "Constant::Dynamic #{bootstrap_method_attr_index}, #{name_and_type_index}"
143 ),
144 Constant::Fieldref {
145 class_index,
146 name_and_type_index,
147 } => write!(
148 f,
149 "Constant::Fieldref #{class_index}, #{name_and_type_index}"
150 ),
151 Constant::Float(float) => write!(f, "Constant::Float {float}"),
152 Constant::Integer(int) => write!(f, "Constant::Integer {int}"),
153 Constant::InterfaceMethodref {
154 class_index,
155 name_and_type_index,
156 } => write!(
157 f,
158 "Constant::InterfaceMethodref #{class_index}, #{name_and_type_index}"
159 ),
160 Constant::Invalid => write!(f, "Constant::Invalid"),
161 Constant::InvokeDynamic {
162 bootstrap_method_attr_index,
163 name_and_type_index,
164 } => write!(
165 f,
166 "Constant::InvokeDynamic #{bootstrap_method_attr_index}, #{name_and_type_index}"
167 ),
168 Constant::Long(long) => write!(f, "Constant::Long {long}"),
169 Constant::MethodHandle {
170 reference_kind,
171 reference_index,
172 } => write!(
173 f,
174 "Constant::MethodHandle #{reference_kind}, #{reference_index}"
175 ),
176 Constant::Methodref {
177 class_index,
178 name_and_type_index,
179 } => write!(
180 f,
181 "Constant::Methodref #{class_index}, #{name_and_type_index}"
182 ),
183 Constant::MethodType { descriptor_index } => {
184 write!(f, "Constant::MethodType #{descriptor_index}")
185 }
186 Constant::Module { name_index } => write!(f, "Constant::Module #{name_index}"),
187 Constant::NameAndType {
188 name_index,
189 descriptor_index,
190 } => write!(
191 f,
192 "Constant::NameAndType #{name_index}, #{descriptor_index}"
193 ),
194 Constant::Package { name_index } => write!(f, "Constant::Package #{name_index}"),
195 Constant::String { string_index } => write!(f, "Constant::String #{string_index}"),
196 Constant::Utf8(s) => write!(f, "Constant::Utf8({s})"),
197 }
198 }
199}
200
201#[derive(Debug, Clone)]
202pub enum Attribute {
203 AnnotationDefault(ElementValue),
204 BootstrapMethods(Vec<BootstrapMethod>),
205 Code {
206 code: Vec<Instruction>,
207 max_stack: u16,
208 max_locals: u16,
209 exception_table: Vec<ExceptionTableEntry>,
210 attributes: Vec<Attribute>,
211 },
212 ConstantValue {
213 constantvalue_index: u16,
214 },
215 Deprecated,
216 EnclosingMethod {
217 class_index: u16,
218 method_index: u16,
219 },
220 Exceptions(Vec<u16>),
221 InnerClasses(Vec<InnerClass>),
222 LineNumberTable(Vec<LineNumber>),
223 LocalVariableTable(Vec<LocalVariable>),
224 LocalVariableTypeTable(Vec<LocalVariableType>),
225 MethodParameters(Vec<MethodParameter>),
226 Module {
227 module_name_index: u16,
228 module_flags: Vec<AccessFlag>,
229 module_version_index: u16,
230 requires: Vec<ModuleRequires>,
231 exports: Vec<ModuleExports>,
232 opens: Vec<ModuleOpens>,
233 uses: Vec<u16>,
234 provides: Vec<ModuleProvides>,
235 },
236 ModuleMainClass(u16),
237 ModulePackages(Vec<u16>),
238 NestHost(u16),
239 NestMembers(Vec<u16>),
240 PermittedSubclasses(Vec<u16>),
241 Record(Vec<RecordComponent>),
242 RuntimeInvisibleAnnotations(Vec<Annotation>),
243 RuntimeInvisibleParameterAnnotations(Vec<Vec<Annotation>>),
244 RuntimeInvisibleTypeAnnotations(Vec<TypeAnnotation>),
245 RuntimeVisibleAnnotations(Vec<Annotation>),
246 RuntimeVisibleParameterAnnotations(Vec<Vec<Annotation>>),
247 RuntimeVisibleTypeAnnotations(Vec<TypeAnnotation>),
248 Signature {
249 signature_index: u16,
250 },
251 SourceDebugExtension {
252 debug_extension: Vec<u8>,
253 },
254 SourceFile {
255 sourcefile_index: u16,
256 },
257 StackMapTable(Vec<StackMapFrame>),
258 Synthetic,
259 Unknown {
260 name: String,
261 data: Vec<u8>,
262 },
263}
264
265#[derive(Debug, Clone)]
266pub enum StackMapFrameType {
267 AppendFrame(u8),
268 ChopFrame(u8),
269 FullFrame,
270 SameFrame(u8),
271 SameFrameExtended,
272 SameLocals1StackItemFrame(u8),
273 SameLocals1StackItemFrameExtended,
274}
275
276#[derive(Debug, Clone)]
277pub enum VerificationType {
278 Double,
279 Float,
280 Integer,
281 Long,
282 Null,
283 Object { cpool_index: u16 },
284 Top,
285 Uninitialized { offset: u16 },
286 UninitializedThis,
287}
288
289#[derive(Debug, Clone)]
290pub enum ElementValue {
291 AnnotationValue(Annotation),
292 ArrayValue(Vec<ElementValue>),
293 ClassInfoIndex(u16),
294 ConstValueIndex {
295 tag: u8,
296 const_value_index: u16,
297 },
298 EnumConstValue {
299 type_name_index: u16,
300 const_name_index: u16,
301 },
302}
303
304#[derive(Debug, Clone)]
305pub enum TargetInfo {
306 TypeParameter {
307 target_type: u8,
308 type_parameter_index: u8,
309 },
310 Supertype {
311 supertype_index: u16,
312 },
313 TypeParameterBound {
314 target_type: u8,
315 type_parameter_index: u8,
316 bound_index: u8,
317 },
318 Empty(u8),
319 FormalParameter {
320 formal_parameter_index: u8,
321 },
322 Throws {
323 throws_type_index: u16,
324 },
325 Localvar {
326 target_type: u8,
327 table: Vec<LocalVar>,
328 },
329 Catch {
330 exception_table_index: u16,
331 },
332 Offset {
333 target_type: u8,
334 offset: u16,
335 },
336 TypeArgument {
337 target_type: u8,
338 offset: u16,
339 type_argument_index: u8,
340 },
341}