Skip to content

Commit 94e9c64

Browse files
romainbrenguierJoel Allred
authored and
Joel Allred
committed
Various improvements in string refinement
Update documentation of the string refinement Correct bounds in substitute_array_lists adding debugging information Fixing the manual setting of type in if expressions When converting array accesses to if expressions, the check made on the type for the case of unknown value was not done correctly and could cause an assertion violation or a mismatch in types.
1 parent f0004a5 commit 94e9c64

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

src/solvers/refinement/string_refinement.cpp

+38-17
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ Author: Alberto Griggio, [email protected]
2626
2727
Constructor: string_refinementt
2828
29-
Inputs: a namespace, a decision procedure, a bound on the number
30-
of refinements and a boolean flag `concretize_result`
29+
Inputs:
30+
_ns - a namespace
31+
_prop - a decision procedure
32+
refinement_bound - a bound on the number of refinements
3133
3234
Purpose: refinement_bound is a bound on the number of refinement allowed.
33-
if `concretize_result` is set to true, at the end of the decision
34-
procedure, the solver try to find a concrete value for each
35-
character
3635
3736
\*******************************************************************/
3837

@@ -167,15 +166,17 @@ void string_refinementt::add_instantiations()
167166
168167
Function: string_refinementt::add_symbol_to_symbol_map()
169168
170-
Inputs: a symbol and the expression to map it to
169+
Inputs:
170+
lhs - a symbol expression
171+
rhs - an expression to map it to
171172
172173
Purpose: keeps a map of symbols to expressions, such as none of the
173174
mapped values exist as a key
174175
175176
\*******************************************************************/
176177

177-
void string_refinementt::add_symbol_to_symbol_map
178-
(const exprt &lhs, const exprt &rhs)
178+
void string_refinementt::add_symbol_to_symbol_map(
179+
const exprt &lhs, const exprt &rhs)
179180
{
180181
assert(lhs.id()==ID_symbol);
181182

@@ -259,6 +260,21 @@ exprt string_refinementt::substitute_function_applications(exprt expr)
259260
return expr;
260261
}
261262

263+
/*******************************************************************\
264+
265+
Function: string_refinementt::is_char_array
266+
267+
Inputs:
268+
type - a type
269+
270+
Outputs: true if the given type is an array of java characters
271+
272+
Purpose: distinguish char array from other types
273+
274+
TODO: this is only for java char array and does not work for other languages
275+
276+
\*******************************************************************/
277+
262278
bool string_refinementt::is_char_array(const typet &type) const
263279
{
264280
if(type.id()==ID_symbol)
@@ -269,18 +285,20 @@ bool string_refinementt::is_char_array(const typet &type) const
269285

270286
/*******************************************************************\
271287
272-
Function: string_refinementt::boolbv_set_equality_to_true
288+
Function: string_refinementt::add_axioms_for_string_assigns
273289
274-
Inputs: the lhs and rhs of an equality expression
290+
Inputs:
291+
lhs - left hand side of an equality expression
292+
rhs - right and side of the equality
275293
276294
Outputs: false if the lemmas were added successfully, true otherwise
277295
278296
Purpose: add lemmas to the solver corresponding to the given equation
279297
280298
\*******************************************************************/
281299

282-
bool string_refinementt::add_axioms_for_string_assigns(const exprt &lhs,
283-
const exprt &rhs)
300+
bool string_refinementt::add_axioms_for_string_assigns(
301+
const exprt &lhs, const exprt &rhs)
284302
{
285303
if(is_char_array(rhs.type()))
286304
{
@@ -443,6 +461,8 @@ void string_refinementt::set_to(const exprt &expr, bool value)
443461
{
444462
debug() << "(sr::set_to) WARNING: ignoring "
445463
<< from_expr(expr) << " [inconsistent types]" << eom;
464+
debug() << "lhs has type: " << eq_expr.lhs().type().pretty(12) << eom;
465+
debug() << "rhs has type: " << eq_expr.rhs().type().pretty(12) << eom;
446466
return;
447467
}
448468

@@ -1037,16 +1057,17 @@ void string_refinementt::substitute_array_access(exprt &expr) const
10371057
}
10381058

10391059
auto op_it=++array_expr.operands().rbegin();
1060+
10401061
for(size_t i=last_index-1;
10411062
op_it!=array_expr.operands().rend(); ++op_it, --i)
10421063
{
10431064
equal_exprt equals(index_expr.index(), from_integer(i, java_int_type()));
1044-
ite=if_exprt(equals, *op_it, ite);
1045-
if(ite.type()!=char_type)
1065+
if(op_it->type()!=char_type)
10461066
{
1047-
assert(ite.id()==ID_unknown);
1048-
ite.type()=char_type;
1067+
assert(op_it->id()==ID_unknown);
1068+
op_it->type()=char_type;
10491069
}
1070+
ite=if_exprt(equals, *op_it, ite);
10501071
}
10511072
expr=ite;
10521073
}
@@ -1752,7 +1773,7 @@ exprt string_refinementt::substitute_array_lists(exprt expr) const
17521773
expr.operands()[0],
17531774
expr.operands()[1]);
17541775

1755-
for(size_t i=2; i<expr.operands().size()/2; i++)
1776+
for(size_t i=1; i<expr.operands().size()/2; i++)
17561777
{
17571778
ret_expr=with_exprt(ret_expr,
17581779
expr.operands()[i*2],

0 commit comments

Comments
 (0)