1
use std::fmt;
2
use std::ops::Deref;
3

            
4
use delegate::delegate;
5

            
6
use merc_aterm::ATerm;
7
use merc_aterm::ATermArgs;
8
use merc_aterm::ATermIndex;
9
use merc_aterm::ATermRef;
10
use merc_aterm::ATermString;
11
use merc_aterm::Markable;
12
use merc_aterm::Symb;
13
use merc_aterm::SymbolRef;
14
use merc_aterm::Term;
15
use merc_aterm::TermIterator;
16
use merc_aterm::Transmutable;
17
use merc_aterm::storage::Marker;
18
use merc_macros::merc_derive_terms;
19
use merc_macros::merc_term;
20

            
21
use crate::DATA_SYMBOLS;
22
use crate::is_basic_sort;
23
use crate::is_sort_expression;
24

            
25
/// This module is only used internally to run the proc macro.
26
#[merc_derive_terms]
27
mod inner {
28
    use super::*;
29

            
30
    #[merc_term(is_sort_expression)]
31
    pub struct SortExpression {
32
        term: ATerm,
33
    }
34

            
35
    impl SortExpression {
36
        /// Returns the name of the sort.
37
        pub fn name(&self) -> &str {
38
            self.term.arg(0).get_head_symbol().name()
39
        }
40

            
41
        /// Creates a basic sort with the unknown value.
42
110747
        pub fn unknown_sort() -> SortExpression {
43
110747
            DATA_SYMBOLS.with_borrow(|ds| SortExpression {
44
110747
                term: ATerm::with_args(ds.basic_sort_symbol.deref(), &[ATermString::new("@no_value@")]).protect(),
45
110747
            })
46
110747
        }
47
    }
48

            
49
    impl fmt::Display for SortExpression {
50
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51
            write!(f, "{}", self.name())
52
        }
53
    }
54

            
55
    #[merc_term(is_basic_sort)]
56
    pub struct BasicSort {
57
        term: ATerm,
58
    }
59

            
60
    impl BasicSort {
61
        /// Returns the name of the sort.
62
        pub fn name(&self) -> &str {
63
            self.term.arg(0).get_head_symbol().name()
64
        }
65
    }
66

            
67
    impl fmt::Display for BasicSort {
68
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69
            write!(f, "{}", self.name())
70
        }
71
    }
72
}
73

            
74
pub use inner::*;