1#![allow(non_upper_case_globals)]
2
3macro_rules! flags {
4 ($name:ident, $size:ty) => {
5 #[derive(Default, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
6 pub struct $name(pub $size);
7 impl $name {
8 pub fn contains(&self, contains: Self) -> bool {
9 *self & contains == contains
10 }
11 }
12 impl std::ops::BitOr for $name {
13 type Output = Self;
14 fn bitor(self, other: Self) -> Self {
15 Self(self.0 | other.0)
16 }
17 }
18 impl std::ops::BitAnd for $name {
19 type Output = Self;
20 fn bitand(self, other: Self) -> Self {
21 Self(self.0 & other.0)
22 }
23 }
24 impl std::ops::BitOrAssign for $name {
25 fn bitor_assign(&mut self, other: Self) {
26 self.0.bitor_assign(other.0)
27 }
28 }
29 impl std::ops::BitAndAssign for $name {
30 fn bitand_assign(&mut self, other: Self) {
31 self.0.bitand_assign(other.0)
32 }
33 }
34 impl std::ops::Not for $name {
35 type Output = Self;
36 fn not(self) -> Self {
37 Self(self.0.not())
38 }
39 }
40 };
41}
42
43flags!(FieldAttributes, u16);
44impl FieldAttributes {
45 pub const Private: Self = Self(0x1);
46 pub const Public: Self = Self(0x6);
47 pub const Literal: Self = Self(0x40);
48 pub const Static: Self = Self(0x10);
49 pub const SpecialName: Self = Self(0x200);
50 pub const RTSpecialName: Self = Self(0x400);
51 pub const HasDefault: Self = Self(0x8000);
52}
53
54flags!(MethodAttributes, u16);
55impl MethodAttributes {
56 pub const Abstract: Self = Self(0x400);
57 pub const HideBySig: Self = Self(0x80);
58 pub const NewSlot: Self = Self(0x100);
59 pub const Public: Self = Self(0x6);
60 pub const SpecialName: Self = Self(0x800);
61 pub const Virtual: Self = Self(0x40);
62}
63
64flags!(MethodImplAttributes, u16);
65impl MethodImplAttributes {
66 pub const PreserveSig: Self = Self(0x80);
67}
68
69// These are not really ECMA-335 attributes but instead the flags found in the method signature.
70flags!(MethodCallAttributes, u8);
71impl MethodCallAttributes {
72 pub const HASTHIS: Self = Self(0x20);
73 pub const VARARG: Self = Self(0x05);
74}
75
76flags!(ParamAttributes, u16);
77impl ParamAttributes {
78 pub const In: Self = Self(0x1);
79 pub const Out: Self = Self(0x2);
80 pub const Optional: Self = Self(0x10);
81}
82
83flags!(PInvokeAttributes, usize);
84impl PInvokeAttributes {
85 pub const SupportsLastError: Self = Self(0x40);
86 pub const CallConvPlatformapi: Self = Self(0x100);
87 pub const CallConvCdecl: Self = Self(0x200);
88 pub const CallConvStdcall: Self = Self(0x300);
89 pub const CallConvThiscall: Self = Self(0x400);
90 pub const CallConvFastcall: Self = Self(0x500);
91}
92
93flags!(TypeAttributes, u32);
94impl TypeAttributes {
95 pub const Public: Self = Self(0x1);
96 pub const ExplicitLayout: Self = Self(0x10);
97 pub const Abstract: Self = Self(0x80);
98 pub const Sealed: Self = Self(0x100);
99 pub const WindowsRuntime: Self = Self(0x4000);
100 pub const Interface: Self = Self(0x20);
101 pub const SequentialLayout: Self = Self(0x8);
102 pub const Import: Self = Self(0x1000);
103}
104
105flags!(AssemblyFlags, u32);
106impl AssemblyFlags {
107 pub const WindowsRuntime: Self = Self(0x200);
108}
109