1use anyhow::{Result, anyhow};
4
5use core::mem::size_of;
6
7use crate::parser::{FipsType, CompileTimeConstant};
8
9impl FipsType {
10 pub fn get_size(&self) -> Result<usize> {
11 match self {
12 FipsType::Double => Ok(size_of::<f64>()),
13 FipsType::Int64 => Ok(size_of::<u64>()),
14 FipsType::Array { typ, length } => match length {
15 CompileTimeConstant::Literal(length) | CompileTimeConstant::Substituted(length,_)
16 => Ok(typ.get_size()? * length),
17 CompileTimeConstant::Identifier(name) => Err(
18 anyhow!("Cannot determine size due to array length {} being undefined", name))
19 }
20 }
21 }
22}