Skip to content

Commit a86ed4a

Browse files
Renaming string length comparing functions
The previous name used (like `axioms_for_is_longer_than`) could be ambiguous and sometimes misleading.
1 parent e047556 commit a86ed4a

7 files changed

+47
-52
lines changed

src/solvers/refinement/string_constraint_generator_comparison.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ exprt string_constraint_generatort::add_axioms_for_hash_code(
175175
and_exprt(
176176
not_exprt(equal_exprt(str[i], it.first[i])),
177177
and_exprt(
178-
str.axiom_for_is_strictly_longer_than(i),
178+
str.axiom_for_length_gt(i),
179179
axiom_for_is_positive_index(i))));
180180
axioms.push_back(or_exprt(c1, or_exprt(c2, c3)));
181181
}
@@ -229,16 +229,12 @@ exprt string_constraint_generatort::add_axioms_for_compare_to(
229229
typecast_exprt(s1.length(), return_type),
230230
typecast_exprt(s2.length(), return_type)));
231231
or_exprt guard1(
232-
and_exprt(s1.axiom_for_is_shorter_than(s2),
233-
s1.axiom_for_is_strictly_longer_than(x)),
234-
and_exprt(s1.axiom_for_is_longer_than(s2),
235-
s2.axiom_for_is_strictly_longer_than(x)));
232+
and_exprt(s1.axiom_for_length_le(s2), s1.axiom_for_length_gt(x)),
233+
and_exprt(s1.axiom_for_length_ge(s2), s2.axiom_for_length_gt(x)));
236234
and_exprt cond1(ret_char_diff, guard1);
237235
or_exprt guard2(
238-
and_exprt(s2.axiom_for_is_strictly_longer_than(s1),
239-
s1.axiom_for_has_length(x)),
240-
and_exprt(s1.axiom_for_is_strictly_longer_than(s2),
241-
s2.axiom_for_has_length(x)));
236+
and_exprt(s2.axiom_for_length_gt(s1), s1.axiom_for_has_length(x)),
237+
and_exprt(s1.axiom_for_length_gt(s2), s2.axiom_for_has_length(x)));
242238
and_exprt cond2(ret_length_diff, guard2);
243239

244240
implies_exprt a3(
@@ -300,7 +296,7 @@ symbol_exprt string_constraint_generatort::add_axioms_for_intern(
300296
str.axiom_for_has_same_length_as(it.first),
301297
and_exprt(
302298
not_exprt(equal_exprt(str[i], it.first[i])),
303-
and_exprt(str.axiom_for_is_strictly_longer_than(i),
299+
and_exprt(str.axiom_for_length_gt(i),
304300
axiom_for_is_positive_index(i)))))));
305301
}
306302

src/solvers/refinement/string_constraint_generator_float.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ string_exprt string_constraint_generatort::add_axioms_for_fractional_part(
235235
// no_trailing_zero: forall j:[2, max_size[. !(|res| = j+1 && res[j] = '0')
236236
// a3 : int_expr = sum_j 10^j (j < |res| ? res[j] - '0' : 0)
237237

238-
and_exprt a1(res.axiom_for_is_strictly_longer_than(1),
239-
res.axiom_for_is_shorter_than(max));
238+
and_exprt a1(res.axiom_for_length_gt(1),
239+
res.axiom_for_length_le(max));
240240
axioms.push_back(a1);
241241

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

src/solvers/refinement/string_constraint_generator_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void string_constraint_generatort::add_default_axioms(
156156
const string_exprt &s)
157157
{
158158
axioms.push_back(
159-
s.axiom_for_is_longer_than(from_integer(0, s.length().type())));
159+
s.axiom_for_length_ge(from_integer(0, s.length().type())));
160160
if(max_string_length!=std::numeric_limits<size_t>::max())
161-
axioms.push_back(s.axiom_for_is_shorter_than(max_string_length));
161+
axioms.push_back(s.axiom_for_length_le(max_string_length));
162162

163163
if(force_printable_characters)
164164
{

src/solvers/refinement/string_constraint_generator_testing.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exprt string_constraint_generatort::add_axioms_for_is_prefix(
3232

3333
implies_exprt a1(
3434
isprefix,
35-
str.axiom_for_is_longer_than(plus_exprt_with_overflow_check(
35+
str.axiom_for_length_ge(plus_exprt_with_overflow_check(
3636
prefix.length(), offset)));
3737
axioms.push_back(a1);
3838

@@ -49,12 +49,12 @@ exprt string_constraint_generatort::add_axioms_for_is_prefix(
4949
and_exprt witness_diff(
5050
axiom_for_is_positive_index(witness),
5151
and_exprt(
52-
prefix.axiom_for_is_strictly_longer_than(witness),
52+
prefix.axiom_for_length_gt(witness),
5353
notequal_exprt(str[plus_exprt_with_overflow_check(witness, offset)],
5454
prefix[witness])));
5555
or_exprt s0_notpref_s1(
5656
not_exprt(
57-
str.axiom_for_is_longer_than(
57+
str.axiom_for_length_ge(
5858
plus_exprt_with_overflow_check(prefix.length(), offset))),
5959
witness_diff);
6060

@@ -132,7 +132,7 @@ exprt string_constraint_generatort::add_axioms_for_is_suffix(
132132
// || (s1.length > witness>=0
133133
// &&s1[witness]!=s0[witness + s0.length-s1.length]
134134

135-
implies_exprt a1(issuffix, s1.axiom_for_is_longer_than(s0));
135+
implies_exprt a1(issuffix, s1.axiom_for_length_ge(s0));
136136
axioms.push_back(a1);
137137

138138
symbol_exprt qvar=fresh_univ_index("QA_suffix", index_type);
@@ -146,12 +146,12 @@ exprt string_constraint_generatort::add_axioms_for_is_suffix(
146146
exprt shifted=plus_exprt(
147147
witness, minus_exprt(s1.length(), s0.length()));
148148
or_exprt constr3(
149-
and_exprt(s0.axiom_for_is_strictly_longer_than(s1),
149+
and_exprt(s0.axiom_for_length_gt(s1),
150150
equal_exprt(witness, from_integer(-1, index_type))),
151151
and_exprt(
152152
notequal_exprt(s0[witness], s1[shifted]),
153153
and_exprt(
154-
s0.axiom_for_is_strictly_longer_than(witness),
154+
s0.axiom_for_length_gt(witness),
155155
axiom_for_is_positive_index(witness))));
156156
implies_exprt a3(not_exprt(issuffix), constr3);
157157

@@ -201,7 +201,7 @@ exprt string_constraint_generatort::add_axioms_for_contains(
201201
// (forall startpos <= |s0| - |s1|.
202202
// exists witness < |s1|. s1[witness] != s0[witness + startpos])
203203

204-
implies_exprt a1(contains, s0.axiom_for_is_longer_than(s1));
204+
implies_exprt a1(contains, s0.axiom_for_length_ge(s1));
205205
axioms.push_back(a1);
206206

207207
symbol_exprt startpos=fresh_exist_index("startpos_contains", index_type);
@@ -229,7 +229,7 @@ exprt string_constraint_generatort::add_axioms_for_contains(
229229
string_not_contains_constraintt a5(
230230
from_integer(0, index_type),
231231
plus_exprt(from_integer(1, index_type), length_diff),
232-
and_exprt(not_exprt(contains), s0.axiom_for_is_longer_than(s1)),
232+
and_exprt(not_exprt(contains), s0.axiom_for_length_ge(s1)),
233233
from_integer(0, index_type),
234234
s1.length(),
235235
s0,

src/solvers/refinement/string_constraint_generator_transformation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ string_exprt string_constraint_generatort::add_axioms_for_set_length(
4242
string_constraintt a2(
4343
idx,
4444
res.length(),
45-
s1.axiom_for_is_strictly_longer_than(idx),
45+
s1.axiom_for_length_gt(idx),
4646
equal_exprt(s1[idx], res[idx]));
4747
axioms.push_back(a2);
4848

@@ -51,7 +51,7 @@ string_exprt string_constraint_generatort::add_axioms_for_set_length(
5151
string_constraintt a3(
5252
idx2,
5353
res.length(),
54-
s1.axiom_for_is_shorter_than(idx2),
54+
s1.axiom_for_length_le(idx2),
5555
equal_exprt(res[idx2], constant_char(0, ref_type.get_char_type())));
5656
axioms.push_back(a3);
5757

@@ -120,7 +120,7 @@ string_exprt string_constraint_generatort::add_axioms_for_substring(
120120
axioms.push_back(a2);
121121

122122
// Warning: check what to do if the string is not long enough
123-
axioms.push_back(str.axiom_for_is_longer_than(end));
123+
axioms.push_back(str.axiom_for_length_ge(end));
124124

125125
symbol_exprt idx=fresh_univ_index("QA_index_substring", index_type);
126126
string_constraintt a4(idx,
@@ -156,21 +156,21 @@ string_exprt string_constraint_generatort::add_axioms_for_trim(
156156
// a8 : forall n<|s1|, s[idx+n]=s1[n]
157157
// a9 : (s[m]>' ' &&s[m+|s1|-1]>' ') || m=|s|
158158

159-
exprt a1=str.axiom_for_is_longer_than(
159+
exprt a1=str.axiom_for_length_ge(
160160
plus_exprt_with_overflow_check(idx, res.length()));
161161
axioms.push_back(a1);
162162

163163
binary_relation_exprt a2(idx, ID_ge, from_integer(0, index_type));
164164
axioms.push_back(a2);
165165

166-
exprt a3=str.axiom_for_is_longer_than(idx);
166+
exprt a3=str.axiom_for_length_ge(idx);
167167
axioms.push_back(a3);
168168

169-
exprt a4=res.axiom_for_is_longer_than(
169+
exprt a4=res.axiom_for_length_ge(
170170
from_integer(0, index_type));
171171
axioms.push_back(a4);
172172

173-
exprt a5=res.axiom_for_is_shorter_than(str);
173+
exprt a5=res.axiom_for_length_le(str);
174174
axioms.push_back(a5);
175175

176176
symbol_exprt n=fresh_univ_index("QA_index_trim", index_type);

src/solvers/refinement/string_constraint_generator_valueof.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ string_exprt string_constraint_generatort::add_axioms_from_int_hex(
222222

223223
size_t max_size=8;
224224
axioms.push_back(
225-
and_exprt(res.axiom_for_is_strictly_longer_than(0),
226-
res.axiom_for_is_shorter_than(max_size)));
225+
and_exprt(res.axiom_for_length_gt(0),
226+
res.axiom_for_length_le(max_size)));
227227

228228
for(size_t size=1; size<=max_size; size++)
229229
{
@@ -322,8 +322,7 @@ void string_constraint_generatort::add_axioms_for_correct_number_format(
322322
is_digit_with_radix(chr, strict_formatting, radix_as_char, radix_ul);
323323

324324
// |str| > 0
325-
const exprt non_empty=
326-
str.axiom_for_is_longer_than(from_integer(1, index_type));
325+
const exprt non_empty=str.axiom_for_length_ge(from_integer(1, index_type));
327326
axioms.push_back(non_empty);
328327

329328
if(strict_formatting)
@@ -343,11 +342,11 @@ void string_constraint_generatort::add_axioms_for_correct_number_format(
343342
// str[0]='+' or '-' ==> |str| > 1
344343
const implies_exprt contains_digit(
345344
or_exprt(starts_with_minus, starts_with_plus),
346-
str.axiom_for_is_longer_than(from_integer(2, index_type)));
345+
str.axiom_for_length_ge(from_integer(2, index_type)));
347346
axioms.push_back(contains_digit);
348347

349348
// |str| <= max_size
350-
axioms.push_back(str.axiom_for_is_shorter_than(max_size));
349+
axioms.push_back(str.axiom_for_length_le(max_size));
351350

352351
// forall 1 <= i < |str| . is_digit_with_radix(str[i], radix)
353352
// We unfold the above because we know that it will be used for all i up to
@@ -356,7 +355,7 @@ void string_constraint_generatort::add_axioms_for_correct_number_format(
356355
{
357356
/// index < length => is_digit_with_radix(str[index], radix)
358357
const implies_exprt character_at_index_is_digit(
359-
str.axiom_for_is_longer_than(from_integer(index+1, index_type)),
358+
str.axiom_for_length_ge(from_integer(index+1, index_type)),
360359
is_digit_with_radix(
361360
str[index], strict_formatting, radix_as_char, radix_ul));
362361
axioms.push_back(character_at_index_is_digit);

src/util/string_expr.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,59 +53,59 @@ class string_exprt: public struct_exprt
5353
}
5454

5555
// Comparison on the length of the strings
56-
binary_relation_exprt axiom_for_is_longer_than(
56+
binary_relation_exprt axiom_for_length_ge(
5757
const string_exprt &rhs) const
5858
{
5959
return binary_relation_exprt(length(), ID_ge, rhs.length());
6060
}
6161

62-
binary_relation_exprt axiom_for_is_longer_than(
62+
binary_relation_exprt axiom_for_length_ge(
6363
const exprt &rhs) const
6464
{
6565
return binary_relation_exprt(length(), ID_ge, rhs);
6666
}
6767

68-
binary_relation_exprt axiom_for_is_strictly_longer_than(
68+
binary_relation_exprt axiom_for_length_gt(
6969
const exprt &rhs) const
7070
{
7171
return binary_relation_exprt(rhs, ID_lt, length());
7272
}
7373

74-
binary_relation_exprt axiom_for_is_strictly_longer_than(
74+
binary_relation_exprt axiom_for_length_gt(
7575
const string_exprt &rhs) const
7676
{
7777
return binary_relation_exprt(rhs.length(), ID_lt, length());
7878
}
7979

80-
binary_relation_exprt axiom_for_is_strictly_longer_than(mp_integer i) const
80+
binary_relation_exprt axiom_for_length_gt(mp_integer i) const
8181
{
82-
return axiom_for_is_strictly_longer_than(from_integer(i, length().type()));
82+
return axiom_for_length_gt(from_integer(i, length().type()));
8383
}
8484

85-
binary_relation_exprt axiom_for_is_shorter_than(
85+
binary_relation_exprt axiom_for_length_le(
8686
const string_exprt &rhs) const
8787
{
8888
return binary_relation_exprt(length(), ID_le, rhs.length());
8989
}
9090

91-
binary_relation_exprt axiom_for_is_shorter_than(
91+
binary_relation_exprt axiom_for_length_le(
9292
const exprt &rhs) const
9393
{
9494
return binary_relation_exprt(length(), ID_le, rhs);
9595
}
9696

97-
binary_relation_exprt axiom_for_is_shorter_than(mp_integer i) const
97+
binary_relation_exprt axiom_for_length_le(mp_integer i) const
9898
{
99-
return axiom_for_is_shorter_than(from_integer(i, length().type()));
99+
return axiom_for_length_le(from_integer(i, length().type()));
100100
}
101101

102-
binary_relation_exprt axiom_for_is_strictly_shorter_than(
102+
binary_relation_exprt axiom_for_length_lt(
103103
const string_exprt &rhs) const
104104
{
105105
return binary_relation_exprt(length(), ID_lt, rhs.length());
106106
}
107107

108-
binary_relation_exprt axiom_for_is_strictly_shorter_than(
108+
binary_relation_exprt axiom_for_length_lt(
109109
const exprt &rhs) const
110110
{
111111
return binary_relation_exprt(length(), ID_lt, rhs);
@@ -132,15 +132,15 @@ class string_exprt: public struct_exprt
132132

133133
inline string_exprt &to_string_expr(exprt &expr)
134134
{
135-
assert(expr.id()==ID_struct);
136-
assert(expr.operands().size()==2);
135+
PRECONDITION(expr.id()==ID_struct);
136+
PRECONDITION(expr.operands().size()==2);
137137
return static_cast<string_exprt &>(expr);
138138
}
139139

140140
inline const string_exprt &to_string_expr(const exprt &expr)
141141
{
142-
assert(expr.id()==ID_struct);
143-
assert(expr.operands().size()==2);
142+
PRECONDITION(expr.id()==ID_struct);
143+
PRECONDITION(expr.operands().size()==2);
144144
return static_cast<const string_exprt &>(expr);
145145
}
146146

0 commit comments

Comments
 (0)