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::Markable;
11
use merc_aterm::Symb;
12
use merc_aterm::SymbolRef;
13
use merc_aterm::Term;
14
use merc_aterm::TermIterator;
15
use merc_aterm::Transmutable;
16
use merc_aterm::storage::Marker;
17
use merc_macros::merc_derive_terms;
18
use merc_macros::merc_term;
19

            
20
use crate::DATA_SYMBOLS;
21
use crate::is_sort_expression;
22

            
23
// This module is only used internally to run the proc macro.
24
#[merc_derive_terms]
25
mod inner {
26
    use merc_aterm::ATermString;
27

            
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 sort expression with the unknown value.
42
84315
        pub fn unknown_sort() -> SortExpression {
43
84315
            DATA_SYMBOLS.with_borrow(|ds| SortExpression {
44
84315
                term: ATerm::with_args(ds.sort_id_symbol.deref(), &[ATermString::new("@no_value@")]).protect(),
45
84315
            })
46
84315
        }
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

            
56
pub use inner::*;