26
26
27
27
Constructor: string_refinementt
28
28
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
31
33
32
34
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
36
35
37
36
\*******************************************************************/
38
37
@@ -167,15 +166,17 @@ void string_refinementt::add_instantiations()
167
166
168
167
Function: string_refinementt::add_symbol_to_symbol_map()
169
168
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
171
172
172
173
Purpose: keeps a map of symbols to expressions, such as none of the
173
174
mapped values exist as a key
174
175
175
176
\*******************************************************************/
176
177
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)
179
180
{
180
181
assert (lhs.id ()==ID_symbol);
181
182
@@ -259,6 +260,21 @@ exprt string_refinementt::substitute_function_applications(exprt expr)
259
260
return expr;
260
261
}
261
262
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
+
262
278
bool string_refinementt::is_char_array (const typet &type) const
263
279
{
264
280
if (type.id ()==ID_symbol)
@@ -269,18 +285,20 @@ bool string_refinementt::is_char_array(const typet &type) const
269
285
270
286
/* ******************************************************************\
271
287
272
- Function: string_refinementt::boolbv_set_equality_to_true
288
+ Function: string_refinementt::add_axioms_for_string_assigns
273
289
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
275
293
276
294
Outputs: false if the lemmas were added successfully, true otherwise
277
295
278
296
Purpose: add lemmas to the solver corresponding to the given equation
279
297
280
298
\*******************************************************************/
281
299
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)
284
302
{
285
303
if (is_char_array (rhs.type ()))
286
304
{
@@ -332,7 +350,6 @@ void string_refinementt::concretize_string(const exprt &expr)
332
350
{
333
351
string_exprt str=to_string_expr (expr);
334
352
exprt length=get (str.length ());
335
- add_lemma (equal_exprt (str.length (), length));
336
353
exprt content=str.content ();
337
354
replace_expr (symbol_resolve, content);
338
355
found_length[content]=length;
@@ -350,6 +367,7 @@ void string_refinementt::concretize_string(const exprt &expr)
350
367
else
351
368
{
352
369
size_t concretize_limit=found_length.to_long ();
370
+ assert (concretize_limit<=generator.max_string_length );
353
371
concretize_limit=concretize_limit>generator.max_string_length ?
354
372
generator.max_string_length :concretize_limit;
355
373
exprt content_expr=str.content ();
@@ -443,6 +461,8 @@ void string_refinementt::set_to(const exprt &expr, bool value)
443
461
{
444
462
debug () << " (sr::set_to) WARNING: ignoring "
445
463
<< 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;
446
466
return ;
447
467
}
448
468
@@ -596,7 +616,11 @@ decision_proceduret::resultt string_refinementt::dec_solve()
596
616
do_concretizing=false ;
597
617
}
598
618
else
619
+ {
620
+ debug () << " check_SAT: the model is correct and "
621
+ << " does not need concretizing" << eom;
599
622
return D_SATISFIABLE;
623
+ }
600
624
}
601
625
602
626
display_index_set ();
@@ -611,6 +635,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
611
635
}
612
636
break ;
613
637
default :
638
+ debug () << " check_SAT: default return " << res << eom;
614
639
return res;
615
640
}
616
641
}
@@ -1032,16 +1057,17 @@ void string_refinementt::substitute_array_access(exprt &expr) const
1032
1057
}
1033
1058
1034
1059
auto op_it=++array_expr.operands ().rbegin ();
1060
+
1035
1061
for (size_t i=last_index-1 ;
1036
1062
op_it!=array_expr.operands ().rend (); ++op_it, --i)
1037
1063
{
1038
1064
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)
1041
1066
{
1042
- assert (ite. id ()==ID_unknown);
1043
- ite. type ()=char_type;
1067
+ assert (op_it-> id ()==ID_unknown);
1068
+ op_it-> type ()=char_type;
1044
1069
}
1070
+ ite=if_exprt (equals, *op_it, ite);
1045
1071
}
1046
1072
expr=ite;
1047
1073
}
@@ -1747,7 +1773,7 @@ exprt string_refinementt::substitute_array_lists(exprt expr) const
1747
1773
expr.operands ()[0 ],
1748
1774
expr.operands ()[1 ]);
1749
1775
1750
- for (size_t i=2 ; i<expr.operands ().size ()/2 ; i++)
1776
+ for (size_t i=1 ; i<expr.operands ().size ()/2 ; i++)
1751
1777
{
1752
1778
ret_expr=with_exprt (ret_expr,
1753
1779
expr.operands ()[i*2 ],
0 commit comments