use java_asm_macro::{ReadFrom, WriteInto};
use crate::jvms::attr::Attribute;
#[derive(Clone, Debug, WriteInto)]
pub struct ClassFile {
pub magic: u32,
pub minor_version: u16,
pub major_version: u16,
pub constant_pool_count: u16,
pub constant_pool: Vec<CPInfo>,
pub access_flags: u16,
pub this_class: u16,
pub super_class: u16,
pub interfaces_count: u16,
pub interfaces: Vec<u16>,
pub fields_count: u16,
pub fields: Vec<FieldInfo>,
pub methods_count: u16,
pub methods: Vec<MethodInfo>,
pub attributes_count: u16,
pub attributes: Vec<AttributeInfo>,
}
#[derive(Clone, Debug, WriteInto)]
pub struct CPInfo {
pub tag: u8,
pub info: Const,
}
#[derive(Clone, Debug, WriteInto)]
pub enum Const {
Invalid,
Class { name_index: u16 },
Field { class_index: u16, name_and_type_index: u16 },
Method { class_index: u16, name_and_type_index: u16 },
InterfaceMethod { class_index: u16, name_and_type_index: u16 },
String { string_index: u16 },
Integer { bytes: u32 },
Float { bytes: u32 }, Long { high_bytes: u32, low_bytes: u32 },
Double { high_bytes: u32, low_bytes: u32 }, NameAndType { name_index: u16, descriptor_index: u16 },
Utf8 { length: u16, bytes: Vec<u8> },
MethodHandle { reference_kind: u8, reference_index: u16 },
MethodType { descriptor_index: u16 },
Dynamic { bootstrap_method_attr_index: u16, name_and_type_index: u16 },
InvokeDynamic { bootstrap_method_attr_index: u16, name_and_type_index: u16 },
Module { name_index: u16 },
Package { name_index: u16 },
}
#[derive(Clone, Debug, ReadFrom, WriteInto)]
pub struct FieldInfo {
pub access_flags: u16,
pub name_index: u16,
pub descriptor_index: u16,
pub attributes_count: u16,
#[index(attributes_count)]
pub attributes: Vec<AttributeInfo>,
}
#[derive(Clone, Debug, ReadFrom, WriteInto)]
pub struct MethodInfo {
pub access_flags: u16,
pub name_index: u16,
pub descriptor_index: u16,
pub attributes_count: u16,
#[index(attributes_count)]
pub attributes: Vec<AttributeInfo>,
}
#[derive(Clone, Debug, WriteInto)]
pub struct AttributeInfo {
pub attribute_name_index: u16,
pub attribute_length: u32,
pub info: Attribute,
}