rustproof_libsmt/backends/
backend.rs1use std::collections::HashMap;
5use std::fmt::Debug;
6use std::fmt;
7
8use backends::smtlib2::SMTProc;
9
10#[derive(Clone, Debug)]
11pub enum SMTError {
12 Undefined,
13 Unsat,
14 AssertionError(String),
15}
16
17#[derive(Clone, Debug)]
18pub enum SMTRes {
19 Sat(String, Option<String>),
20 Unsat(String, Option<String>),
21 Error(String, Option<String>),
22}
23
24
25pub type SMTResult<T> = Result<T, SMTError>;
26
27pub trait SMTBackend {
49 type Idx: Debug + Clone;
50 type Logic: Logic;
51
52 fn set_logic<S: SMTProc>(&mut self, &mut S);
53 fn new_var<T, P>(&mut self, Option<T>, P) -> Self::Idx
56 where T: AsRef<str>,
57 P: Into<<<Self as SMTBackend>::Logic as Logic>::Sorts>;
58
59 fn assert<T: Into<<<Self as SMTBackend>::Logic as Logic>::Fns>>(&mut self, T, &[Self::Idx]) -> Self::Idx;
60 fn check_sat<S: SMTProc>(&mut self, &mut S, bool) -> SMTRes;
61 fn solve<S: SMTProc>(&mut self, &mut S, bool) -> (SMTResult<HashMap<Self::Idx, u64>>, SMTRes);
62}
63
64pub trait Logic: fmt::Display + Clone + Copy {
65 type Fns: SMTNode + fmt::Display + Debug + Clone;
66 type Sorts: fmt::Display + Debug + Clone;
67
68 fn free_var<T: AsRef<str>>(T, Self::Sorts) -> Self::Fns;
69}
70
71pub trait SMTNode: fmt::Display {
72 fn is_var(&self) -> bool;
74 fn is_const(&self) -> bool;
76 fn is_fn(&self) -> bool {
78 !self.is_var() && !self.is_const()
79 }
80}