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