Static object creation
This commit is contained in:
parent
8642dcdd6a
commit
6c0fbd179a
6 changed files with 160 additions and 29 deletions
|
@ -1,7 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::accessmasks::FieldAccessFlag;
|
||||
use crate::stackframe::Value;
|
||||
use crate::classfile::{ AbstractTypeDescription, MethodInfo };
|
||||
use crate::classfile::{ JavaClassFile, AbstractTypeDescription, MethodInfo };
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HeapArea {
|
||||
|
@ -54,13 +55,46 @@ pub struct StaticArea {
|
|||
static_objects: HashMap<String, StaticObject>,
|
||||
}
|
||||
|
||||
impl StaticArea {
|
||||
pub fn make(&mut self, class: &JavaClassFile, class_index: usize) {
|
||||
let mut fields = Vec::new();
|
||||
|
||||
for field in &class.fields {
|
||||
if field.access_flags & FieldAccessFlag::Static {
|
||||
fields.push(
|
||||
StaticField {
|
||||
name: field.name.clone(),
|
||||
type_description: field.descriptor.clone(),
|
||||
value: Value::default_for(field.descriptor),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
let new_object = StaticObject {
|
||||
class_index,
|
||||
fields: fields.into_boxed_slice(),
|
||||
methods: Box::new([]),
|
||||
};
|
||||
|
||||
let _ = self.static_objects.insert(class.get_classname().unwrap(), new_object);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StaticObject {
|
||||
pub class_index: usize,
|
||||
pub fields: Box<[ObjectField]>,
|
||||
pub fields: Box<[StaticField]>,
|
||||
pub methods: Box<[MethodInfo]>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StaticField {
|
||||
pub name: String,
|
||||
pub type_description: AbstractTypeDescription,
|
||||
pub value: Value,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectField {
|
||||
pub type_description: AbstractTypeDescription,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue