LCOV - code coverage report
Current view: top level - src/dwarf/editor - types.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 75 0
Test Date: 2026-04-12:00:00:00 Functions: 0.0 % 13 0

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : 
       3              : pub mod array;
       4              : pub mod base;
       5              : pub mod enum_ty;
       6              : pub mod function;
       7              : pub mod pointer;
       8              : pub mod struct_ty;
       9              : pub mod typedef;
      10              : 
      11              : use crate::common::FromFFI;
      12              : 
      13              : #[doc(inline)]
      14              : pub use pointer::Pointer;
      15              : 
      16              : #[doc(inline)]
      17              : pub use array::Array;
      18              : 
      19              : #[doc(inline)]
      20              : pub use base::Base;
      21              : 
      22              : #[doc(inline)]
      23              : pub use enum_ty::Enum;
      24              : 
      25              : #[doc(inline)]
      26              : pub use function::Function;
      27              : 
      28              : #[doc(inline)]
      29              : pub use struct_ty::Struct;
      30              : 
      31              : #[doc(inline)]
      32              : pub use typedef::Typedef;
      33              : 
      34              : /// The different types supported by the editor interface
      35              : pub enum Type {
      36              :     /// Mirror `DW_TAG_pointer_type`
      37              :     Pointer(Pointer),
      38              : 
      39              :     /// Mirror `DW_TAG_array_type`
      40              :     Array(Array),
      41              : 
      42              :     /// Mirror `DW_TAG_base_type`
      43              :     Base(Base),
      44              : 
      45              :     /// Mirror `DW_TAG_enumeration_type`
      46              :     Enum(Enum),
      47              : 
      48              :     /// Mirror `DW_TAG_subroutine_type`
      49              :     Function(Function),
      50              : 
      51              :     /// Mirror `DW_TAG_class_type, DW_TAG_structure_type, DW_TAG_union_type`
      52              :     Struct(Struct),
      53              : 
      54              :     /// Mirror `DW_TAG_typedef`
      55              :     Typedef(Typedef),
      56              : 
      57              :     Generic(Generic),
      58              : }
      59              : 
      60              : impl FromFFI<ffi::DWARF_editor_Type> for Type {
      61            0 :     fn from_ffi(ffi_entry: cxx::UniquePtr<ffi::DWARF_editor_Type>) -> Self {
      62            0 :         unsafe {
      63            0 :             let type_ref = ffi_entry.as_ref().unwrap();
      64            0 : 
      65            0 :             if ffi::DWARF_editor_PointerType::classof(type_ref) {
      66            0 :                 let raw = {
      67            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
      68            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_PointerType>;
      69            0 :                     std::mem::transmute::<From, To>(ffi_entry)
      70            0 :                 };
      71            0 :                 Type::Pointer(Pointer::from_ffi(raw))
      72            0 :             } else if ffi::DWARF_editor_ArrayType::classof(type_ref) {
      73            0 :                 let raw = {
      74            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
      75            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_ArrayType>;
      76            0 :                     std::mem::transmute::<From, To>(ffi_entry)
      77            0 :                 };
      78            0 :                 Type::Array(Array::from_ffi(raw))
      79            0 :             } else if ffi::DWARF_editor_BaseType::classof(type_ref) {
      80            0 :                 let raw = {
      81            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
      82            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_BaseType>;
      83            0 :                     std::mem::transmute::<From, To>(ffi_entry)
      84            0 :                 };
      85            0 :                 Type::Base(Base::from_ffi(raw))
      86            0 :             } else if ffi::DWARF_editor_EnumType::classof(type_ref) {
      87            0 :                 let raw = {
      88            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
      89            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_EnumType>;
      90            0 :                     std::mem::transmute::<From, To>(ffi_entry)
      91            0 :                 };
      92            0 :                 Type::Enum(Enum::from_ffi(raw))
      93            0 :             } else if ffi::DWARF_editor_FunctionType::classof(type_ref) {
      94            0 :                 let raw = {
      95            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
      96            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_FunctionType>;
      97            0 :                     std::mem::transmute::<From, To>(ffi_entry)
      98            0 :                 };
      99            0 :                 Type::Function(Function::from_ffi(raw))
     100            0 :             } else if ffi::DWARF_editor_StructType::classof(type_ref) {
     101            0 :                 let raw = {
     102            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
     103            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_StructType>;
     104            0 :                     std::mem::transmute::<From, To>(ffi_entry)
     105            0 :                 };
     106            0 :                 Type::Struct(Struct::from_ffi(raw))
     107            0 :             } else if ffi::DWARF_editor_TypeDef::classof(type_ref) {
     108            0 :                 let raw = {
     109            0 :                     type From = cxx::UniquePtr<ffi::DWARF_editor_Type>;
     110            0 :                     type To = cxx::UniquePtr<ffi::DWARF_editor_TypeDef>;
     111            0 :                     std::mem::transmute::<From, To>(ffi_entry)
     112            0 :                 };
     113            0 :                 Type::Typedef(Typedef::from_ffi(raw))
     114              :             } else {
     115            0 :                 Type::Generic(Generic::from_ffi(ffi_entry))
     116              :             }
     117              :         }
     118            0 :     }
     119              : }
     120              : 
     121              : /// Generic trait shared by all DWARF editor types
     122              : pub trait EditorType {
     123              :     #[doc(hidden)]
     124              :     fn get_base(&self) -> &ffi::DWARF_editor_Type;
     125              : 
     126            0 :     fn pointer_to(&self) -> Pointer {
     127            0 :         Pointer::from_ffi(self.get_base().pointer_to())
     128            0 :     }
     129              : }
     130              : 
     131              : /// This structure represents a generic type (like `DW_TAG_unspecified_type`)
     132              : pub struct Generic {
     133              :     ptr: cxx::UniquePtr<ffi::DWARF_editor_Type>,
     134              : }
     135              : 
     136              : impl FromFFI<ffi::DWARF_editor_Type> for Generic {
     137            0 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_editor_Type>) -> Self {
     138            0 :         Self { ptr: cmd }
     139            0 :     }
     140              : }
     141              : 
     142              : impl EditorType for Generic {
     143            0 :     fn get_base(&self) -> &ffi::DWARF_editor_Type {
     144            0 :         self.ptr.as_ref().unwrap()
     145            0 :     }
     146              : }
     147              : 
     148              : impl EditorType for Type {
     149            0 :     fn get_base(&self) -> &ffi::DWARF_editor_Type {
     150            0 :         match &self {
     151            0 :             Type::Pointer(s) => s.get_base(),
     152            0 :             Type::Array(s) => s.get_base(),
     153            0 :             Type::Base(s) => s.get_base(),
     154            0 :             Type::Enum(s) => s.get_base(),
     155            0 :             Type::Function(s) => s.get_base(),
     156            0 :             Type::Struct(s) => s.get_base(),
     157            0 :             Type::Typedef(s) => s.get_base(),
     158            0 :             Type::Generic(s) => s.get_base(),
     159              :         }
     160            0 :     }
     161              : }
        

Generated by: LCOV version 2.1-1