pipeline_script/context/
key.rs

1#[derive(Clone, Debug)]
2pub enum ContextKey {
3    Background,
4    Builder,
5    // SymbolTable,
6    LLVMContext,
7    LLVMModule,
8    SymbolType,
9    ModuleSlotMap,
10    /// 预处理阶段闭包捕获变量分析
11    LocalVariable,
12    CaptureVariable,
13    AliasType,
14    // 编译阶段,当前函数类型
15    Type(String),
16    Flag(String),
17    TypeTable,
18    Function,
19    Scope,
20    // 循环的基本块
21    LoopBlock(String),
22    DefaultExpr,
23}
24
25impl Default for ContextKey {
26    fn default() -> Self {
27        Self::Background
28    }
29}
30
31impl PartialEq for ContextKey {
32    fn eq(&self, other: &Self) -> bool {
33        match self {
34            ContextKey::Background => matches!(other, ContextKey::Background),
35            ContextKey::Builder => matches!(other, ContextKey::Builder),
36            ContextKey::TypeTable => matches!(other, ContextKey::TypeTable),
37            // ContextKey::SymbolTable => matches!(other, ContextKey::SymbolTable),
38            ContextKey::Function => matches!(other, ContextKey::Function),
39            ContextKey::Scope => matches!(other, ContextKey::Scope),
40            ContextKey::Flag(f) => match other {
41                ContextKey::Flag(o) => f == o,
42                _ => false,
43            },
44            ContextKey::SymbolType => matches!(other, ContextKey::SymbolType),
45            ContextKey::AliasType => matches!(other, ContextKey::AliasType),
46            ContextKey::LocalVariable => matches!(other, ContextKey::LocalVariable),
47            ContextKey::CaptureVariable => matches!(other, ContextKey::CaptureVariable),
48            ContextKey::Type(t) => match other {
49                ContextKey::Type(o) => t == o,
50                _ => false,
51            },
52            ContextKey::LLVMContext => matches!(other, ContextKey::LLVMContext),
53            ContextKey::LLVMModule => matches!(other, ContextKey::LLVMModule),
54            ContextKey::ModuleSlotMap => matches!(other, ContextKey::ModuleSlotMap),
55            ContextKey::LoopBlock(l) => match other {
56                ContextKey::LoopBlock(o) => l == o,
57                _ => false,
58            },
59            ContextKey::DefaultExpr => matches!(other, ContextKey::DefaultExpr),
60        }
61    }
62}