Skip to content

Commit 57f5927

Browse files
Merge pull request #806 from allredj/string-axioms-corrections
Various improvements in string refinement
2 parents cc3e3cc + 94e9c64 commit 57f5927

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

src/solvers/refinement/string_constraint_generator_main.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ string_exprt string_constraint_generatort::fresh_string(
177177
symbol_exprt content=fresh_symbol("string_content", type.get_content_type());
178178
string_exprt str(length, content, type);
179179
created_strings.insert(str);
180+
add_default_axioms(str);
180181
return str;
181182
}
182183

@@ -246,7 +247,7 @@ string_exprt string_constraint_generatort::convert_java_string_to_string_exprt(
246247

247248
/*******************************************************************\
248249
249-
Function: string_constraint_generatort::add_default_constraints
250+
Function: string_constraint_generatort::add_default_axioms
250251
251252
Inputs:
252253
s - a string expression
@@ -267,7 +268,8 @@ Function: string_constraint_generatort::add_default_constraints
267268
void string_constraint_generatort::add_default_axioms(
268269
const string_exprt &s)
269270
{
270-
s.axiom_for_is_longer_than(from_integer(0, s.length().type()));
271+
axioms.push_back(
272+
s.axiom_for_is_longer_than(from_integer(0, s.length().type())));
271273
if(max_string_length!=std::numeric_limits<size_t>::max())
272274
axioms.push_back(s.axiom_for_is_shorter_than(max_string_length));
273275

src/solvers/refinement/string_refinement.cpp

+44-18
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
{
@@ -332,7 +350,6 @@ void string_refinementt::concretize_string(const exprt &expr)
332350
{
333351
string_exprt str=to_string_expr(expr);
334352
exprt length=get(str.length());
335-
add_lemma(equal_exprt(str.length(), length));
336353
exprt content=str.content();
337354
replace_expr(symbol_resolve, content);
338355
found_length[content]=length;
@@ -350,6 +367,7 @@ void string_refinementt::concretize_string(const exprt &expr)
350367
else
351368
{
352369
size_t concretize_limit=found_length.to_long();
370+
assert(concretize_limit<=generator.max_string_length);
353371
concretize_limit=concretize_limit>generator.max_string_length?
354372
generator.max_string_length:concretize_limit;
355373
exprt content_expr=str.content();
@@ -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

@@ -596,7 +616,11 @@ decision_proceduret::resultt string_refinementt::dec_solve()
596616
do_concretizing=false;
597617
}
598618
else
619+
{
620+
debug() << "check_SAT: the model is correct and "
621+
<< "does not need concretizing" << eom;
599622
return D_SATISFIABLE;
623+
}
600624
}
601625

602626
display_index_set();
@@ -611,6 +635,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
611635
}
612636
break;
613637
default:
638+
debug() << "check_SAT: default return " << res << eom;
614639
return res;
615640
}
616641
}
@@ -1032,16 +1057,17 @@ void string_refinementt::substitute_array_access(exprt &expr) const
10321057
}
10331058

10341059
auto op_it=++array_expr.operands().rbegin();
1060+
10351061
for(size_t i=last_index-1;
10361062
op_it!=array_expr.operands().rend(); ++op_it, --i)
10371063
{
10381064
equal_exprt equals(index_expr.index(), from_integer(i, java_int_type()));
1039-
ite=if_exprt(equals, *op_it, ite);
1040-
if(ite.type()!=char_type)
1065+
if(op_it->type()!=char_type)
10411066
{
1042-
assert(ite.id()==ID_unknown);
1043-
ite.type()=char_type;
1067+
assert(op_it->id()==ID_unknown);
1068+
op_it->type()=char_type;
10441069
}
1070+
ite=if_exprt(equals, *op_it, ite);
10451071
}
10461072
expr=ite;
10471073
}
@@ -1747,7 +1773,7 @@ exprt string_refinementt::substitute_array_lists(exprt expr) const
17471773
expr.operands()[0],
17481774
expr.operands()[1]);
17491775

1750-
for(size_t i=2; i<expr.operands().size()/2; i++)
1776+
for(size_t i=1; i<expr.operands().size()/2; i++)
17511777
{
17521778
ret_expr=with_exprt(ret_expr,
17531779
expr.operands()[i*2],

0 commit comments

Comments
 (0)