1
use crate::ast::ReturnType;
2
use polyquine::Quine;
3
use serde::{Deserialize, Serialize};
4
use std::fmt::{Debug, Display};
5
use std::hash::Hash;
6
use uniplate::derive_unplateable;
7

            
8
derive_unplateable!(Metadata);
9

            
10
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default, Quine)]
11
#[path_prefix(conjure_cp::ast)]
12
pub struct Metadata {
13
    pub clean: bool,
14
    pub etype: Option<ReturnType>,
15
    #[serde(default, skip_serializing_if = "Option::is_none")]
16
    pub span_id: Option<u32>,
17
}
18

            
19
impl Metadata {
20
10542764
    pub fn new() -> Metadata {
21
10542764
        Metadata {
22
10542764
            clean: false,
23
10542764
            etype: None,
24
10542764
            span_id: None,
25
10542764
        }
26
10542764
    }
27

            
28
    pub fn with_span_id(span_id: u32) -> Metadata {
29
        Metadata {
30
            clean: false,
31
            etype: None,
32
            span_id: Some(span_id),
33
        }
34
    }
35

            
36
24000
    pub fn clone_dirty(&self) -> Metadata {
37
24000
        Metadata {
38
24000
            clean: false,
39
24000
            ..self.clone()
40
24000
        }
41
24000
    }
42
}
43

            
44
impl Display for Metadata {
45
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46
        write!(f, "Metadata")
47
    }
48
}
49

            
50
impl Hash for Metadata {
51
    fn hash<H: std::hash::Hasher>(&self, _state: &mut H) {
52
        // Dummy method - Metadata is ignored when hashing an Expression
53
    }
54
}