1414#include < cegis/learn/insert_counterexample.h>
1515
1616#define CE_ARRAY_PREFIX CPROVER_PREFIX " ce_array_"
17- #define CE_ARRAY_INDEX CPROVER_PREFIX " ce_array_index"
1817#define CE_VALUES_INDEX_PREFIX CPROVER_PREFIX " ce_values_index_"
1918
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,
2520 const goto_programt::targetst &ce_locs)
2621{
2722 std::map<const irep_idt, exprt> zero_values;
28- const goto_programt::instructionst &body=get_entry_body (gf).instructions ;
2923 const source_locationt loc (default_cegis_source_location ());
3024 const namespacet ns (st);
3125 null_message_handlert msg;
@@ -39,16 +33,7 @@ zero_valuest get_zero_values(const symbol_tablet &st, const goto_functionst &gf,
3933 return zero_values;
4034}
4135
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,
5237 labelled_counterexamplest &ces)
5338{
5439 const exprt::operandst no_values;
@@ -89,7 +74,16 @@ void normalise(const std::set<irep_idt> ce_keys, const zero_valuest &zv,
8974 }
9075}
9176
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+ }
9387
9488array_exprt to_values (const exprt::operandst &ops)
9589{
@@ -101,6 +95,7 @@ array_exprt to_values(const exprt::operandst &ops)
10195 copy (ops.begin (), ops.end (), std::back_inserter (result.operands ()));
10296 return result;
10397}
98+ }
10499
105100array_valuest get_array_values (const labelled_counterexamplest &ces)
106101{
@@ -123,12 +118,20 @@ array_valuest get_array_values(const labelled_counterexamplest &ces)
123118 return result;
124119}
125120
126- std::string get_array_name (const irep_idt &loc_id)
121+ std::string get_ce_array_name (const irep_idt &loc_id)
127122{
128123 std::string base_name (CE_ARRAY_PREFIX);
129124 return base_name+=id2string (loc_id);
130125}
131126
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+ {
132135void add_array_declarations (symbol_tablet &st, goto_functionst &gf,
133136 const labelled_counterexamplest &ces, const goto_programt::targett &begin)
134137{
@@ -141,25 +144,16 @@ void add_array_declarations(symbol_tablet &st, goto_functionst &gf,
141144 for (const labelled_counterexamplest::value_type::value_type &value : prototype)
142145 {
143146 const labelled_assignmentst::value_type::first_type loc_id=value.first ;
144- const typet &org_type=value.second .front ().type ();
145147 const array_valuest::const_iterator array_val=array_values.find (loc_id);
146148 assert (array_values.end () != array_val);
147149 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 ());
152152 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 );
154154 }
155155}
156156
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-
163157void add_array_indexes (const std::set<irep_idt> &ce_keys, symbol_tablet &st,
164158 goto_functionst &gf)
165159{
@@ -176,7 +170,7 @@ void add_array_indexes(const std::set<irep_idt> &ce_keys, symbol_tablet &st,
176170 pos=cprover_init;
177171 for (const irep_idt &key : ce_keys)
178172 {
179- const std::string label (get_value_index (key));
173+ const std::string label (get_ce_value_index_name (key));
180174 pos=declare_cegis_meta_variable (st, gf, pos, label, type);
181175 pos=assign_cegis_meta_variable (st, gf, pos, label, zero);
182176 }
@@ -218,10 +212,10 @@ const index_exprt get_array_val_expr(const symbol_tablet &st,
218212{
219213 const std::string index_name (get_cegis_meta_name (CE_ARRAY_INDEX));
220214 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)));
222216 const symbol_exprt array (st.lookup (array_name).symbol_expr ());
223217 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)));
225219 const symbol_exprt value_index_expr (st.lookup (value_index).symbol_expr ());
226220 return index_exprt (ce, value_index_expr);
227221}
@@ -247,7 +241,7 @@ void assign_ce_values(symbol_tablet &st, goto_functionst &gf,
247241 default :
248242 assert (!" Unsupported counterexample location type." );
249243 }
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)));
251245 const symbol_exprt value_index_expr (st.lookup (value_index).symbol_expr ());
252246 const plus_exprt inc (increment (value_index_expr));
253247 cegis_assign (st, gf, pos, value_index_expr, inc);
@@ -259,7 +253,7 @@ void insert_counterexamples(symbol_tablet &st, goto_functionst &gf,
259253 labelled_counterexamplest ces, const goto_programt::targetst &ce_locs)
260254{
261255 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));
263257 const std::set<irep_idt> ce_keys (get_all_keys (zero_values));
264258 normalise (ce_keys, zero_values, ces);
265259 goto_programt &body=get_entry_body (gf);
0 commit comments