#[derive(Debug, Clone, Default)]
pub(in crate::decompiler) struct SlotTypes {
pub arguments: Vec<&'static str>,
pub locals: Vec<&'static str>,
pub statics: Vec<&'static str>,
}
impl SlotTypes {
pub(in crate::decompiler) fn argument_type(&self, index: usize) -> Option<&'static str> {
self.arguments
.get(index)
.copied()
.filter(|ty| !ty.is_empty())
}
pub(super) fn declaration_type(&self, name: &str) -> Option<&'static str> {
let (slots, idx) = if let Some(rest) = name.strip_prefix("loc") {
(&self.locals, parse_slot_index(rest)?)
} else if let Some(rest) = name.strip_prefix("static") {
(&self.statics, parse_slot_index(rest)?)
} else {
return None;
};
slots.get(idx).copied().filter(|ty| !ty.is_empty())
}
}
fn parse_slot_index(rest: &str) -> Option<usize> {
if rest.is_empty() || !rest.bytes().all(|b| b.is_ascii_digit()) {
return None;
}
rest.parse::<usize>().ok()
}