Skip to content

Commit 9c80352

Browse files
author
Joel Allred
committed
Refactor length_le to less_than_or_equal_to
Binary relations on string lengths do not need the string itself. Refactor to delegate dereferencing the length to the caller. This is necessary for upcoming changes in which accessing the length always involves accessing the array_pool.
1 parent 8ec1e42 commit 9c80352

5 files changed

+18
-13
lines changed

src/solvers/strings/string_constraint_generator_comparison.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ std::pair<exprt, string_constraintst> add_axioms_for_compare_to(
271271
typecast_exprt(s1.length(), return_type),
272272
typecast_exprt(s2.length(), return_type)));
273273
const or_exprt guard1(
274-
and_exprt(length_le(s1, s2.length()), greater_than(s1.length(), x)),
274+
and_exprt(
275+
less_than_or_equal_to(s1.length(), s2.length()),
276+
greater_than(s1.length(), x)),
275277
and_exprt(
276278
greater_or_equal_to(s1.length(), s2.length()),
277279
greater_than(s2.length(), x)));

src/solvers/strings/string_constraint_generator_float.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ std::pair<exprt, string_constraintst> add_axioms_for_fractional_part(
278278
// no_trailing_zero: forall j:[2, max_size[. !(|res| = j+1 && res[j] = '0')
279279
// a3 : int_expr = sum_j 10^j (j < |res| ? res[j] - '0' : 0)
280280

281-
const and_exprt a1(greater_than(res.length(), 1), length_le(res, max));
281+
const and_exprt a1(
282+
greater_than(res.length(), 1), less_than_or_equal_to(res.length(), max));
282283
constraints.existential.push_back(a1);
283284

284285
equal_exprt starts_with_dot(res[0], from_integer('.', char_type));

src/solvers/strings/string_constraint_generator_transformation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_trim(
209209
greater_or_equal_to(res.length(), from_integer(0, index_type));
210210
constraints.existential.push_back(a4);
211211

212-
const exprt a5 = length_le(res, str.length());
212+
const exprt a5 = less_than_or_equal_to(res.length(), str.length());
213213
constraints.existential.push_back(a5);
214214

215215
symbol_exprt n = fresh_symbol("QA_index_trim", index_type);

src/solvers/strings/string_constraint_generator_valueof.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ add_axioms_from_int_hex(const array_string_exprt &res, const exprt &i)
230230
exprt f_char = from_integer('f', char_type);
231231

232232
size_t max_size = 8;
233-
constraints.existential.push_back(
234-
and_exprt(greater_than(res.length(), 0), length_le(res, max_size)));
233+
constraints.existential.push_back(and_exprt(
234+
greater_than(res.length(), 0),
235+
less_than_or_equal_to(res.length(), max_size)));
235236

236237
for(size_t size = 1; size <= max_size; size++)
237238
{
@@ -370,7 +371,8 @@ string_constraintst add_axioms_for_correct_number_format(
370371
constraints.existential.push_back(contains_digit);
371372

372373
// |str| <= max_size
373-
constraints.existential.push_back(length_le(str, max_size));
374+
constraints.existential.push_back(
375+
less_than_or_equal_to(str.length(), max_size));
374376

375377
// forall 1 <= i < |str| . is_digit_with_radix(str[i], radix)
376378
// We unfold the above because we know that it will be used for all i up to

src/util/string_expr.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ inline binary_relation_exprt greater_than(const exprt &lhs, mp_integer i)
3434
return greater_than(lhs, from_integer(i, lhs.type()));
3535
}
3636

37-
template <typename T>
38-
binary_relation_exprt length_le(const T &lhs, const exprt &rhs)
37+
inline binary_relation_exprt
38+
less_than_or_equal_to(const exprt &lhs, const exprt &rhs)
3939
{
40-
PRECONDITION(rhs.type() == lhs.length().type());
41-
return binary_relation_exprt(lhs.length(), ID_le, rhs);
40+
PRECONDITION(rhs.type() == lhs.type());
41+
return binary_relation_exprt(lhs, ID_le, rhs);
4242
}
4343

44-
template <typename T>
45-
binary_relation_exprt length_le(const T &lhs, mp_integer i)
44+
inline binary_relation_exprt
45+
less_than_or_equal_to(const exprt &lhs, mp_integer i)
4646
{
47-
return length_le(lhs, from_integer(i, lhs.length().type()));
47+
return less_than_or_equal_to(lhs, from_integer(i, lhs.type()));
4848
}
4949

5050
inline equal_exprt equal_to(const exprt &lhs, const exprt &rhs)

0 commit comments

Comments
 (0)