microcad_lang/lower/ir/call/
argument.rs1use crate::lower::ir;
7
8use microcad_lang_base::{Identifier, OrdMapValue, SrcRef};
9use microcad_lang_proc_macros::SrcReferrer;
10
11#[derive(Clone, Debug, PartialEq, SrcReferrer)]
13pub struct Argument {
14 pub id: Option<Identifier>,
16 pub expression: ir::Expression,
18 pub src_ref: SrcRef,
20}
21
22impl OrdMapValue<Identifier> for Argument {
23 fn key(&self) -> Option<Identifier> {
24 self.id.clone()
25 }
26}
27
28impl std::fmt::Display for Argument {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 match self.id {
31 Some(ref id) => write!(f, "{id} = {}", self.expression),
32 None => write!(f, "{}", self.expression),
33 }
34 }
35}
36
37#[test]
38fn test_argument_debug() {
39 let arg1 = Argument {
40 id: Some("id1".into()),
41 expression: ir::Expression::QualifiedName("my::name1".into()),
42 src_ref: SrcRef::none(),
43 };
44
45 let arg2 = Argument {
46 id: None,
47 expression: ir::Expression::QualifiedName("my::name2".into()),
48 src_ref: SrcRef::none(),
49 };
50
51 let arg3 = Argument {
52 id: Some(Identifier::none()),
53 expression: ir::Expression::QualifiedName("my::name2".into()),
54 src_ref: SrcRef::none(),
55 };
56
57 let mut args = ir::ArgumentList::default();
58
59 args.try_push(arg1).expect("test error");
60 args.try_push(arg2).expect("test error");
61 args.try_push(arg3).expect("test error");
62
63 log::info!("{args}");
64 log::info!("{args:?}");
65}