Skip to content

Commit a44b369

Browse files
authored
Merge pull request #1258 from romainbrenguier/cleaning/string-expr-function-renaming
Rename string expr functions having misleading names
2 parents 960d2c3 + a86ed4a commit a44b369

13 files changed

+75
-96
lines changed

src/solvers/refinement/string_constraint_generator_comparison.cpp

+6-10
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_concat.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ string_exprt string_constraint_generatort::add_axioms_for_concat_double(
171171
const function_application_exprt &f)
172172
{
173173
string_exprt s1=get_string_expr(args(f, 2)[0]);
174-
PRECONDITION(refined_string_typet::is_refined_string_type(f.type()));
174+
PRECONDITION(is_refined_string_type(f.type()));
175175
refined_string_typet ref_type=to_refined_string_type(f.type());
176176
string_exprt s2=add_axioms_for_string_of_float(args(f, 2)[1], ref_type);
177177
return add_axioms_for_concat(s1, s2);
@@ -184,7 +184,7 @@ string_exprt string_constraint_generatort::add_axioms_for_concat_float(
184184
const function_application_exprt &f)
185185
{
186186
string_exprt s1=get_string_expr(args(f, 2)[0]);
187-
PRECONDITION(refined_string_typet::is_refined_string_type(f.type()));
187+
PRECONDITION(is_refined_string_type(f.type()));
188188
refined_string_typet ref_type=to_refined_string_type(f.type());
189189
string_exprt s2=add_axioms_for_string_of_float(args(f, 2)[1], ref_type);
190190
return add_axioms_for_concat(s1, s2);

src/solvers/refinement/string_constraint_generator_constants.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ string_exprt string_constraint_generatort::add_axioms_for_empty_string(
5656
const function_application_exprt &f)
5757
{
5858
PRECONDITION(f.arguments().empty());
59-
PRECONDITION(refined_string_typet::is_refined_string_type(f.type()));
59+
PRECONDITION(is_refined_string_type(f.type()));
6060
const refined_string_typet &ref_type=to_refined_string_type(f.type());
6161
return empty_string(ref_type);
6262
}

src/solvers/refinement/string_constraint_generator_float.cpp

+2-2
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_indexof.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ exprt string_constraint_generatort::add_axioms_for_index_of(
252252
else
253253
{
254254
INVARIANT(
255-
refined_string_typet::is_refined_string_type(c.type()),
255+
is_refined_string_type(c.type()),
256256
string_refinement_invariantt("c can only be a (un)signedbv or a refined "
257257
"string and the (un)signedbv case is already handled"));
258258
string_exprt sub=get_string_expr(c);

src/solvers/refinement/string_constraint_generator_main.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ string_exprt string_constraint_generatort::fresh_string(
131131
/// \return a string expression
132132
string_exprt string_constraint_generatort::get_string_expr(const exprt &expr)
133133
{
134-
PRECONDITION(refined_string_typet::is_refined_string_type(expr.type()));
134+
PRECONDITION(is_refined_string_type(expr.type()));
135135

136136
if(expr.id()==ID_symbol)
137137
{
@@ -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
{
@@ -180,7 +180,7 @@ void string_constraint_generatort::add_default_axioms(
180180
string_exprt string_constraint_generatort::add_axioms_for_refined_string(
181181
const exprt &string)
182182
{
183-
PRECONDITION(refined_string_typet::is_refined_string_type(string.type()));
183+
PRECONDITION(is_refined_string_type(string.type()));
184184
refined_string_typet type=to_refined_string_type(string.type());
185185

186186
// Function applications should have been removed before
@@ -246,11 +246,9 @@ string_exprt string_constraint_generatort::add_axioms_for_refined_string(
246246
string_exprt string_constraint_generatort::add_axioms_for_if(
247247
const if_exprt &expr)
248248
{
249-
PRECONDITION(
250-
refined_string_typet::is_refined_string_type(expr.true_case().type()));
249+
PRECONDITION(is_refined_string_type(expr.true_case().type()));
251250
string_exprt t=get_string_expr(expr.true_case());
252-
PRECONDITION(
253-
refined_string_typet::is_refined_string_type(expr.false_case().type()));
251+
PRECONDITION(is_refined_string_type(expr.false_case().type()));
254252
string_exprt f=get_string_expr(expr.false_case());
255253
const refined_string_typet &ref_type=to_refined_string_type(t.type());
256254
const typet &index_type=ref_type.get_index_type();

src/solvers/refinement/string_constraint_generator_testing.cpp

+8-8
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

+7-7
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

+6-7
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/solvers/refinement/string_refinement.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void string_refinementt::add_symbol_to_symbol_map(
162162
rhs.id()==ID_array_of ||
163163
rhs.id()==ID_if ||
164164
(rhs.id()==ID_struct &&
165-
refined_string_typet::is_refined_string_type(rhs.type())));
165+
is_refined_string_type(rhs.type())));
166166

167167
// We insert the mapped value of the rhs, if it exists.
168168
auto it=symbol_resolve.find(rhs);
@@ -279,7 +279,7 @@ bool string_refinementt::add_axioms_for_string_assigns(
279279
return true;
280280
}
281281
}
282-
if(refined_string_typet::is_refined_string_type(rhs.type()))
282+
if(is_refined_string_type(rhs.type()))
283283
{
284284
exprt refined_rhs=generator.add_axioms_for_refined_string(rhs);
285285
add_symbol_to_symbol_map(lhs, refined_rhs);
@@ -302,7 +302,7 @@ bool string_refinementt::add_axioms_for_string_assigns(
302302
/// last value that has been initialized.
303303
void string_refinementt::concretize_string(const exprt &expr)
304304
{
305-
if(refined_string_typet::is_refined_string_type(expr.type()))
305+
if(is_refined_string_type(expr.type()))
306306
{
307307
string_exprt str=to_string_expr(expr);
308308
exprt length=get(str.length());
@@ -392,7 +392,7 @@ void string_refinementt::concretize_lengths()
392392
{
393393
for(const auto &it : symbol_resolve)
394394
{
395-
if(refined_string_typet::is_refined_string_type(it.second.type()))
395+
if(is_refined_string_type(it.second.type()))
396396
{
397397
string_exprt str=to_string_expr(it.second);
398398
exprt length=get(str.length());
@@ -403,7 +403,7 @@ void string_refinementt::concretize_lengths()
403403
}
404404
for(const auto &it : generator.created_strings)
405405
{
406-
if(refined_string_typet::is_refined_string_type(it.type()))
406+
if(is_refined_string_type(it.type()))
407407
{
408408
string_exprt str=to_string_expr(it);
409409
exprt length=get(str.length());
@@ -429,12 +429,10 @@ void string_refinementt::set_to(const exprt &expr, bool value)
429429

430430
// The assignment of a string equality to false is not supported.
431431
PRECONDITION(value || !is_char_array(rhs.type()));
432-
PRECONDITION(value ||
433-
!refined_string_typet::is_refined_string_type(rhs.type()));
432+
PRECONDITION(value || !is_refined_string_type(rhs.type()));
434433

435434
PRECONDITION(lhs.id()==ID_symbol || !is_char_array(rhs.type()));
436-
PRECONDITION(lhs.id()==ID_symbol ||
437-
!refined_string_typet::is_refined_string_type(rhs.type()));
435+
PRECONDITION(lhs.id()==ID_symbol || !is_refined_string_type(rhs.type()));
438436

439437
// If lhs is not a symbol, let supert::set_to() handle it.
440438
if(lhs.id()!=ID_symbol)
@@ -811,7 +809,7 @@ void string_refinementt::debug_model()
811809
const std::string indent(" ");
812810
for(auto it : symbol_resolve)
813811
{
814-
if(refined_string_typet::is_refined_string_type(it.second.type()))
812+
if(is_refined_string_type(it.second.type()))
815813
{
816814
debug() << "- " << from_expr(ns, "", to_symbol_expr(it.first)) << ":\n";
817815
string_exprt refined=to_string_expr(it.second);
@@ -1684,8 +1682,7 @@ exprt string_refinementt::get(const exprt &expr) const
16841682
if(it!=found_length.end())
16851683
return get_array(ecopy, it->second);
16861684
}
1687-
else if(refined_string_typet::is_refined_string_type(ecopy.type()) &&
1688-
ecopy.id()==ID_struct)
1685+
else if(is_refined_string_type(ecopy.type()) && ecopy.id()==ID_struct)
16891686
{
16901687
const string_exprt &string=to_string_expr(ecopy);
16911688
const exprt &content=string.content();

src/util/refined_string_type.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Author: Romain Brenguier, [email protected]
1616
/// `content` of type `content_type`. This module also defines functions to
1717
/// recognise the C and java string types.
1818

19-
#include <util/cprover_prefix.h>
20-
2119
#include "refined_string_type.h"
2220

2321
refined_string_typet::refined_string_typet(
@@ -29,13 +27,3 @@ refined_string_typet::refined_string_typet(
2927
components().emplace_back("content", char_array);
3028
set_tag(CPROVER_PREFIX"refined_string_type");
3129
}
32-
33-
/// \par parameters: a type
34-
/// \return Boolean telling whether the input is a refined string type
35-
bool refined_string_typet::is_refined_string_type(const typet &type)
36-
{
37-
return
38-
type.id()==ID_struct &&
39-
to_struct_type(type).get_tag()==CPROVER_PREFIX"refined_string_type";
40-
}
41-

0 commit comments

Comments
 (0)