use microcad_lang_base::SrcRef;
use microcad_lang_proc_macros::SrcReferrer;
use crate::{ty::*, value::*};
#[derive(Clone, Debug, Default, SrcReferrer)]
pub struct ParameterValue {
pub specified_type: Option<Type>,
pub default_value: Option<Value>,
pub src_ref: SrcRef,
}
impl ParameterValue {
pub fn invalid(src_ref: SrcRef) -> Self {
Self {
specified_type: None,
default_value: None,
src_ref,
}
}
}
impl Ty for ParameterValue {
fn ty(&self) -> Type {
if let Some(ty) = &self.specified_type {
ty.clone()
} else if let Some(def) = &self.default_value {
def.ty()
} else {
Type::Invalid
}
}
}
impl std::fmt::Display for ParameterValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(def) = &self.default_value {
write!(f, "{} = {def}", def.ty())?;
} else if let Some(ty) = &self.specified_type {
write!(f, "= {ty}")?;
}
Ok(())
}
}
#[test]
fn test_is_list_of() {
assert!(
Type::Array(Box::new(QuantityType::Scalar.into()))
.is_array_of(&QuantityType::Scalar.into())
);
}