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 a function type (`DW_TAG_subroutine_type`)
7 : pub struct Function {
8 : ptr: cxx::UniquePtr<ffi::DWARF_editor_FunctionType>,
9 : }
10 :
11 : impl FromFFI<ffi::DWARF_editor_FunctionType> for Function {
12 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_editor_FunctionType>) -> Self {
13 0 : Self {
14 0 : ptr: cmd,
15 0 : }
16 0 : }
17 : }
18 :
19 : impl EditorType for Function {
20 0 : fn get_base(&self) -> &ffi::DWARF_editor_Type {
21 0 : self.ptr.as_ref().unwrap().as_ref()
22 0 : }
23 : }
24 :
25 : impl Function {
26 : /// Set the return type of this function
27 0 : pub fn set_return_type(&mut self, ty: &dyn EditorType) -> &mut Self {
28 0 : self.ptr.pin_mut().set_return_type(ty.get_base());
29 0 : self
30 0 : }
31 :
32 : /// Add a parameter
33 0 : pub fn add_parameter(&mut self, ty: &dyn EditorType) -> Parameter {
34 0 : Parameter::from_ffi(self.ptr.pin_mut().add_parameter(ty.get_base()))
35 0 : }
36 : }
37 :
38 : /// This structure represents a function's parameter
39 : #[allow(dead_code)]
40 : pub struct Parameter {
41 : ptr: cxx::UniquePtr<ffi::DWARF_editor_FunctionType_Parameter>,
42 : }
43 :
44 : impl FromFFI<ffi::DWARF_editor_FunctionType_Parameter> for Parameter {
45 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_editor_FunctionType_Parameter>) -> Self {
46 0 : Self {
47 0 : ptr: cmd,
48 0 : }
49 0 : }
50 : }
51 :
52 :
|