From 8376d22aa60587392550cdcb3a29f605a49ef43d Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Sat, 28 Aug 2021 23:51:43 +0200 Subject: [PATCH] moving to Java SE16 everything should be done except the attributes --- crates/file-parser/src/lib.rs | 20 +++++++++++++++- crates/file-parser/src/model/cp_info.rs | 31 +++++++++++++++++-------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/crates/file-parser/src/lib.rs b/crates/file-parser/src/lib.rs index 6b7ac86..3ca621f 100644 --- a/crates/file-parser/src/lib.rs +++ b/crates/file-parser/src/lib.rs @@ -165,7 +165,6 @@ impl Parse for ClassFile { impl Parse for CpInfo { fn parse(data: &mut Data, cp: &[CpInfo]) -> Result { let tag = data.u1()?; - dbg!(tag); Ok(match tag { 7 => Self { @@ -261,6 +260,13 @@ impl Parse for CpInfo { descriptor_index: data.cp(cp)?, }), }, + 17 => Self { + tag, + inner: CpInfoInner::Dynamic(cp_info::Dynamic { + bootstrap_method_attr_index: data.u2()?, + name_and_type_index: data.cp(cp)?, + }), + }, 18 => Self { tag, inner: CpInfoInner::InvokeDynamic(cp_info::InvokeDynamic { @@ -268,6 +274,18 @@ impl Parse for CpInfo { name_and_type_index: data.cp(cp)?, }), }, + 19 => Self { + tag, + inner: CpInfoInner::Module(cp_info::Module { + name_index: data.cp(cp)?, + }), + }, + 20 => Self { + tag, + inner: CpInfoInner::Package(cp_info::Package { + name_index: data.cp(cp)?, + }), + }, _ => return Err(ParseErr(format!("Invalid CPInfo tag: {}", tag))), }) } diff --git a/crates/file-parser/src/model/cp_info.rs b/crates/file-parser/src/model/cp_info.rs index 101dd03..8221eae 100644 --- a/crates/file-parser/src/model/cp_info.rs +++ b/crates/file-parser/src/model/cp_info.rs @@ -159,7 +159,6 @@ impl ValidateCpInfo for CpInfoInner { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Class { - /// Entry must be `Utf8` pub name_index: FromPool, } @@ -167,7 +166,6 @@ pub struct Class { pub struct Fieldref { /// May be a class or interface type pub class_index: FromPool, - /// Entry must be `NameAndType` pub name_and_type_index: FromPool, } @@ -175,7 +173,6 @@ pub struct Fieldref { pub struct MethodRef { /// Must be a class type pub class_index: FromPool, - /// Entry must be `NameAndType` pub name_and_type_index: FromPool, } @@ -183,13 +180,11 @@ pub struct MethodRef { pub struct InterfaceMethodref { /// Must be an interface type pub class_index: FromPool, - /// Entry must be `NameAndType` pub name_and_type_index: FromPool, } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct String { - /// Entry must be `Utf8` pub string_index: FromPool, } @@ -226,9 +221,7 @@ pub struct Double { /// Any field or method, without the class it belongs to #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NameAndType { - /// Entry must be `Utf8` pub name_index: FromPool, - /// Entry must be `Utf8` pub descriptor_index: FromPool, } @@ -256,18 +249,33 @@ pub enum MethodHandleIndex { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct MethodType { - /// Entry must be `Utf8` pub descriptor_index: FromPool, } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Dynamic { + /// Must be a valid index into the `bootstrap_methods` array of the bootstrap method table of this class field + pub bootstrap_method_attr_index: u2, + pub name_and_type_index: FromPool, +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct InvokeDynamic { /// Must be a valid index into the `bootstrap_methods` array of the bootstrap method table of this class field pub bootstrap_method_attr_index: u2, - /// Entry must `NameAndType` pub name_and_type_index: FromPool, } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Module { + pub name_index: FromPool, +} + +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Package { + pub name_index: FromPool, +} + // default implementations impl_try_from_cp!( @@ -283,7 +291,10 @@ impl_try_from_cp!( NameAndType, MethodHandle, MethodType, - InvokeDynamic + Dynamic, + InvokeDynamic, + Module, + Package ); impl ValidateCpInfo for Utf8 {