deimos-lang/dmc-lib/src/scope/class_scope.rs

66 lines
2.0 KiB
Rust

use crate::symbol::class_symbol::ClassSymbol;
use crate::symbol::constructor_symbol::ConstructorSymbol;
use crate::symbol::field_symbol::FieldSymbol;
use crate::symbol::function_symbol::FunctionSymbol;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
pub struct ClassScope {
debug_name: String,
parent_id: usize,
class_symbols: HashMap<Rc<str>, Rc<RefCell<ClassSymbol>>>,
field_symbols: HashMap<Rc<str>, Rc<RefCell<FieldSymbol>>>,
function_symbols: HashMap<Rc<str>, Rc<RefCell<FunctionSymbol>>>,
constructor_symbol: Option<Rc<RefCell<ConstructorSymbol>>>,
}
impl ClassScope {
pub fn new(debug_name: &str, parent_id: usize) -> Self {
Self {
debug_name: debug_name.into(),
parent_id,
class_symbols: HashMap::new(),
field_symbols: HashMap::new(),
function_symbols: HashMap::new(),
constructor_symbol: None,
}
}
pub fn class_symbols(&self) -> &HashMap<Rc<str>, Rc<RefCell<ClassSymbol>>> {
&self.class_symbols
}
pub fn class_symbols_mut(&mut self) -> &mut HashMap<Rc<str>, Rc<RefCell<ClassSymbol>>> {
&mut self.class_symbols
}
pub fn field_symbols(&self) -> &HashMap<Rc<str>, Rc<RefCell<FieldSymbol>>> {
&self.field_symbols
}
pub fn field_symbols_mut(&mut self) -> &mut HashMap<Rc<str>, Rc<RefCell<FieldSymbol>>> {
&mut self.field_symbols
}
pub fn function_symbols(&self) -> &HashMap<Rc<str>, Rc<RefCell<FunctionSymbol>>> {
&self.function_symbols
}
pub fn function_symbols_mut(&mut self) -> &mut HashMap<Rc<str>, Rc<RefCell<FunctionSymbol>>> {
&mut self.function_symbols
}
pub fn constructor_symbol(&self) -> Option<&Rc<RefCell<ConstructorSymbol>>> {
self.constructor_symbol.as_ref()
}
pub fn constructor_symbol_mut(&mut self) -> &mut Option<Rc<RefCell<ConstructorSymbol>>> {
&mut self.constructor_symbol
}
pub fn parent_id(&self) -> usize {
self.parent_id
}
}