Skip to content

Commit e18a6bd

Browse files
Add a function interpreting arrays inside an expression
This interpret them in a way that makes sense to the string solver, by propagating values to the left.
1 parent 0b9811b commit e18a6bd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/solvers/refinement/string_refinement.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Alberto Griggio, [email protected]
2424
#include <stack>
2525
#include <ansi-c/string_constant.h>
2626
#include <util/cprover_prefix.h>
27+
#include <util/expr_iterator.h>
2728
#include <util/replace_expr.h>
2829
#include <util/refined_string_type.h>
2930
#include <util/simplify_expr.h>
@@ -1087,6 +1088,32 @@ static exprt negation_of_constraint(const string_constraintt &axiom)
10871088
return negaxiom;
10881089
}
10891090

1091+
/// Result of the solver `supert` should not be interpreted literally for char
1092+
/// arrays as not all indices are present in the index set.
1093+
/// In the given expression, we populate arrays at the indices for which the
1094+
/// solver has no constraint by copying values to the left.
1095+
/// For example an expression `ARRAY_OF(0) WITH [1:=2] WITH [4:=3]` would
1096+
/// be interpreted as `{ 2, 2, 3, 3, 3}`.
1097+
/// \param expr: expression to interpret
1098+
/// \param string_max_length: maximum size of arrays to consider
1099+
/// \return the interpreted expression
1100+
exprt concretize_arrays_in_expression(exprt expr, std::size_t string_max_length)
1101+
{
1102+
auto it=expr.depth_begin();
1103+
const auto end=expr.depth_end();
1104+
while(it!=end)
1105+
{
1106+
if(it->id()==ID_with && it->type().id()==ID_array)
1107+
{
1108+
it.mutate()=fill_in_array_with_expr(*it, string_max_length);
1109+
it.next_sibling_or_parent();
1110+
}
1111+
else
1112+
++it;
1113+
}
1114+
return expr;
1115+
}
1116+
10901117
/// return true if the current model satisfies all the axioms
10911118
/// \return a Boolean
10921119
bool string_refinementt::check_axioms()

0 commit comments

Comments
 (0)