Skip to content

Commit 03667af

Browse files
romainbrenguierJoel Allred
authored and
Joel Allred
committed
Make add_axioms_from_bool add concret constraints
Adding universal constraints was not working because the index set wasn't updated for the created constants ("true" and "false"). Adding concrete constraints avoids this problem and is more efficient than updating the index set. For issue diffblue/test-gen#119
1 parent 5851f63 commit 03667af

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/solvers/refinement/string_constraint_generator_valueof.cpp

+18-21
Original file line numberDiff line numberDiff line change
@@ -228,42 +228,39 @@ string_exprt string_constraint_generatort::add_axioms_from_bool(
228228
const exprt &b, const refined_string_typet &ref_type)
229229
{
230230
string_exprt res=fresh_string(ref_type);
231-
const typet &index_type=ref_type.get_index_type();
231+
const typet &char_type=ref_type.get_char_type();
232232

233233
assert(b.type()==bool_typet() || b.type().id()==ID_c_bool);
234234

235235
typecast_exprt eq(b, bool_typet());
236236

237-
string_exprt true_string=add_axioms_for_constant("true", ref_type);
238-
string_exprt false_string=add_axioms_for_constant("false", ref_type);
239-
240237
// We add axioms:
241238
// a1 : eq => res = |"true"|
242239
// a2 : forall i < |"true"|. eq => res[i]="true"[i]
243240
// a3 : !eq => res = |"false"|
244241
// a4 : forall i < |"false"|. !eq => res[i]="false"[i]
245242

246-
implies_exprt a1(eq, res.axiom_for_has_same_length_as(true_string));
243+
std::string str_true="true";
244+
implies_exprt a1(eq, res.axiom_for_has_length(str_true.length()));
247245
axioms.push_back(a1);
248-
symbol_exprt qvar=fresh_univ_index("QA_equal_true", index_type);
249-
string_constraintt a2(
250-
qvar,
251-
true_string.length(),
252-
eq,
253-
equal_exprt(res[qvar], true_string[qvar]));
254-
axioms.push_back(a2);
255246

256-
implies_exprt a3(
257-
not_exprt(eq), res.axiom_for_has_same_length_as(false_string));
247+
for(std::size_t i=0; i<str_true.length(); i++)
248+
{
249+
exprt chr=from_integer(str_true[i], char_type);
250+
implies_exprt a2(eq, equal_exprt(res[i], chr));
251+
axioms.push_back(a2);
252+
}
253+
254+
std::string str_false="false";
255+
implies_exprt a3(not_exprt(eq), res.axiom_for_has_length(str_false.length()));
258256
axioms.push_back(a3);
259257

260-
symbol_exprt qvar1=fresh_univ_index("QA_equal_false", index_type);
261-
string_constraintt a4(
262-
qvar,
263-
false_string.length(),
264-
not_exprt(eq),
265-
equal_exprt(res[qvar1], false_string[qvar1]));
266-
axioms.push_back(a4);
258+
for(std::size_t i=0; i<str_false.length(); i++)
259+
{
260+
exprt chr=from_integer(str_false[i], char_type);
261+
implies_exprt a4(not_exprt(eq), equal_exprt(res[i], chr));
262+
axioms.push_back(a4);
263+
}
267264

268265
return res;
269266
}

0 commit comments

Comments
 (0)