smt_lang/problem/
instance.rs

1use super::*;
2use crate::parser::Position;
3
4//------------------------- Id -------------------------
5
6#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
7pub struct InstanceId(pub usize);
8
9impl Id for InstanceId {
10    fn empty() -> Self {
11        Self(0)
12    }
13}
14
15//------------------------- Instance -------------------------
16
17#[derive(Clone)]
18pub struct Instance {
19    id: InstanceId,
20    name: String,
21    typ: Type,
22    position: Option<Position>,
23}
24
25impl Instance {
26    pub fn new<S: Into<String>>(name: S, typ: Type, position: Option<Position>) -> Self {
27        let id = InstanceId::empty();
28        let name = name.into();
29        Self {
30            id,
31            name,
32            typ,
33            position,
34        }
35    }
36}
37
38//------------------------- Postion -------------------------
39
40impl WithPosition for Instance {
41    fn position(&self) -> &Option<Position> {
42        &self.position
43    }
44}
45
46//------------------------- Named -------------------------
47
48impl Named<InstanceId> for Instance {
49    fn id(&self) -> InstanceId {
50        self.id
51    }
52
53    fn set_id(&mut self, id: InstanceId) {
54        self.id = id;
55    }
56
57    fn name(&self) -> &str {
58        &self.name
59    }
60}
61
62//------------------------- WithType -------------------------
63
64impl WithType for Instance {
65    fn typ(&self) -> &Type {
66        &self.typ
67    }
68
69    fn set_type(&mut self, typ: Type) {
70        self.typ = typ
71    }
72
73    fn resolve_type_children(&mut self, _: &TypeEntries) -> Result<(), Error> {
74        Ok(())
75    }
76
77    fn check_interval_children(&self, _: &Problem) -> Result<(), Error> {
78        Ok(())
79    }
80}
81
82//------------------------- ToLang -------------------------
83
84impl ToLang for Instance {
85    fn to_lang(&self, problem: &Problem) -> String {
86        format!("inst {}: {}", self.name(), self.typ.to_lang(problem))
87    }
88}