/
codes.rs
79 lines (71 loc) · 1.82 KB
/
codes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/// A `ResolutionScope` is an index into a certain table indicating the scope in which a TypeRef can be resolved.
#[derive(Clone, Copy)]
pub enum ResolutionScope {
None,
Module(usize),
ModuleRef(usize),
AssemblyRef(usize),
TypeRef(usize),
}
impl ResolutionScope {
pub fn encode(&self) -> usize {
match self {
Self::Module(row) => (row + 1) << 2,
Self::ModuleRef(row) => ((row + 1) << 2) + 1,
Self::AssemblyRef(row) => ((row + 1) << 2) + 2,
Self::TypeRef(row) => ((row + 1) << 2) + 3,
_ => 0,
}
}
}
impl Default for ResolutionScope {
fn default() -> Self {
Self::None
}
}
/// A `TypeDefOrRef` is an index into a certain table used to locate a type definition.
#[derive(Clone, Copy)]
pub enum TypeDefOrRef {
None,
TypeDef(usize),
TypeRef(usize),
TypeSpec(usize),
}
impl TypeDefOrRef {
pub fn encode(&self) -> usize {
match self {
Self::TypeDef(row) => (row + 1) << 2,
Self::TypeRef(row) => ((row + 1) << 2) + 1,
Self::TypeSpec(row) => ((row + 1) << 2) + 2,
_ => 0,
}
}
}
impl Default for TypeDefOrRef {
fn default() -> Self {
Self::None
}
}
/// A `HasConstant` is an index into a certain table used to identify the parent of a row in the `Constant` table.
#[derive(Clone, Copy)]
pub enum HasConstant {
None,
Field(usize),
Param(usize),
Property(usize),
}
impl HasConstant {
pub fn encode(&self) -> usize {
match self {
Self::Field(row) => (row + 1) << 2,
Self::Param(row) => ((row + 1) << 2) + 1,
Self::Property(row) => ((row + 1) << 2) + 2,
_ => 0,
}
}
}
impl Default for HasConstant {
fn default() -> Self {
Self::None
}
}