14
14
#include < cegis/learn/insert_counterexample.h>
15
15
16
16
#define CE_ARRAY_PREFIX CPROVER_PREFIX " ce_array_"
17
- #define CE_ARRAY_INDEX CPROVER_PREFIX " ce_array_index"
18
17
#define CE_VALUES_INDEX_PREFIX CPROVER_PREFIX " ce_values_index_"
19
18
20
- namespace
21
- {
22
- typedef std::map<const irep_idt, exprt> zero_valuest;
23
-
24
- zero_valuest get_zero_values (const symbol_tablet &st, const goto_functionst &gf,
19
+ zero_valuest get_zero_values (const symbol_tablet &st,
25
20
const goto_programt::targetst &ce_locs)
26
21
{
27
22
std::map<const irep_idt, exprt> zero_values;
28
- const goto_programt::instructionst &body=get_entry_body (gf).instructions ;
29
23
const source_locationt loc (default_cegis_source_location ());
30
24
const namespacet ns (st);
31
25
null_message_handlert msg;
@@ -39,16 +33,7 @@ zero_valuest get_zero_values(const symbol_tablet &st, const goto_functionst &gf,
39
33
return zero_values;
40
34
}
41
35
42
- std::set<irep_idt> get_all_keys (const zero_valuest &zv)
43
- {
44
- std::set<irep_idt> result;
45
- std::transform (zv.begin (), zv.end (), std::inserter (result, result.end ()),
46
- [](const zero_valuest::value_type &v)
47
- { return v.first ;});
48
- return result;
49
- }
50
-
51
- void normalise (const std::set<irep_idt> ce_keys, const zero_valuest &zv,
36
+ void normalise (const std::set<irep_idt> &ce_keys, const zero_valuest &zv,
52
37
labelled_counterexamplest &ces)
53
38
{
54
39
const exprt::operandst no_values;
@@ -89,7 +74,16 @@ void normalise(const std::set<irep_idt> ce_keys, const zero_valuest &zv,
89
74
}
90
75
}
91
76
92
- typedef std::map<labelled_assignmentst::key_type, array_exprt> array_valuest;
77
+ namespace
78
+ {
79
+ std::set<irep_idt> get_all_keys (const zero_valuest &zv)
80
+ {
81
+ std::set<irep_idt> result;
82
+ std::transform (zv.begin (), zv.end (), std::inserter (result, result.end ()),
83
+ [](const zero_valuest::value_type &v)
84
+ { return v.first ;});
85
+ return result;
86
+ }
93
87
94
88
array_exprt to_values (const exprt::operandst &ops)
95
89
{
@@ -101,6 +95,7 @@ array_exprt to_values(const exprt::operandst &ops)
101
95
copy (ops.begin (), ops.end (), std::back_inserter (result.operands ()));
102
96
return result;
103
97
}
98
+ }
104
99
105
100
array_valuest get_array_values (const labelled_counterexamplest &ces)
106
101
{
@@ -123,12 +118,20 @@ array_valuest get_array_values(const labelled_counterexamplest &ces)
123
118
return result;
124
119
}
125
120
126
- std::string get_array_name (const irep_idt &loc_id)
121
+ std::string get_ce_array_name (const irep_idt &loc_id)
127
122
{
128
123
std::string base_name (CE_ARRAY_PREFIX);
129
124
return base_name+=id2string (loc_id);
130
125
}
131
126
127
+ std::string get_ce_value_index_name (const irep_idt &loc)
128
+ {
129
+ std::string label (CE_VALUES_INDEX_PREFIX);
130
+ return label+=id2string (loc);
131
+ }
132
+
133
+ namespace
134
+ {
132
135
void add_array_declarations (symbol_tablet &st, goto_functionst &gf,
133
136
const labelled_counterexamplest &ces, const goto_programt::targett &begin)
134
137
{
@@ -141,25 +144,16 @@ void add_array_declarations(symbol_tablet &st, goto_functionst &gf,
141
144
for (const labelled_counterexamplest::value_type::value_type &value : prototype)
142
145
{
143
146
const labelled_assignmentst::value_type::first_type loc_id=value.first ;
144
- const typet &org_type=value.second .front ().type ();
145
147
const array_valuest::const_iterator array_val=array_values.find (loc_id);
146
148
assert (array_values.end () != array_val);
147
149
const array_exprt &array_expr=array_val->second ;
148
- const typet &array_type=array_expr.type ();
149
- const typet &element_type=array_type.subtype ();
150
- const std::string base_name (get_array_name (loc_id));
151
- pos=declare_cegis_meta_variable (st, gf, pos, base_name, array_type);
150
+ const std::string base_name (get_ce_array_name (loc_id));
151
+ pos=declare_cegis_meta_variable (st, gf, pos, base_name, array_expr.type ());
152
152
assert (array_expr.operands ().size () == ces.size ());
153
- pos=assign_cegis_meta_variable (st, gf, pos, base_name, array_val-> second );
153
+ pos=assign_cegis_meta_variable (st, gf, pos, base_name, array_expr );
154
154
}
155
155
}
156
156
157
- std::string get_value_index (const irep_idt &loc)
158
- {
159
- std::string label (CE_VALUES_INDEX_PREFIX);
160
- return label+=id2string (loc);
161
- }
162
-
163
157
void add_array_indexes (const std::set<irep_idt> &ce_keys, symbol_tablet &st,
164
158
goto_functionst &gf)
165
159
{
@@ -176,7 +170,7 @@ void add_array_indexes(const std::set<irep_idt> &ce_keys, symbol_tablet &st,
176
170
pos=cprover_init;
177
171
for (const irep_idt &key : ce_keys)
178
172
{
179
- const std::string label (get_value_index (key));
173
+ const std::string label (get_ce_value_index_name (key));
180
174
pos=declare_cegis_meta_variable (st, gf, pos, label, type);
181
175
pos=assign_cegis_meta_variable (st, gf, pos, label, zero);
182
176
}
@@ -218,10 +212,10 @@ const index_exprt get_array_val_expr(const symbol_tablet &st,
218
212
{
219
213
const std::string index_name (get_cegis_meta_name (CE_ARRAY_INDEX));
220
214
const symbol_exprt index (st.lookup (index_name).symbol_expr ());
221
- const std::string array_name (get_cegis_meta_name (get_array_name (loc)));
215
+ const std::string array_name (get_cegis_meta_name (get_ce_array_name (loc)));
222
216
const symbol_exprt array (st.lookup (array_name).symbol_expr ());
223
217
const index_exprt ce (array, index);
224
- const std::string value_index (get_cegis_meta_name (get_value_index (loc)));
218
+ const std::string value_index (get_cegis_meta_name (get_ce_value_index_name (loc)));
225
219
const symbol_exprt value_index_expr (st.lookup (value_index).symbol_expr ());
226
220
return index_exprt (ce, value_index_expr);
227
221
}
@@ -247,7 +241,7 @@ void assign_ce_values(symbol_tablet &st, goto_functionst &gf,
247
241
default :
248
242
assert (!" Unsupported counterexample location type." );
249
243
}
250
- const std::string value_index (get_cegis_meta_name (get_value_index (label)));
244
+ const std::string value_index (get_cegis_meta_name (get_ce_value_index_name (label)));
251
245
const symbol_exprt value_index_expr (st.lookup (value_index).symbol_expr ());
252
246
const plus_exprt inc (increment (value_index_expr));
253
247
cegis_assign (st, gf, pos, value_index_expr, inc);
@@ -259,7 +253,7 @@ void insert_counterexamples(symbol_tablet &st, goto_functionst &gf,
259
253
labelled_counterexamplest ces, const goto_programt::targetst &ce_locs)
260
254
{
261
255
assert (!ces.empty ());
262
- const zero_valuest zero_values (get_zero_values (st, gf, ce_locs));
256
+ const zero_valuest zero_values (get_zero_values (st, ce_locs));
263
257
const std::set<irep_idt> ce_keys (get_all_keys (zero_values));
264
258
normalise (ce_keys, zero_values, ces);
265
259
goto_programt &body=get_entry_body (gf);
0 commit comments