machine_check_common/iir/
context.rs

1use indexmap::IndexMap;
2
3use crate::iir::{
4    description::{IFnId, IStruct, IStructId},
5    func::IFn,
6    path::IIdent,
7};
8
9#[derive(Clone, Debug)]
10pub struct IFnContext<'a> {
11    pub func: &'a IFn,
12    pub context: &'a IContext<'a>,
13}
14
15#[derive(Clone, Debug)]
16pub struct IContext<'a> {
17    pub structs: Option<&'a IndexMap<IIdent, IStruct>>,
18}
19
20impl IContext<'_> {
21    pub fn empty() -> IContext<'static> {
22        IContext { structs: None }
23    }
24
25    pub fn struct_with_id(&self, id: IStructId) -> &IStruct {
26        let Some(structs) = self.structs else {
27            panic!("Should have structs when looking up one");
28        };
29        structs
30            .get_index(id.0)
31            .expect("Struct with given id should exist")
32            .1
33    }
34
35    pub fn fn_with_id(&self, id: IFnId) -> &IFn {
36        self.struct_with_id(id.struct_id)
37            .fns
38            .get_index(id.fn_index)
39            .expect("Call with given id should exist")
40            .1
41    }
42}