smt_lang/problem/
parameter.rs1use super::*;
2use crate::parser::Position;
3
4#[derive(Clone, PartialEq, Eq, Hash, Debug)]
7pub struct Parameter {
8 name: String,
9 typ: Type,
10 position: Option<Position>,
11}
12
13impl Parameter {
14 pub fn new<S: Into<String>>(name: S, typ: Type, position: Option<Position>) -> Self {
15 let name = name.into();
16 Self {
17 name,
18 typ,
19 position,
20 }
21 }
22
23 pub fn name(&self) -> &str {
24 &self.name
25 }
26
27 pub fn is_same(&self, other: &Parameter) -> bool {
28 self.name == other.name && self.typ == other.typ
29 }
30
31 pub fn check_bounded(&self, problem: &Problem) -> Result<(), Error> {
34 if self.typ.is_bounded() {
35 Ok(())
36 } else {
37 Err(Error::Bounded {
38 name: self.to_lang(problem),
39 position: self.position.clone(),
40 })
41 }
42 }
43}
44
45impl WithType for Parameter {
48 fn typ(&self) -> &Type {
49 &self.typ
50 }
51
52 fn set_type(&mut self, typ: Type) {
53 self.typ = typ
54 }
55
56 fn resolve_type_children(&mut self, _: &TypeEntries) -> Result<(), Error> {
57 Ok(())
58 }
59
60 fn check_interval_children(&self, _: &Problem) -> Result<(), Error> {
61 Ok(())
62 }
63}
64
65impl WithPosition for Parameter {
68 fn position(&self) -> &Option<Position> {
69 &self.position
70 }
71}
72
73impl ToLang for Parameter {
76 fn to_lang(&self, problem: &Problem) -> String {
77 format!("{}: {}", self.name(), self.typ.to_lang(problem))
78 }
79}