use java_asm_macro::{ReadFrom, WriteInto};
use crate::jvms::attr::annotation::{AnnotationElementValueInfo, AnnotationInfo, ParameterAnnotationInfo};
use crate::jvms::attr::module::{ModuleExports, ModuleOpens, ModuleProvides, ModuleRequires};
use crate::jvms::attr::type_annotation::TypeAnnotation;
use crate::jvms::element::AttributeInfo;
use crate::node::element::LabelNode;
pub mod annotation;
pub mod module;
pub mod type_annotation;
#[derive(Clone, Debug, WriteInto)]
pub enum Attribute {
Custom(Vec<u8>),
ConstantValue { constantvalue_index: u16 },
Code {
max_stack: u16,
max_locals: u16,
code_length: u32,
code: Vec<u8>,
exception_table_length: u16,
exception_table: Vec<ExceptionTable>,
attributes_count: u16,
attributes: Vec<AttributeInfo>,
},
StackMapTable {
number_of_entries: u16,
entries: Vec<StackMapFrame>,
},
Exceptions {
number_of_exceptions: u16,
exception_index_table: Vec<u16>,
},
InnerClasses {
number_of_classes: u16,
classes: Vec<InnerClassInfo>,
},
EnclosingMethod {
class_index: u16,
method_index: u16,
},
Synthetic,
Signature {
signature_index: u16,
},
SourceFile {
sourcefile_index: u16,
},
SourceDebugExtension {
debug_extension: Vec<u8>,
},
LineNumberTable {
line_number_table_length: u16,
line_number_table: Vec<LineNumberTableInfo>,
},
LocalVariableTable {
local_variable_table_length: u16,
local_variable_table: Vec<LocalVariableTableInfo>,
},
LocalVariableTypeTable {
local_variable_type_table_length: u16,
local_variable_table: Vec<LocalVariableTypeTableInfo>,
},
Deprecated,
RuntimeVisibleAnnotations {
num_annotations: u16,
annotations: Vec<AnnotationInfo>,
},
RuntimeInvisibleAnnotations {
num_annotations: u16,
annotations: Vec<AnnotationInfo>,
},
RuntimeVisibleParameterAnnotations {
num_parameters: u8,
parameter_annotations: Vec<ParameterAnnotationInfo>,
},
RuntimeInvisibleParameterAnnotations {
num_parameters: u8,
parameter_annotations: Vec<ParameterAnnotationInfo>,
},
RuntimeVisibleTypeAnnotations {
num_parameters: u16,
annotations: Vec<TypeAnnotation>,
},
RuntimeInvisibleTypeAnnotations {
num_parameters: u16,
annotations: Vec<TypeAnnotation>,
},
AnnotationDefault {
default_value: AnnotationElementValueInfo,
},
BootstrapMethods {
num_bootstrap_methods: u16,
bootstrap_methods: Vec<BootstrapMethod>,
},
MethodParameters {
parameters_count: u8,
parameters: Vec<MethodParameter>,
},
Module {
module_name_index: u16,
module_flags: u16,
module_version_index: u16,
requires_count: u16,
requires: Vec<ModuleRequires>,
exports_count: u16,
exports: Vec<ModuleExports>,
opens_count: u16,
opens: Vec<ModuleOpens>,
uses_count: u16,
uses_index: Vec<u16>,
provides_count: u16,
provides: Vec<ModuleProvides>,
},
ModulePackages {
package_count: u16,
package_index: Vec<u16>,
},
ModuleMainClass {
main_class_index: u16,
},
NestHost {
host_class_index: u16,
},
NestMembers {
number_of_classes: u16,
classes: Vec<u16>,
},
Record {
components_count: u16,
components: Vec<RecordComponentInfo>,
},
PermittedSubclasses {
number_of_classes: u16,
classes: Vec<u16>,
},
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct InnerClassInfo {
pub inner_class_info_index: u16,
pub outer_class_info_index: u16,
pub inner_name_index: u16,
pub inner_class_access_flags: u16,
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct LineNumberTableInfo {
pub start_pc: LabelNode,
pub line_number: u16,
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct LocalVariableTableInfo {
pub start_pc: LabelNode,
pub length: u16,
pub name_index: u16,
pub descriptor_index: u16,
pub index: u16,
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct LocalVariableTypeTableInfo {
pub start_pc: LabelNode,
pub length: u16,
pub name_index: u16,
pub signature_index: u16,
pub index: u16,
}
#[derive(Clone, Copy, Debug, WriteInto)]
pub enum VerificationTypeInfo {
Top { tag: u8 },
Integer { tag: u8 },
Float { tag: u8 },
Null { tag: u8 },
UninitializedThis { tag: u8 },
Object { tag: u8, cpool_index: u16 },
Uninitialized { tag: u8, offset: u16 },
Long { tag: u8 },
Double { tag: u8 },
}
#[derive(Clone, Debug, WriteInto)]
pub enum StackMapFrame {
SameFrame { frame_type: u8 },
SameFrameExtended { frame_type: u8, offset_delta: u16 },
SameLocals1StackItemFrame {
frame_type: u8,
verification_type_info: VerificationTypeInfo,
},
SameLocals1StackItemFrameExtended {
frame_type: u8,
offset_delta: u16,
verification_type_info: VerificationTypeInfo,
},
ChopFrame { frame_type: u8, offset_delta: u16 },
AppendFrame {
frame_type: u8,
offset_delta: u16,
locals: Vec<VerificationTypeInfo>,
},
FullFrame {
frame_type: u8,
offset_delta: u16,
number_of_locals: u16,
locals: Vec<VerificationTypeInfo>,
number_of_stack_items: u16,
stack: Vec<VerificationTypeInfo>,
},
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct ExceptionTable {
pub start_pc: LabelNode,
pub end_pc: LabelNode,
pub handler_pc: LabelNode,
pub catch_type: u16,
}
#[derive(Clone, Debug, ReadFrom, WriteInto)]
pub struct BootstrapMethod {
pub bootstrap_method_ref: u16,
pub num_bootstrap_arguments: u16,
#[index(num_bootstrap_arguments)]
pub bootstrap_arguments: Vec<u16>,
}
#[derive(Clone, Copy, Debug, ReadFrom, WriteInto)]
pub struct MethodParameter {
pub name_index: u16,
pub access_flags: u16,
}
#[derive(Clone, Debug, ReadFrom, WriteInto)]
pub struct RecordComponentInfo {
pub name_index: u16,
pub descriptor_index: u16,
pub attributes_count: u16,
#[index(attributes_count)]
pub attributes: Vec<AttributeInfo>,
}