use alloc::string::String;
use alloc::vec::Vec;
use crate::dll::NativeType;
pub(crate) fn numeric(name: &str) -> Option<NativeType> {
match name.to_ascii_lowercase().as_str() {
"int8" => Some(NativeType::Char),
"uint8" => Some(NativeType::UChar),
"int16" => Some(NativeType::Short),
"uint16" => Some(NativeType::UShort),
"int32" => Some(NativeType::Int),
"uint32" => Some(NativeType::UInt),
"int64" => Some(NativeType::Int64),
"intptr" => Some(NativeType::Ptr),
"float32" => Some(NativeType::Float),
"float64" => Some(NativeType::Double),
_ => None,
}
}
pub(crate) fn is_a_struct_class_name(name: &str) -> bool {
name.eq_ignore_ascii_case("struct") || numeric(name).is_some()
}
#[derive(Clone, Debug)]
pub(crate) enum FieldType {
Numeric(NativeType),
Struct(String),
}
#[derive(Clone, Debug)]
pub(crate) struct FieldLayout {
pub name: String,
pub offset: usize,
pub field_type: FieldType,
}
#[derive(Clone, Debug)]
pub(crate) struct Layout {
pub fields: Vec<FieldLayout>,
pub size: usize,
pub align: usize,
}
pub(crate) fn alignment_of(size: usize) -> usize {
size.clamp(1, 8)
}
pub(crate) fn align_up(offset: usize, align: usize) -> usize {
offset.div_ceil(align) * align
}