@@ -1188,36 +1188,18 @@ exprt fill_in_array_expr(const array_exprt &expr, std::size_t string_max_length)
1188
1188
// / expressions: for instance in array access `arr[index]`, where:
1189
1189
// / `arr := {12, 24, 48}` the constructed expression will be:
1190
1190
// / `index==0 ? 12 : index==1 ? 24 : 48`
1191
+ // / Avoids repetition so `arr := {12, 12, 24, 48}` will give
1192
+ // / `index<=1 ? 12 : index==1 ? 24 : 48`
1191
1193
static exprt substitute_array_access (
1192
1194
const array_exprt &array_expr,
1193
1195
const exprt &index,
1194
1196
const std::function<symbol_exprt(const irep_idt &, const typet &)>
1195
1197
&symbol_generator)
1196
1198
{
1197
1199
const typet &char_type = array_expr.type ().subtype ();
1198
- const typet &index_type = to_array_type (array_expr.type ()).size ().type ();
1199
- const std::vector<exprt> &operands = array_expr.operands ();
1200
-
1201
- exprt result = symbol_generator (" out_of_bound_access" , char_type);
1202
-
1203
- for (std::size_t i = 0 ; i < operands.size (); ++i)
1204
- {
1205
- // Go in reverse order so that smaller indexes appear first in the result
1206
- const std::size_t pos = operands.size () - 1 - i;
1207
- const equal_exprt equals (index , from_integer (pos, index_type));
1208
- if (operands[pos].type () != char_type)
1209
- {
1210
- INVARIANT (
1211
- operands[pos].id () == ID_unknown,
1212
- string_refinement_invariantt (
1213
- " elements can only have type char or "
1214
- " unknown, and it is not char type" ));
1215
- result = if_exprt (equals, exprt (ID_unknown, char_type), result);
1216
- }
1217
- else
1218
- result = if_exprt (equals, operands[pos], result);
1219
- }
1220
- return result;
1200
+ const exprt default_val = symbol_generator (" out_of_bound_access" , char_type);
1201
+ const interval_sparse_arrayt sparse_array (array_expr, default_val);
1202
+ return sparse_array.to_if_expression (index );
1221
1203
}
1222
1204
1223
1205
static exprt substitute_array_access (
0 commit comments