microcad_lang/value/
argument_value.rs1use microcad_lang_base::{SrcRef, SrcReferrer};
7
8use crate::{syntax::*, ty::*, value::*};
9
10#[derive(Clone)]
12pub struct ArgumentValue {
13 pub value: Value,
15 pub inline_id: Option<Identifier>,
17 src_ref: SrcRef,
19}
20
21impl SrcReferrer for ArgumentValue {
22 fn src_ref(&self) -> SrcRef {
23 self.src_ref.clone()
24 }
25}
26
27impl std::fmt::Display for ArgumentValue {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 write!(f, "{val}", val = self.value,)
30 }
31}
32
33impl std::fmt::Debug for ArgumentValue {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{val:?}", val = self.value)
36 }
37}
38
39impl Ty for ArgumentValue {
40 fn ty(&self) -> Type {
41 self.value.ty()
42 }
43}
44
45impl ArgumentValue {
46 pub fn new(value: Value, inline_id: Option<Identifier>, src_ref: SrcRef) -> Self {
48 Self {
49 value,
50 inline_id,
51 src_ref,
52 }
53 }
54
55 pub fn ty_inner(&self) -> Type {
57 if let Type::Array(ty) = self.ty() {
58 ty.as_ref().clone()
59 } else {
60 Type::Invalid
61 }
62 }
63}