pipeline_script/ast/
class.rs

1use crate::ast::declaration::VariableDeclaration;
2use crate::ast::function::Function;
3use std::collections::HashMap;
4
5#[derive(Clone, Debug)]
6pub struct Class {
7    name: String,
8    attributions: Vec<VariableDeclaration>,
9    pub(crate) methods: HashMap<String, Function>,
10    static_methods: HashMap<String, Function>,
11}
12
13impl Class {
14    pub fn new(name: &str, attributions: Vec<VariableDeclaration>) -> Self {
15        Self {
16            name: name.to_string(),
17            attributions,
18            methods: HashMap::new(),
19            static_methods: HashMap::new(),
20        }
21    }
22    pub fn get_attributions(&self) -> &Vec<VariableDeclaration> {
23        &self.attributions
24    }
25    pub fn get_name(&self) -> String {
26        self.name.clone()
27    }
28    pub fn get_static_function(&self, name: &str) -> Option<Function> {
29        self.static_methods.get(name).cloned()
30    }
31    pub fn register_method(&mut self, name: String, method: Function) {
32        self.methods.insert(name, method);
33    }
34    pub fn register_static_method(&mut self, name: String, method: Function) {
35        self.static_methods.insert(name, method);
36    }
37}