I need to make smaller commits
This commit is contained in:
parent
64eef60c4e
commit
0c54a1d7e1
8 changed files with 377 additions and 83 deletions
|
@ -5,7 +5,7 @@ use core::str::Utf8Error;
|
|||
|
||||
use crate::accessmasks::*;
|
||||
use crate::bytecode::Bytecode;
|
||||
use crate::constantpool::{ ConstantFieldRefInfo, ConstantPoolInfo, ConstantUtf8Info, ConstantStringInfo, ConstantMethodRefInfo, ConstantClassInfo, ConstantNameAndTypeInfo, ConstantIntegerInfo, ConstantLongInfo };
|
||||
use crate::constantpool::{ ConstantFieldRefInfo, ConstantPoolInfo, ConstantUtf8Info, ConstantStringInfo, ConstantMethodRefInfo, ConstantFloatInfo, ConstantClassInfo, ConstantNameAndTypeInfo, ConstantIntegerInfo, ConstantLongInfo };
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
@ -246,6 +246,15 @@ impl JavaClassFile {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn pool_float_entry(&self, index: u16) -> Result<&ConstantFloatInfo, Error> {
|
||||
let pool_entry = self.pool_entry(index)?;
|
||||
|
||||
return match pool_entry {
|
||||
ConstantPoolInfo::Float(data) => Ok(data),
|
||||
_ => Err(Error::BadFileError(format!("Expected constant pool entry {} in class {} to be of type Float but found {:?}", index, self.get_classname()?, pool_entry)))
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pool_long_entry(&self, index: u16) -> Result<&ConstantLongInfo, Error> {
|
||||
let pool_entry = self.pool_entry(index)?;
|
||||
|
||||
|
@ -282,6 +291,12 @@ impl JavaClassFile {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn gather_float(&self, index: u16) -> Result<f32, Error> {
|
||||
let float = self.pool_float_entry(index)?;
|
||||
|
||||
return Ok(float.value);
|
||||
}
|
||||
|
||||
pub fn gather_string(&self, index: u16) -> Result<&String, Error> {
|
||||
let string = self.pool_string_entry(index)?;
|
||||
|
||||
|
@ -766,17 +781,17 @@ impl Into<String> for &AbstractTypeKind {
|
|||
impl From<&str> for AbstractTypeKind {
|
||||
fn from(value: &str) -> Self {
|
||||
match value.chars().nth(0).unwrap() {
|
||||
'V' => AbstractTypeKind::Void(),
|
||||
'B' => AbstractTypeKind::Byte(),
|
||||
'C' => AbstractTypeKind::Char(),
|
||||
'D' => AbstractTypeKind::Double(),
|
||||
'F' => AbstractTypeKind::Float(),
|
||||
'I' => AbstractTypeKind::Int(),
|
||||
'J' => AbstractTypeKind::Long(),
|
||||
'S' => AbstractTypeKind::Short(),
|
||||
'Z' => AbstractTypeKind::Boolean(),
|
||||
'L' => todo!(),
|
||||
_ => todo!(),
|
||||
'V' => AbstractTypeKind::Void(),
|
||||
'B' => AbstractTypeKind::Byte(),
|
||||
'C' => AbstractTypeKind::Char(),
|
||||
'D' => AbstractTypeKind::Double(),
|
||||
'F' => AbstractTypeKind::Float(),
|
||||
'I' => AbstractTypeKind::Int(),
|
||||
'J' => AbstractTypeKind::Long(),
|
||||
'S' => AbstractTypeKind::Short(),
|
||||
'Z' => AbstractTypeKind::Boolean(),
|
||||
'L' => AbstractTypeKind::Classname(value.chars().skip(1).map_while(|c| if c != ';' { Some(c) } else { None } ).collect()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue