deimos-lang/dmc-lib/src/ast/parameter.rs

59 lines
1.5 KiB
Rust

use crate::ast::type_use::TypeUse;
use crate::diagnostic::Diagnostic;
use crate::source_range::SourceRange;
use crate::symbol::parameter_symbol::ParameterSymbol;
use crate::symbol_table::SymbolTable;
use std::rc::Rc;
pub struct Parameter {
declared_name: Rc<str>,
declared_name_source_range: SourceRange,
type_use: TypeUse,
scope_id: Option<usize>,
}
impl Parameter {
pub fn new(
declared_name: &str,
declared_name_source_range: SourceRange,
type_use: TypeUse,
) -> Self {
Self {
declared_name: declared_name.into(),
declared_name_source_range,
type_use,
scope_id: None,
}
}
pub fn declared_name(&self) -> &str {
&self.declared_name
}
pub fn scope_id(&self) -> usize {
self.scope_id.unwrap()
}
pub fn init_scopes(&mut self, symbol_table: &mut SymbolTable, container_scope: usize) {
self.scope_id = Some(container_scope);
self.type_use.init_scopes(symbol_table, container_scope);
}
pub fn make_symbol(&self) -> ParameterSymbol {
ParameterSymbol::new(
&self.declared_name,
self.declared_name_source_range.clone(),
self.scope_id.unwrap(),
)
}
pub fn check_names(&self, symbol_table: &SymbolTable) -> Vec<Diagnostic> {
self.type_use.check_names(symbol_table)
}
pub fn type_check(&mut self, symbol_table: &SymbolTable) -> Result<(), Vec<Diagnostic>> {
self.type_use.type_check(symbol_table)?;
Ok(())
}
}