use lief_ffi as ffi;
use std::marker::PhantomData;
use crate::DebugLocation;
use crate::DeclOpt;
use crate::common::FromFFI;
use crate::declare_fwd_iterator;
pub struct Function<'a> {
ptr: cxx::UniquePtr<ffi::PDB_Function>,
_owner: PhantomData<&'a ()>,
}
impl FromFFI<ffi::PDB_Function> for Function<'_> {
fn from_ffi(ptr: cxx::UniquePtr<ffi::PDB_Function>) -> Self {
Self {
ptr,
_owner: PhantomData,
}
}
}
impl Function<'_> {
pub fn name(&self) -> String {
self.ptr.name().to_string()
}
pub fn rva(&self) -> u32 {
self.ptr.RVA()
}
pub fn code_size(&self) -> u32 {
self.ptr.code_size()
}
pub fn section_name(&self) -> String {
self.ptr.section_name().to_string()
}
pub fn debug_location(&self) -> DebugLocation {
DebugLocation::from_ffi(self.ptr.debug_location())
}
pub fn to_decl(&self) -> String {
self.ptr.to_decl().to_string()
}
pub fn to_decl_with_opt(&self, opt: &DeclOpt) -> String {
self.ptr.to_decl_with_opt(&opt.to_ffi()).to_string()
}
}
impl std::fmt::Display for Function<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.ptr.to_string())
}
}
declare_fwd_iterator!(
Functions,
Function<'a>,
ffi::PDB_Function,
ffi::PDB_CompilationUnit,
ffi::PDB_CompilationUnit_it_functions
);