@@ -218,16 +218,20 @@ bool string_refinementt::add_axioms_for_string_assigns(
218
218
add_symbol_to_symbol_map (lhs, rhs);
219
219
return false ;
220
220
}
221
- else if (rhs.id () == ID_nondet_symbol)
221
+ else if (rhs.id ()== ID_nondet_symbol)
222
222
{
223
223
add_symbol_to_symbol_map (
224
224
lhs, generator.fresh_symbol (" nondet_array" , lhs.type ()));
225
225
return false ;
226
226
}
227
+ else if (rhs.id ()==ID_if)
228
+ {
229
+ generator.add_axioms_for_if_array (lhs, to_if_expr (rhs));
230
+ return false ;
231
+ }
227
232
else
228
233
{
229
- debug () << " string_refinement warning: not handling char_array: "
230
- << from_expr (ns, " " , rhs) << eom;
234
+ warning () << " ignoring char array " << from_expr (ns, " " , rhs) << eom;
231
235
return true ;
232
236
}
233
237
}
@@ -370,8 +374,8 @@ void string_refinementt::set_to(const exprt &expr, bool value)
370
374
371
375
if (eq_expr.lhs ().type ()!=eq_expr.rhs ().type ())
372
376
{
373
- debug () << " (sr::set_to) WARNING: ignoring "
374
- << from_expr (ns, " " , expr) << " [inconsistent types]" << eom;
377
+ warning () << " ignoring " << from_expr (ns, " " , expr)
378
+ << " [inconsistent types]" << eom;
375
379
debug () << " lhs has type: " << eq_expr.lhs ().type ().pretty (12 ) << eom;
376
380
debug () << " rhs has type: " << eq_expr.rhs ().type ().pretty (12 ) << eom;
377
381
return ;
@@ -392,8 +396,7 @@ void string_refinementt::set_to(const exprt &expr, bool value)
392
396
// TODO: See if this happens at all.
393
397
if (lhs.id ()!=ID_symbol)
394
398
{
395
- debug () << " (sr::set_to) WARNING: ignoring "
396
- << from_expr (ns, " " , expr) << eom;
399
+ warning () << " ignoring " << from_expr (ns, " " , expr) << eom;
397
400
return ;
398
401
}
399
402
@@ -404,9 +407,8 @@ void string_refinementt::set_to(const exprt &expr, bool value)
404
407
subst_rhs.type ().id () != ID_array ||
405
408
eq_expr.lhs ().type ().subtype () != subst_rhs.type ().subtype ())
406
409
{
407
- debug () << " (sr::set_to) WARNING: ignoring "
408
- << from_expr (ns, " " , expr) << " [inconsistent types after substitution]"
409
- << eom;
410
+ warning () << " ignoring " << from_expr (ns, " " , expr)
411
+ << " [inconsistent types after substitution]" << eom;
410
412
return ;
411
413
}
412
414
else
@@ -857,9 +859,15 @@ exprt string_refinementt::substitute_array_with_expr(
857
859
}
858
860
859
861
// / create an equivalent expression where array accesses and 'with' expressions
860
- // / are replaced by 'if' expressions. e.g. for an array access arr[x], where:
861
- // / `arr := {12, 24, 48}` the constructed expression will be: `index==0 ? 12 :
862
- // / index==1 ? 24 : 48`
862
+ // / are replaced by 'if' expressions, in particular:
863
+ // / * for an array access `arr[x]`, where:
864
+ // / `arr := {12, 24, 48}` the constructed expression will be:
865
+ // / `index==0 ? 12 : index==1 ? 24 : 48`
866
+ // / * for an array access `arr[x]`, where:
867
+ // / `arr := array_of(12) with {0:=24} with {2:=42}` the constructed
868
+ // / expression will be: `index==0 ? 24 : index==2 ? 42 : 12`
869
+ // / * for an array access `(g1?arr1:arr2)[x]` where `arr1 := {12}` and
870
+ // / `arr2 := {34}`, the constructed expression will be: `g1 ? 12 : 34`
863
871
// / \param expr: an expression containing array accesses
864
872
// / \return an expression containing no array access
865
873
void string_refinementt::substitute_array_access (exprt &expr) const
@@ -890,6 +898,18 @@ void string_refinementt::substitute_array_access(exprt &expr) const
890
898
return ;
891
899
}
892
900
901
+ if (index_expr.array ().id ()==ID_if)
902
+ {
903
+ // Substitute recursively in branches of conditional expressions
904
+ if_exprt if_expr=to_if_expr (index_expr.array ());
905
+ exprt true_case=index_exprt (if_expr.true_case (), index_expr.index ());
906
+ substitute_array_access (true_case);
907
+ exprt false_case=index_exprt (if_expr.false_case (), index_expr.index ());
908
+ substitute_array_access (false_case);
909
+ expr=if_exprt (if_expr.cond (), true_case, false_case);
910
+ return ;
911
+ }
912
+
893
913
assert (index_expr.array ().id ()==ID_array);
894
914
array_exprt &array_expr=to_array_expr (index_expr.array ());
895
915
0 commit comments