LCOV - code coverage report
Current view: top level - src/dwarf/types - array.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 30 0
Test Date: 2024-11-30:00:00:00 Functions: 0.0 % 8 0

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : 
       3              : use crate::common::{into_optional, FromFFI};
       4              : use std::marker::PhantomData;
       5              : use crate::dwarf::types::DwarfType;
       6              : 
       7              : use crate::dwarf::Type;
       8              : 
       9              : /// This class represents a `DW_TAG_array_type`
      10              : pub struct Array<'a> {
      11              :     ptr: cxx::UniquePtr<ffi::DWARF_types_Array>,
      12              :     _owner: PhantomData<&'a ()>,
      13              : }
      14              : 
      15              : impl FromFFI<ffi::DWARF_types_Array> for Array<'_> {
      16            0 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_types_Array>) -> Self {
      17            0 :         Self {
      18            0 :             ptr: cmd,
      19            0 :             _owner: PhantomData,
      20            0 :         }
      21            0 :     }
      22              : }
      23              : 
      24              : impl Array<'_> {
      25              :     /// The underlying type of this array
      26            0 :     pub fn underlying_type(&self) -> Option<Type> {
      27            0 :         into_optional(self.ptr.underlying_type())
      28            0 :     }
      29              : 
      30              :     /// Return information about the size of this array.
      31              :     ///
      32              :     /// This size info is usually embedded in a `DW_TAG_subrange_type` DIE which
      33              :     /// is represented by the [`SizeInfo`] structure.
      34            0 :     pub fn size_info(&self) -> SizeInfo {
      35            0 :         SizeInfo::from_ffi(self.ptr.size_info())
      36            0 :     }
      37              : }
      38              : 
      39              : impl DwarfType for Array<'_> {
      40            0 :     fn get_base(&self) -> &ffi::DWARF_Type {
      41            0 :         self.ptr.as_ref().unwrap().as_ref()
      42            0 :     }
      43              : }
      44              : 
      45              : /// Structure that wraps information about the dimension of this array
      46              : pub struct SizeInfo<'a> {
      47              :     ptr: cxx::UniquePtr<ffi::DWARF_types_array_size_info>,
      48              :     _owner: PhantomData<&'a ()>,
      49              : }
      50              : 
      51              : impl FromFFI<ffi::DWARF_types_array_size_info> for SizeInfo<'_> {
      52            0 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::DWARF_types_array_size_info>) -> Self {
      53            0 :         Self {
      54            0 :             ptr,
      55            0 :             _owner: PhantomData,
      56            0 :         }
      57            0 :     }
      58              : }
      59              : 
      60              : impl SizeInfo<'_> {
      61              :     /// Name of the index (usually not relevant like `__ARRAY_SIZE_TYPE__`)
      62            0 :     pub fn name(&self) -> String {
      63            0 :         self.ptr.name().to_string()
      64            0 :     }
      65              : 
      66              :     /// Size of the array. For instance in `uint8_t[3]`, it returns 3
      67            0 :     pub fn size(&self) -> u64 {
      68            0 :         self.ptr.size()
      69            0 :     }
      70              : 
      71              :     /// Type of the **index** for this array.
      72              :     ///
      73              :     /// For instance in `uint8_t[3]` the index type could be set to a `size_t`.
      74            0 :     pub fn get_type(&self) -> Option<Type> {
      75            0 :         into_optional(self.ptr.get_type())
      76            0 :     }
      77              : }
        

Generated by: LCOV version 2.1-1