c3_lang_parser/
register.rs1use std::collections::HashMap;
2
3use c3_lang_linearization::{Class, Fn, Var};
4use syn::{Field, ImplItemMethod};
5
6#[derive(Default)]
7pub struct Register {
8 functions: HashMap<Fn, Vec<(Class, ImplItemMethod)>>,
9 variables: HashMap<Var, Field>,
10}
11
12impl Register {
13 pub fn add(&mut self, class: Class, fun: Fn, fun_impl: ImplItemMethod) {
14 self.functions
15 .entry(fun)
16 .or_default()
17 .push((class, fun_impl));
18 }
19
20 pub fn get_first_impl(&self, fun: &Fn) -> ImplItemMethod {
21 self.get(fun).first().unwrap().clone().1
22 }
23
24 pub fn get(&self, fun: &Fn) -> Vec<(Class, ImplItemMethod)> {
25 self.functions.get(fun).unwrap().clone()
26 }
27
28 pub fn functions(&self) -> Vec<Fn> {
29 let mut list: Vec<Fn> = self.functions.keys().cloned().collect();
30 list.sort();
31 list
32 }
33
34 pub fn add_var(&mut self, var: Var, field: Field) {
35 self.variables.insert(var, field);
36 }
37
38 pub fn get_var(&self, var: Var) -> Field {
39 self.variables.get(&var).unwrap().clone()
40 }
41}