Skip to content

Commit c6c1b3f

Browse files
Add an optional guard to add_axioms_for_constant
This allows to add a condition under which we want the result to be equal to the given constant. By default this is true, meaning that the result should always equal the constant.
1 parent 933d635 commit c6c1b3f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/solvers/refinement/string_constraint_generator.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ class string_constraint_generatort final
164164
const exprt &end_index);
165165
exprt add_axioms_for_concat(const function_application_exprt &f);
166166
exprt add_axioms_for_concat_code_point(const function_application_exprt &f);
167-
exprt add_axioms_for_constant(const array_string_exprt &res, irep_idt sval);
167+
exprt add_axioms_for_constant(
168+
const array_string_exprt &res,
169+
irep_idt sval,
170+
const exprt &guard = true_exprt());
171+
168172
exprt add_axioms_for_delete(
169173
const array_string_exprt &res,
170174
const array_string_exprt &str,

src/solvers/refinement/string_constraint_generator_constants.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ Author: Romain Brenguier, [email protected]
1919
/// equal.
2020
/// \param res: array of characters for the result
2121
/// \param sval: a string constant
22+
/// \param guard: condition under which the axiom should apply, true by default
2223
/// \return integer expression equal to zero
2324
exprt string_constraint_generatort::add_axioms_for_constant(
2425
const array_string_exprt &res,
25-
irep_idt sval)
26+
irep_idt sval,
27+
const exprt &guard)
2628
{
2729
const typet &index_type = res.length().type();
2830
const typet &char_type = res.content().type().subtype();
@@ -43,12 +45,12 @@ exprt string_constraint_generatort::add_axioms_for_constant(
4345
const exprt idx = from_integer(i, index_type);
4446
const exprt c = from_integer(str[i], char_type);
4547
const equal_exprt lemma(res[idx], c);
46-
axioms.push_back(lemma);
48+
axioms.push_back(implies_exprt(guard, lemma));
4749
}
4850

4951
const exprt s_length = from_integer(str.size(), index_type);
5052

51-
axioms.push_back(res.axiom_for_has_length(s_length));
53+
axioms.push_back(implies_exprt(guard, equal_exprt(res.length(), s_length)));
5254
return from_integer(0, get_return_code_type());
5355
}
5456

0 commit comments

Comments
 (0)