windows_metadata/reader/tables/
method_def.rs

1use super::*;
2
3impl std::fmt::Debug for MethodDef<'_> {
4    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5        f.debug_tuple("MethodDef").field(&self.name()).finish()
6    }
7}
8
9impl MethodDef<'_> {
10    pub fn rva(&self) -> usize {
11        self.usize(0)
12    }
13
14    pub fn impl_flags(&self) -> MethodImplAttributes {
15        MethodImplAttributes(self.usize(1).try_into().unwrap())
16    }
17
18    pub fn flags(&self) -> MethodAttributes {
19        MethodAttributes(self.usize(2).try_into().unwrap())
20    }
21
22    pub fn name(&self) -> &str {
23        self.str(3)
24    }
25
26    pub fn signature(&self, generics: &[Type]) -> Signature {
27        self.blob(4).read_method_signature(generics)
28    }
29
30    pub fn params(&self) -> RowIterator<MethodParam> {
31        self.list(5)
32    }
33
34    pub fn parent(&self) -> MemberRefParent {
35        MemberRefParent::TypeDef(self.parent_row(5))
36    }
37
38    pub fn impl_map(&self) -> Option<ImplMap> {
39        self.equal_range(1, MemberForwarded::MethodDef(*self).encode())
40            .next()
41    }
42
43    pub fn calling_convention(&self) -> &str {
44        self.impl_map().map_or("", |map| {
45            let flags = map.flags();
46
47            if flags.contains(PInvokeAttributes::CallConvPlatformapi) {
48                "system"
49            } else if flags.contains(PInvokeAttributes::CallConvCdecl) {
50                "cdecl"
51            } else {
52                ""
53            }
54        })
55    }
56}