53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
use crate::symbol::{FunctionSymbol, ParameterSymbol, VariableSymbol};
|
|
use std::cell::RefCell;
|
|
use std::collections::HashMap;
|
|
use std::rc::Rc;
|
|
|
|
pub struct Scope {
|
|
debug_name: String,
|
|
parent_id: Option<usize>,
|
|
function_symbols: HashMap<Rc<str>, Rc<RefCell<FunctionSymbol>>>,
|
|
parameter_symbols: HashMap<Rc<str>, Rc<RefCell<ParameterSymbol>>>,
|
|
variable_symbols: HashMap<Rc<str>, Rc<RefCell<VariableSymbol>>>,
|
|
}
|
|
|
|
impl Scope {
|
|
pub fn new(debug_name: &str, parent_id: Option<usize>) -> Self {
|
|
Self {
|
|
debug_name: debug_name.into(),
|
|
parent_id,
|
|
function_symbols: HashMap::new(),
|
|
parameter_symbols: HashMap::new(),
|
|
variable_symbols: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
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 parameter_symbols(&self) -> &HashMap<Rc<str>, Rc<RefCell<ParameterSymbol>>> {
|
|
&self.parameter_symbols
|
|
}
|
|
|
|
pub fn parameter_symbols_mut(&mut self) -> &mut HashMap<Rc<str>, Rc<RefCell<ParameterSymbol>>> {
|
|
&mut self.parameter_symbols
|
|
}
|
|
|
|
pub fn variable_symbols(&self) -> &HashMap<Rc<str>, Rc<RefCell<VariableSymbol>>> {
|
|
&self.variable_symbols
|
|
}
|
|
|
|
pub fn variable_symbols_mut(&mut self) -> &mut HashMap<Rc<str>, Rc<RefCell<VariableSymbol>>> {
|
|
&mut self.variable_symbols
|
|
}
|
|
|
|
pub fn parent_id(&self) -> Option<usize> {
|
|
self.parent_id
|
|
}
|
|
}
|