moving to Java SE16

everything should be done except the attributes
This commit is contained in:
nora 2021-08-28 23:51:43 +02:00
parent 456087553a
commit 8376d22aa6
2 changed files with 40 additions and 11 deletions

View file

@ -165,7 +165,6 @@ impl Parse for ClassFile {
impl Parse for CpInfo {
fn parse(data: &mut Data, cp: &[CpInfo]) -> Result<Self> {
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))),
})
}

View file

@ -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<Utf8>,
}
@ -167,7 +166,6 @@ pub struct Class {
pub struct Fieldref {
/// May be a class or interface type
pub class_index: FromPool<Class>,
/// Entry must be `NameAndType`
pub name_and_type_index: FromPool<NameAndType>,
}
@ -175,7 +173,6 @@ pub struct Fieldref {
pub struct MethodRef {
/// Must be a class type
pub class_index: FromPool<Class>,
/// Entry must be `NameAndType`
pub name_and_type_index: FromPool<NameAndType>,
}
@ -183,13 +180,11 @@ pub struct MethodRef {
pub struct InterfaceMethodref {
/// Must be an interface type
pub class_index: FromPool<Class>,
/// Entry must be `NameAndType`
pub name_and_type_index: FromPool<NameAndType>,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct String {
/// Entry must be `Utf8`
pub string_index: FromPool<Utf8>,
}
@ -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<Utf8>,
/// Entry must be `Utf8`
pub descriptor_index: FromPool<Utf8>,
}
@ -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<Utf8>,
}
#[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<NameAndType>,
}
#[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<NameAndType>,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Module {
pub name_index: FromPool<Utf8>,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Package {
pub name_index: FromPool<Utf8>,
}
// 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 {