@@ -34,7 +34,7 @@ class smt2_solvert:public smt2_parsert
34
34
decision_proceduret &solver;
35
35
36
36
void command (const std::string &) override ;
37
- void define_constants (const exprt & );
37
+ void define_constants ();
38
38
void expand_function_applications (exprt &);
39
39
40
40
std::set<irep_idt> constants_done;
@@ -47,36 +47,28 @@ class smt2_solvert:public smt2_parsert
47
47
} status;
48
48
};
49
49
50
- void smt2_solvert::define_constants (const exprt &expr )
50
+ void smt2_solvert::define_constants ()
51
51
{
52
- for (const auto &op : expr.operands ())
53
- define_constants (op);
54
-
55
- if (expr.id ()==ID_symbol)
52
+ for (const auto &id : id_map)
56
53
{
57
- irep_idt identifier=to_symbol_expr (expr).get_identifier ();
54
+ if (id.second .type .id () == ID_mathematical_function)
55
+ continue ;
56
+
57
+ if (id.second .definition .is_nil ())
58
+ continue ;
59
+
60
+ const irep_idt &identifier = id.first ;
58
61
59
62
// already done?
60
63
if (constants_done.find (identifier)!=constants_done.end ())
61
- return ;
64
+ continue ;
62
65
63
66
constants_done.insert (identifier);
64
67
65
- auto f_it=id_map.find (identifier);
66
-
67
- if (f_it!=id_map.end ())
68
- {
69
- const auto &f=f_it->second ;
70
-
71
- if (f.type .id ()!=ID_mathematical_function &&
72
- f.definition .is_not_nil ())
73
- {
74
- exprt def=f.definition ;
75
- expand_function_applications (def);
76
- define_constants (def); // recursive!
77
- solver.set_to_true (equal_exprt (expr, def));
78
- }
79
- }
68
+ exprt def = id.second .definition ;
69
+ expand_function_applications (def);
70
+ solver.set_to_true (
71
+ equal_exprt (symbol_exprt (identifier, id.second .type ), def));
80
72
}
81
73
}
82
74
@@ -135,12 +127,14 @@ void smt2_solvert::command(const std::string &c)
135
127
if (e.is_not_nil ())
136
128
{
137
129
expand_function_applications (e);
138
- define_constants (e);
139
130
solver.set_to_true (e);
140
131
}
141
132
}
142
133
else if (c == " check-sat" )
143
134
{
135
+ // add constant definitions as constraints
136
+ define_constants ();
137
+
144
138
switch (solver ())
145
139
{
146
140
case decision_proceduret::resultt::D_SATISFIABLE:
@@ -200,12 +194,7 @@ void smt2_solvert::command(const std::string &c)
200
194
if (id_map_it == id_map.end ())
201
195
throw error (" unexpected symbol " + id2string (identifier));
202
196
203
- exprt value;
204
-
205
- if (id_map_it->second .definition .is_nil ())
206
- value = solver.get (op);
207
- else
208
- value = solver.get (id_map_it->second .definition );
197
+ const exprt value = solver.get (op);
209
198
210
199
if (value.is_nil ())
211
200
throw error (" no value for " + id2string (identifier));
0 commit comments