@@ -859,9 +859,15 @@ exprt string_refinementt::substitute_array_with_expr(
859
859
}
860
860
861
861
// / create an equivalent expression where array accesses and 'with' expressions
862
- // / are replaced by 'if' expressions. e.g. for an array access arr[x], where:
863
- // / `arr := {12, 24, 48}` the constructed expression will be: `index==0 ? 12 :
864
- // / 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`
865
871
// / \param expr: an expression containing array accesses
866
872
// / \return an expression containing no array access
867
873
void string_refinementt::substitute_array_access (exprt &expr) const
@@ -892,6 +898,18 @@ void string_refinementt::substitute_array_access(exprt &expr) const
892
898
return ;
893
899
}
894
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
+
895
913
assert (index_expr.array ().id ()==ID_array);
896
914
array_exprt &array_expr=to_array_expr (index_expr.array ());
897
915
0 commit comments