use lief_ffi as ffi;
use crate::common::{FromFFI, into_optional};
use crate::dwarf::types::DwarfType;
use std::marker::PhantomData;
use crate::dwarf::Type;
pub struct Array<'a> {
ptr: cxx::UniquePtr<ffi::DWARF_types_Array>,
_owner: PhantomData<&'a ()>,
}
impl FromFFI<ffi::DWARF_types_Array> for Array<'_> {
fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_types_Array>) -> Self {
Self {
ptr: cmd,
_owner: PhantomData,
}
}
}
impl Array<'_> {
pub fn underlying_type(&self) -> Option<Type<'_>> {
into_optional(self.ptr.underlying_type())
}
pub fn size_info(&self) -> SizeInfo<'_> {
SizeInfo::from_ffi(self.ptr.size_info())
}
}
impl DwarfType for Array<'_> {
fn get_base(&self) -> &ffi::DWARF_Type {
self.ptr.as_ref().unwrap().as_ref()
}
}
pub struct SizeInfo<'a> {
ptr: cxx::UniquePtr<ffi::DWARF_types_array_size_info>,
_owner: PhantomData<&'a ()>,
}
impl FromFFI<ffi::DWARF_types_array_size_info> for SizeInfo<'_> {
fn from_ffi(ptr: cxx::UniquePtr<ffi::DWARF_types_array_size_info>) -> Self {
Self {
ptr,
_owner: PhantomData,
}
}
}
impl SizeInfo<'_> {
pub fn name(&self) -> String {
self.ptr.name().to_string()
}
pub fn size(&self) -> u64 {
self.ptr.size()
}
pub fn get_type(&self) -> Option<Type<'_>> {
into_optional(self.ptr.get_type())
}
}