Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::{FromFFI, into_optional};
4 : use std::marker::PhantomData;
5 : use super::Type;
6 : use crate::dwarf::types::DwarfType;
7 : use crate::declare_fwd_iterator;
8 : use crate::dwarf::Parameters;
9 :
10 : /// This structure represents a `DW_TAG_subroutine_type`
11 : pub struct Subroutine<'a> {
12 : ptr: cxx::UniquePtr<ffi::DWARF_types_Subroutine>,
13 : _owner: PhantomData<&'a ()>,
14 : }
15 :
16 : impl FromFFI<ffi::DWARF_types_Subroutine> for Subroutine<'_> {
17 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::DWARF_types_Subroutine>) -> Self {
18 0 : Self {
19 0 : ptr,
20 0 : _owner: PhantomData,
21 0 : }
22 0 : }
23 : }
24 :
25 : impl DwarfType for Subroutine<'_> {
26 0 : fn get_base(&self) -> &ffi::DWARF_Type {
27 0 : self.ptr.as_ref().unwrap().as_ref()
28 0 : }
29 : }
30 :
31 : impl Subroutine<'_> {
32 : /// Return the [`Type`] associated with the **return type** of this function.
33 0 : pub fn return_type(&self) -> Option<Type> {
34 0 : into_optional(self.ptr.return_type())
35 0 : }
36 :
37 : /// [`Parameters`] of this subroutine
38 0 : pub fn parameters(&self) -> ParametersIt {
39 0 : ParametersIt::new(self.ptr.parameters())
40 0 : }
41 : }
42 :
43 0 : declare_fwd_iterator!(
44 0 : ParametersIt,
45 0 : Parameters<'a>,
46 0 : ffi::DWARF_Parameter,
47 0 : ffi::DWARF_types_Subroutine,
48 0 : ffi::DWARF_types_Subroutine_it_parameters
49 0 : );
|