Skip to content

Commit

Permalink
Merge pull request #107 from cmjava2023/feat_parse_super_class
Browse files Browse the repository at this point in the history
feat(btyecode_parser): now also parse super class
  • Loading branch information
liketechnik authored Jan 10, 2024
2 parents dce13c0 + 66b37fe commit b8e7ec3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub struct BytecodeClass {
pub instance_fields: Vec<FieldDescriptor>,
// TODO flags
pub class_identifier: ClassIdentifier,
pub super_class: Option<Rc<dyn Class>>,
pub super_class: Rc<dyn Class>,
// TODO how are interfaces represented?
pub interfaces: Vec<Rc<dyn std::any::Any>>,
// TODO attributes
Expand Down
2 changes: 1 addition & 1 deletion src/class/bytecode_classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Class for BytecodeClass {
}

fn super_class(&self) -> Option<Rc<dyn Class>> {
self.super_class.clone()
Some(self.super_class.clone())
}

fn interfaces(&self) -> &[Rc<dyn std::any::Any>] {
Expand Down
9 changes: 7 additions & 2 deletions src/classloader/class_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,19 @@ pub fn create_bytecode_class(
&runtime_cp[remove_cp_offset(class_file.this_class as usize)];
let class_identifier = parse_class_identifier(class.as_class().unwrap());

let super_class = None;
let super_class_name: &RuntimeCPEntry =
&runtime_cp[remove_cp_offset(class_file.super_class as usize)];
let super_class_identifier =
parse_class_identifier(super_class_name.as_class().unwrap());
let super_class = heap.find_class(&super_class_identifier).unwrap();
// let super_class = None;
let interfaces = Vec::new();
BytecodeClass {
methods,
static_fields,
instance_fields,
class_identifier,
super_class,
super_class: super_class.clone(),
interfaces,
}
}

0 comments on commit b8e7ec3

Please sign in to comment.