Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::FromFFI;
4 : use crate::dwarf::editor::types::EditorType;
5 :
6 : /// This structure represents an editable enum type (`DW_TAG_enumeration_type`)
7 : pub struct Enum {
8 : ptr: cxx::UniquePtr<ffi::DWARF_editor_EnumType>,
9 : }
10 :
11 : impl FromFFI<ffi::DWARF_editor_EnumType> for Enum {
12 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_editor_EnumType>) -> Self {
13 0 : Self {
14 0 : ptr: cmd,
15 0 : }
16 0 : }
17 : }
18 :
19 : impl Enum {
20 : /// Define the number of bytes required to hold an instance of the
21 : /// enumeration (`DW_AT_byte_size`).
22 0 : pub fn set_size(&mut self, size: u64) {
23 0 : self.ptr.pin_mut().set_size(size);
24 0 : }
25 :
26 : /// Add an enum value by specifying its name and its integer value
27 0 : pub fn add_value(&mut self, name: &str, value: i64) -> Value {
28 0 : Value::from_ffi(self.ptr.pin_mut().add_value(name, value))
29 0 : }
30 :
31 : /// Set the underlying type that is used to encode this enum
32 0 : pub fn set_underlying_type(&mut self, ty: &dyn EditorType) -> &mut Self {
33 0 : self.ptr.pin_mut().set_underlying_type(ty.get_base());
34 0 : self
35 0 : }
36 : }
37 :
38 :
39 : impl EditorType for Enum {
40 0 : fn get_base(&self) -> &ffi::DWARF_editor_Type {
41 0 : self.ptr.as_ref().unwrap().as_ref()
42 0 : }
43 : }
44 :
45 :
46 : /// This structure represents an enum value.
47 : #[allow(dead_code)]
48 : pub struct Value {
49 : ptr: cxx::UniquePtr<ffi::DWARF_editor_EnumType_Value>,
50 : }
51 :
52 : impl FromFFI<ffi::DWARF_editor_EnumType_Value> for Value {
53 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_editor_EnumType_Value>) -> Self {
54 0 : Self {
55 0 : ptr: cmd,
56 0 : }
57 0 : }
58 : }
|