Skip to content

Commit b84d9d5

Browse files
Handling of if_exprt in checking universal axioms of string solver
1 parent 2e6d2ce commit b84d9d5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,15 @@ exprt string_refinementt::substitute_array_with_expr(
859859
}
860860

861861
/// 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`
865871
/// \param expr: an expression containing array accesses
866872
/// \return an expression containing no array access
867873
void string_refinementt::substitute_array_access(exprt &expr) const
@@ -892,6 +898,18 @@ void string_refinementt::substitute_array_access(exprt &expr) const
892898
return;
893899
}
894900

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+
895913
assert(index_expr.array().id()==ID_array);
896914
array_exprt &array_expr=to_array_expr(index_expr.array());
897915

0 commit comments

Comments
 (0)