Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::FromFFI;
4 : use std::marker::PhantomData;
5 : use crate::pdb::types::PdbType;
6 : use crate::pdb::types::attribute::Attributes;
7 : use crate::pdb::types::method::Methods;
8 :
9 :
10 : /// Trait shared by [`Structure`], [`Class`], [`Union`] and [`Interface`]
11 : pub trait ClassLike {
12 : #[doc(hidden)]
13 : fn get_classlike(&self) -> &ffi::PDB_types_ClassLike;
14 :
15 : /// Mangled type name
16 0 : fn unique_name(&self) -> String {
17 0 : self.get_classlike().unique_name().to_string()
18 0 : }
19 :
20 : /// Iterator over the different [`crate::pdb::types::Attribute`] defined in this
21 : /// class-like type
22 0 : fn attributes(&self) -> Attributes<'_> {
23 0 : Attributes::new(self.get_classlike().attributes())
24 0 : }
25 :
26 : /// Iterator over the different [`crate::pdb::types::Method`] implemented in this
27 : /// class-like type
28 0 : fn methods(&self) -> Methods<'_> {
29 0 : Methods::new(self.get_classlike().methods())
30 0 : }
31 : }
32 :
33 : /// This structure wraps a `LF_CLASS` PDB type
34 : pub struct Class<'a> {
35 : ptr: cxx::UniquePtr<ffi::PDB_types_Class>,
36 : _owner: PhantomData<&'a ()>,
37 : }
38 :
39 : impl FromFFI<ffi::PDB_types_Class> for Class<'_> {
40 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::PDB_types_Class>) -> Self {
41 0 : Self {
42 0 : ptr: cmd,
43 0 : _owner: PhantomData,
44 0 : }
45 0 : }
46 : }
47 :
48 : impl ClassLike for Class<'_> {
49 0 : fn get_classlike(&self) -> &ffi::PDB_types_ClassLike {
50 0 : self.ptr.as_ref().unwrap().as_ref()
51 0 : }
52 : }
53 :
54 : impl PdbType for Class<'_> {
55 0 : fn get_base(&self) -> &ffi::PDB_Type {
56 0 : self.ptr.as_ref().unwrap().as_ref().as_ref()
57 0 : }
58 : }
59 :
60 : /// This structure wraps a `LF_STRUCTURE` PDB type
61 : pub struct Structure<'a> {
62 : ptr: cxx::UniquePtr<ffi::PDB_types_Structure>,
63 : _owner: PhantomData<&'a ()>,
64 : }
65 :
66 : impl FromFFI<ffi::PDB_types_Structure> for Structure<'_> {
67 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::PDB_types_Structure>) -> Self {
68 0 : Self {
69 0 : ptr: cmd,
70 0 : _owner: PhantomData,
71 0 : }
72 0 : }
73 : }
74 :
75 : impl ClassLike for Structure<'_> {
76 0 : fn get_classlike(&self) -> &ffi::PDB_types_ClassLike {
77 0 : self.ptr.as_ref().unwrap().as_ref()
78 0 : }
79 : }
80 :
81 : impl PdbType for Structure<'_> {
82 0 : fn get_base(&self) -> &ffi::PDB_Type {
83 0 : self.ptr.as_ref().unwrap().as_ref().as_ref()
84 0 : }
85 : }
86 :
87 : /// This structure wraps a `LF_INTERFACE` PDB type
88 : pub struct Interface<'a> {
89 : ptr: cxx::UniquePtr<ffi::PDB_types_Interface>,
90 : _owner: PhantomData<&'a ()>,
91 : }
92 :
93 : impl FromFFI<ffi::PDB_types_Interface> for Interface<'_> {
94 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::PDB_types_Interface>) -> Self {
95 0 : Self {
96 0 : ptr: cmd,
97 0 : _owner: PhantomData,
98 0 : }
99 0 : }
100 : }
101 :
102 : impl ClassLike for Interface<'_> {
103 0 : fn get_classlike(&self) -> &ffi::PDB_types_ClassLike {
104 0 : self.ptr.as_ref().unwrap().as_ref()
105 0 : }
106 : }
107 :
108 : impl PdbType for Interface<'_> {
109 0 : fn get_base(&self) -> &ffi::PDB_Type {
110 0 : self.ptr.as_ref().unwrap().as_ref().as_ref()
111 0 : }
112 : }
|