-
Notifications
You must be signed in to change notification settings - Fork 1
/
pred_abs_exercise.cc
95 lines (83 loc) · 2.33 KB
/
pred_abs_exercise.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "pred_abs_exercise.h"
void PredAbs::alloc_state(state& st, int n) {
SMTLibParser<IMathSAT> parser(iface);
for(auto it = prog.vars.begin() ; it!=prog.vars.end() ; it++) {
const std::string& name = it->first;
sexp_t* tp = it->second;
IMathSAT::type rtp = parser.parse_type(tp);
std::ostringstream conv;
conv << name << "_" << n;
IMathSAT::decl var = iface.make_decl(conv.str(),rtp);
st.insert(state::value_type(name,var));
}
}
void PredAbs::init_state(state& st) {
SMTLibParser<IMathSAT> parser(iface);
for(auto it = st.begin(); it!=st.end(); it++) {
parser.add_named_term(it->first,it->second);
}
for(auto it = prog.inits.begin(); it!=prog.inits.end(); it++) {
IMathSAT::term t = parser.parse_term(*it);
iface.assert(t);
}
}
void PredAbs::transition(state& from,state& to) {
SMTLibParser<IMathSAT> parser(iface);
for(auto it = from.begin() ; it!=from.end() ; it++) {
parser.add_named_term(it->first,it->second);
}
for(auto it = to.begin() ; it!=to.end() ; it++) {
parser.add_named_term(it->first+"_",it->second);
}
for(auto it = prog.trans.begin() ; it!=prog.trans.end() ; it++) {
IMathSAT::term t = parser.parse_term(*it);
iface.assert(t);
}
}
void PredAbs::neg_property(state& st) {
std::vector<IMathSAT::term> vec;
SMTLibParser<IMathSAT> parser(iface);
for(auto it = st.begin() ; it!=st.end() ; it++) {
parser.add_named_term(it->first,it->second);
}
for(auto it = prog.props.begin() ; it!=prog.props.end() ; it++) {
IMathSAT::term t = parser.parse_term(*it);
vec.push_back(iface.make_not(t));
}
iface.assert(iface.make_or(vec));
}
void PredAbs::add_state(abs_state& st) {
// TODO
}
void PredAbs::assert_abstract(state& st, abs_state& abs) {
// TODO
}
void PredAbs::extract_states(state& st) {
// TODO
}
void PredAbs::add_init_states() {
// TODO
}
bool PredAbs::check_abstract_state(abs_state& st) {
// TODO
return false;
}
void PredAbs::add_transition_states(abs_state& src) {
// TODO
}
PredAbs::PredAbs(int fd,IMathSAT& i) : prog(fd), iface(i) {
alloc_state(from,0);
alloc_state(to,1);
}
bool PredAbs::check() {
add_init_states();
while(!todo.empty()) {
abs_state cur = todo.back();
todo.pop_back();
if(!check_abstract_state(cur)) {
return false;
}
add_transition_states(cur);
}
return true;
}