1 | macro_rules! flags { |
2 | ($name:ident, $size:ty) => { |
3 | #[derive(Default, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)] |
4 | pub struct $name(pub $size); |
5 | impl $name { |
6 | #[allow(dead_code)] |
7 | pub fn contains(&self, contains: Self) -> bool { |
8 | *self & contains == contains |
9 | } |
10 | } |
11 | impl std::ops::BitOr for $name { |
12 | type Output = Self; |
13 | fn bitor(self, other: Self) -> Self { |
14 | Self(self.0 | other.0) |
15 | } |
16 | } |
17 | impl std::ops::BitAnd for $name { |
18 | type Output = Self; |
19 | fn bitand(self, other: Self) -> Self { |
20 | Self(self.0 & other.0) |
21 | } |
22 | } |
23 | impl std::ops::BitOrAssign for $name { |
24 | fn bitor_assign(&mut self, other: Self) { |
25 | self.0.bitor_assign(other.0) |
26 | } |
27 | } |
28 | impl std::ops::BitAndAssign for $name { |
29 | fn bitand_assign(&mut self, other: Self) { |
30 | self.0.bitand_assign(other.0) |
31 | } |
32 | } |
33 | impl std::ops::Not for $name { |
34 | type Output = Self; |
35 | fn not(self) -> Self { |
36 | Self(self.0.not()) |
37 | } |
38 | } |
39 | }; |
40 | } |
41 | |
42 | flags!(FieldAttributes, u16); |
43 | impl FieldAttributes { |
44 | pub const Literal: Self = Self(0x40); |
45 | } |
46 | |
47 | flags!(MethodAttributes, u16); |
48 | impl MethodAttributes { |
49 | pub const SpecialName: Self = Self(0x800); |
50 | } |
51 | |
52 | // These are not really ECMA-335 attributes but instead the flags found in the method signature. |
53 | flags!(MethodCallAttributes, u8); |
54 | impl MethodCallAttributes { |
55 | pub const VARARG: Self = Self(0x05); |
56 | } |
57 | |
58 | flags!(ParamAttributes, u16); |
59 | impl ParamAttributes { |
60 | pub const In: Self = Self(0x1); |
61 | pub const Out: Self = Self(0x2); |
62 | pub const Optional: Self = Self(0x10); |
63 | } |
64 | |
65 | flags!(PInvokeAttributes, usize); |
66 | impl PInvokeAttributes { |
67 | pub const SupportsLastError: Self = Self(0x40); |
68 | pub const CallConvPlatformapi: Self = Self(0x100); |
69 | pub const CallConvCdecl: Self = Self(0x200); |
70 | } |
71 | |
72 | flags!(TypeAttributes, u32); |
73 | impl TypeAttributes { |
74 | pub const ExplicitLayout: Self = Self(0x10); |
75 | pub const WindowsRuntime: Self = Self(0x4000); |
76 | } |
77 | |