use std::cell::Cell;
use crate::semantic::execution::Variable as FinalVariable;
use crate::Span;
use super::FieldSize;
#[derive(Clone, Debug)]
pub struct Variable {
pub name: String,
pub size: Cell<FieldSize>,
pub src: Span,
pub explicit: bool,
}
impl Variable {
pub fn new(name: String, src: Span, size: Option<FieldSize>, explicit: bool) -> Self {
Self {
name,
size: Cell::new(size.unwrap_or(FieldSize::new_unsized())),
src,
explicit,
}
}
pub fn convert(self) -> FinalVariable {
FinalVariable {
name: self.name.into(),
len_bits: self
.size
.get()
.possible_value()
.unwrap_or(32.try_into().unwrap()),
location: self.explicit.then_some(self.src),
}
}
}