use super::declarations::Declarations;
use super::ir::VariableType;
pub trait TypeMeta {
fn propagate_types(&mut self, vars: &Declarations);
#[must_use]
fn is_local(&self) -> bool;
#[must_use]
fn is_signal(&self) -> bool;
#[must_use]
fn is_component(&self) -> bool;
#[must_use]
fn variable_type(&self) -> Option<&VariableType>;
}
#[derive(Default, Clone)]
pub struct TypeKnowledge {
var_type: Option<VariableType>,
}
impl TypeKnowledge {
#[must_use]
pub fn new() -> TypeKnowledge {
TypeKnowledge::default()
}
pub fn set_variable_type(&mut self, var_type: &VariableType) {
self.var_type = Some(var_type.clone());
}
#[must_use]
pub fn variable_type(&self) -> Option<&VariableType> {
self.var_type.as_ref()
}
#[must_use]
pub fn is_local(&self) -> bool {
matches!(self.var_type, Some(VariableType::Local))
}
#[must_use]
pub fn is_signal(&self) -> bool {
matches!(self.var_type, Some(VariableType::Signal(_)))
}
#[must_use]
pub fn is_component(&self) -> bool {
matches!(self.var_type, Some(VariableType::Component))
}
}