Skip to content

Commit 09fa70f

Browse files
author
Joel Allred
authored
Merge pull request #4609 from allredj/array_string_exprt-length_type
Refactor: Introduce array_string_exprt.length_type() [TG-7439]
2 parents 3e8b9d9 + d80890f commit 09fa70f

14 files changed

+73
-70
lines changed

src/solvers/strings/string_builtin_function.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ optionalt<exprt> string_concat_char_builtin_functiont::eval(
182182
}();
183183
input_opt.value().push_back(char_val);
184184
const auto length =
185-
from_integer(input_opt.value().size(), result.length().type());
185+
from_integer(input_opt.value().size(), result.length_type());
186186
const array_typet type(result.type().subtype(), length);
187187
return make_string(input_opt.value(), type);
188188
}
@@ -200,7 +200,7 @@ string_constraintst string_concat_char_builtin_functiont::constraints(
200200
constraints.existential.push_back(length_constraint());
201201
constraints.universal.push_back([&] {
202202
const symbol_exprt idx =
203-
generator.fresh_symbol("QA_index_concat_char", result.length().type());
203+
generator.fresh_symbol("QA_index_concat_char", result.length_type());
204204
const exprt upper_bound = zero_if_negative(input.length());
205205
return string_constraintt(
206206
idx, upper_bound, equal_exprt(input[idx], result[idx]));
@@ -228,7 +228,7 @@ optionalt<exprt> string_set_char_builtin_functiont::eval(
228228
if(0 <= *position_opt && *position_opt < input_opt.value().size())
229229
input_opt.value()[numeric_cast_v<std::size_t>(*position_opt)] = *char_opt;
230230
const auto length =
231-
from_integer(input_opt.value().size(), result.length().type());
231+
from_integer(input_opt.value().size(), result.length_type());
232232
const array_typet type(result.type().subtype(), length);
233233
return make_string(input_opt.value(), type);
234234
}
@@ -275,7 +275,7 @@ exprt string_set_char_builtin_functiont::length_constraint() const
275275
const exprt out_of_bounds = or_exprt(
276276
binary_relation_exprt(position, ID_ge, input.length()),
277277
binary_relation_exprt(
278-
position, ID_lt, from_integer(0, input.length().type())));
278+
position, ID_lt, from_integer(0, input.length_type())));
279279
const exprt return_value = if_exprt(
280280
out_of_bounds,
281281
from_integer(1, return_code.type()),
@@ -308,7 +308,7 @@ optionalt<exprt> string_to_lower_case_builtin_functiont::eval(
308308
c += 0x20;
309309
}
310310
const auto length =
311-
from_integer(input_opt.value().size(), result.length().type());
311+
from_integer(input_opt.value().size(), result.length_type());
312312
const array_typet type(result.type().subtype(), length);
313313
return make_string(input_opt.value(), type);
314314
}
@@ -371,7 +371,7 @@ string_constraintst string_to_lower_case_builtin_functiont::constraints(
371371
constraints.existential.push_back(length_constraint());
372372
constraints.universal.push_back([&] {
373373
const symbol_exprt idx =
374-
generator.fresh_symbol("QA_lower_case", result.length().type());
374+
generator.fresh_symbol("QA_lower_case", result.length_type());
375375
const exprt conditional_convert = [&] {
376376
// The difference between upper-case and lower-case for the basic
377377
// latin and latin-1 supplement is 0x20.
@@ -400,7 +400,7 @@ optionalt<exprt> string_to_upper_case_builtin_functiont::eval(
400400
c -= 0x20;
401401
}
402402
const auto length =
403-
from_integer(input_opt.value().size(), result.length().type());
403+
from_integer(input_opt.value().size(), result.length_type());
404404
const array_typet type(result.type().subtype(), length);
405405
return make_string(input_opt.value(), type);
406406
}
@@ -421,7 +421,7 @@ string_constraintst string_to_upper_case_builtin_functiont::constraints(
421421
constraints.existential.push_back(length_constraint());
422422
constraints.universal.push_back([&] {
423423
const symbol_exprt idx =
424-
fresh_symbol("QA_upper_case", result.length().type());
424+
fresh_symbol("QA_upper_case", result.length_type());
425425
const typet &char_type = input.content().type().subtype();
426426
const exprt converted =
427427
minus_exprt(input[idx], from_integer(0x20, char_type));
@@ -480,7 +480,7 @@ optionalt<exprt> string_insertion_builtin_functiont::eval(
480480
});
481481

482482
const auto result_value = eval(*input1_value, *input2_value, arg_values);
483-
const auto length = from_integer(result_value.size(), result.length().type());
483+
const auto length = from_integer(result_value.size(), result.length_type());
484484
const array_typet type(result.type().subtype(), length);
485485
return make_string(result_value, type);
486486
}
@@ -552,7 +552,7 @@ optionalt<exprt> string_of_int_builtin_functiont::eval(
552552
right_to_left_characters.emplace_back('-');
553553

554554
const auto length = right_to_left_characters.size();
555-
const auto length_expr = from_integer(length, result.length().type());
555+
const auto length_expr = from_integer(length, result.length_type());
556556
const array_typet type(result.type().subtype(), length_expr);
557557
return make_string(
558558
right_to_left_characters.rbegin(), right_to_left_characters.rend(), type);
@@ -569,7 +569,7 @@ string_constraintst string_of_int_builtin_functiont::constraints(
569569

570570
exprt string_of_int_builtin_functiont::length_constraint() const
571571
{
572-
const typet &type = result.length().type();
572+
const typet &type = result.length_type();
573573
const auto radix_opt = numeric_cast<std::size_t>(radix);
574574
const auto radix_value = radix_opt.has_value() ? radix_opt.value() : 2;
575575
const std::size_t upper_bound =

src/solvers/strings/string_constraint_generator_code_points.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_code_point_at(
131131
const exprt &pos = f.arguments()[1];
132132

133133
const symbol_exprt result = fresh_symbol("char", return_type);
134-
const exprt index1 = from_integer(1, str.length().type());
134+
const exprt index1 = from_integer(1, str.length_type());
135135
const exprt &char1 = str[pos];
136136
const exprt &char2 = str[plus_exprt(pos, index1)];
137137
const typecast_exprt char1_as_int(char1, return_type);

src/solvers/strings/string_constraint_generator_comparison.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_equals(
4343
symbol_exprt eq = fresh_symbol("equal");
4444
typecast_exprt tc_eq(eq, f.type());
4545

46-
typet index_type = s1.length().type();
46+
typet index_type = s1.length_type();
4747

4848
// Axiom 1.
4949
constraints.existential.push_back(
@@ -145,7 +145,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_equals_ignore_case(
145145
const exprt char_a = from_integer('a', char_type);
146146
const exprt char_A = from_integer('A', char_type);
147147
const exprt char_Z = from_integer('Z', char_type);
148-
const typet index_type = s1.length().type();
148+
const typet index_type = s1.length_type();
149149

150150
const implies_exprt a1(eq, equal_exprt(s1.length(), s2.length()));
151151
constraints.existential.push_back(a1);
@@ -193,7 +193,7 @@ string_constraint_generatort::add_axioms_for_hash_code(
193193
string_constraintst hash_constraints;
194194
const array_string_exprt str = get_string_expr(array_pool, f.arguments()[0]);
195195
const typet &return_type = f.type();
196-
const typet &index_type = str.length().type();
196+
const typet &index_type = str.length_type();
197197

198198
auto pair = hash_code_of_string.insert(
199199
std::make_pair(str, fresh_symbol("hash", return_type)));
@@ -247,7 +247,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_compare_to(
247247
const array_string_exprt &s1 = get_string_expr(array_pool, f.arguments()[0]);
248248
const array_string_exprt &s2 = get_string_expr(array_pool, f.arguments()[1]);
249249
const symbol_exprt res = fresh_symbol("compare_to", return_type);
250-
const typet &index_type = s1.length().type();
250+
const typet &index_type = s1.length_type();
251251

252252
const equal_exprt res_null(res, from_integer(0, return_type));
253253
const implies_exprt a1(res_null, equal_exprt(s1.length(), s2.length()));

src/solvers/strings/string_constraint_generator_concat.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,15 @@ std::pair<exprt, string_constraintst> add_axioms_for_concat_substr(
5454

5555
// Axiom 2.
5656
constraints.universal.push_back([&] {
57-
const symbol_exprt idx =
58-
fresh_symbol("QA_index_concat", res.length().type());
57+
const symbol_exprt idx = fresh_symbol("QA_index_concat", res.length_type());
5958
return string_constraintt(
6059
idx, zero_if_negative(s1.length()), equal_exprt(s1[idx], res[idx]));
6160
}());
6261

6362
// Axiom 3.
6463
constraints.universal.push_back([&] {
6564
const symbol_exprt idx2 =
66-
fresh_symbol("QA_index_concat2", res.length().type());
65+
fresh_symbol("QA_index_concat2", res.length_type());
6766
const equal_exprt res_eq(
6867
res[plus_exprt(idx2, s1.length())], s2[plus_exprt(start1, idx2)]);
6968
const minus_exprt upper_bound(res.length(), s1.length());
@@ -85,12 +84,12 @@ exprt length_constraint_for_concat_substr(
8584
const exprt &start,
8685
const exprt &end)
8786
{
88-
PRECONDITION(res.length().type().id() == ID_signedbv);
87+
PRECONDITION(res.length_type().id() == ID_signedbv);
8988
const exprt start1 = maximum(start, from_integer(0, start.type()));
9089
const exprt end1 = maximum(minimum(end, s2.length()), start1);
9190
const plus_exprt res_length(s1.length(), minus_exprt(end1, start1));
9291
const exprt overflow = sum_overflows(res_length);
93-
const exprt max_int = to_signedbv_type(res.length().type()).largest_expr();
92+
const exprt max_int = to_signedbv_type(res.length_type()).largest_expr();
9493
return equal_exprt(res.length(), if_exprt(overflow, max_int, res_length));
9594
}
9695

@@ -111,7 +110,7 @@ exprt length_constraint_for_concat_char(
111110
const array_string_exprt &s1)
112111
{
113112
return equal_exprt(
114-
res.length(), plus_exprt(s1.length(), from_integer(1, s1.length().type())));
113+
res.length(), plus_exprt(s1.length(), from_integer(1, s1.length_type())));
115114
}
116115

117116
/// Add axioms enforcing that `res` is equal to the concatenation of `s1` and
@@ -129,7 +128,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_concat(
129128
const array_string_exprt &s1,
130129
const array_string_exprt &s2)
131130
{
132-
exprt index_zero = from_integer(0, s2.length().type());
131+
exprt index_zero = from_integer(0, s2.length_type());
133132
return add_axioms_for_concat_substr(
134133
fresh_symbol, res, s1, s2, index_zero, s2.length());
135134
}
@@ -150,7 +149,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_concat_code_point(
150149
array_pool.find(f.arguments()[1], f.arguments()[0]);
151150
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
152151
const typet &char_type = s1.content().type().subtype();
153-
const typet &index_type = s1.length().type();
152+
const typet &index_type = s1.length_type();
154153
const array_string_exprt code_point =
155154
array_pool.fresh_string(index_type, char_type);
156155
return combine_results(

src/solvers/strings/string_constraint_generator_float.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_string_of_float(
210210
const floatbv_typet &type = to_floatbv_type(f.type());
211211
const ieee_float_spect float_spec(type);
212212
const typet &char_type = res.content().type().subtype();
213-
const typet &index_type = res.length().type();
213+
const typet &index_type = res.length_type();
214214

215215
// We will look at the first 5 digits of the fractional part.
216216
// shifted is floor(f * 1e5)
@@ -264,7 +264,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_fractional_part(
264264
string_constraintst constraints;
265265
const typet &type = int_expr.type();
266266
const typet &char_type = res.content().type().subtype();
267-
const typet &index_type = res.length().type();
267+
const typet &index_type = res.length_type();
268268
const exprt ten = from_integer(10, type);
269269
const exprt zero_char = from_integer('0', char_type);
270270
const exprt nine_char = from_integer('9', char_type);
@@ -292,7 +292,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_fractional_part(
292292
{
293293
// after_end is |res| <= j
294294
binary_relation_exprt after_end(
295-
res.length(), ID_le, from_integer(j, res.length().type()));
295+
res.length(), ID_le, from_integer(j, res.length_type()));
296296
mult_exprt ten_sum(sum, ten);
297297

298298
// sum = 10 * sum + after_end ? 0 : (res[j]-'0')
@@ -311,7 +311,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_fractional_part(
311311
if(j > 1)
312312
{
313313
not_exprt no_trailing_zero(and_exprt(
314-
equal_exprt(res.length(), from_integer(j + 1, res.length().type())),
314+
equal_exprt(res.length(), from_integer(j + 1, res.length_type())),
315315
equal_exprt(res[j], zero_char)));
316316
digit_constraints.push_back(no_trailing_zero);
317317
}
@@ -355,7 +355,7 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
355355
const ieee_float_spect float_spec = ieee_float_spect::single_precision();
356356
const typet float_type = float_spec.to_type();
357357
const signedbv_typet int_type(32);
358-
const typet &index_type = res.length().type();
358+
const typet &index_type = res.length_type();
359359
const typet &char_type = res.content().type().subtype();
360360

361361
// This is used for rounding float to integers.

src/solvers/strings/string_constraint_generator_format.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ static std::vector<format_elementt> parse_format_string(std::string s)
245245
static exprt is_null(const array_string_exprt &string)
246246
{
247247
return and_exprt{
248-
equal_exprt{string.length(), from_integer(4, string.length().type())},
249-
and_exprt{
250-
equal_exprt{string[0], from_integer('n', string[0].type())},
251-
equal_exprt{string[1], from_integer('u', string[0].type())},
252-
equal_exprt{string[2], from_integer('l', string[0].type())},
253-
equal_exprt{string[3], from_integer('l', string[0].type())}}};
248+
equal_exprt{string.length(), from_integer(4, string.length_type())},
249+
and_exprt{equal_exprt{string[0], from_integer('n', string[0].type())},
250+
equal_exprt{string[1], from_integer('u', string[0].type())},
251+
equal_exprt{string[2], from_integer('l', string[0].type())},
252+
equal_exprt{string[3], from_integer('l', string[0].type())}}};
254253
}
255254

256255
/// Parse `s` and add axioms ensuring the output corresponds to the output of
@@ -457,7 +456,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
457456
std::vector<array_string_exprt> intermediary_strings;
458457
std::size_t arg_count = 0;
459458
const typet &char_type = res.content().type().subtype();
460-
const typet &index_type = res.length().type();
459+
const typet &index_type = res.length_type();
461460

462461
for(const format_elementt &fe : format_strings)
463462
{

src/solvers/strings/string_constraint_generator_indexof.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_index_of(
4242
const exprt &from_index)
4343
{
4444
string_constraintst constraints;
45-
const typet &index_type = str.length().type();
45+
const typet &index_type = str.length_type();
4646
symbol_exprt index = fresh_symbol("index_of", index_type);
4747
symbol_exprt contains = fresh_symbol("contains_in_index_of");
4848

@@ -115,7 +115,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_index_of_string(
115115
const exprt &from_index)
116116
{
117117
string_constraintst constraints;
118-
const typet &index_type = haystack.length().type();
118+
const typet &index_type = haystack.length_type();
119119
symbol_exprt offset = fresh_symbol("index_of", index_type);
120120
symbol_exprt contains = fresh_symbol("contains_substring");
121121

@@ -208,7 +208,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_last_index_of_string(
208208
const exprt &from_index)
209209
{
210210
string_constraintst constraints;
211-
const typet &index_type = haystack.length().type();
211+
const typet &index_type = haystack.length_type();
212212
symbol_exprt offset = fresh_symbol("index_of", index_type);
213213
symbol_exprt contains = fresh_symbol("contains_substring");
214214

@@ -295,7 +295,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_index_of(
295295
PRECONDITION(args.size() == 2 || args.size() == 3);
296296
const array_string_exprt str = get_string_expr(array_pool, args[0]);
297297
const exprt &c = args[1];
298-
const typet &index_type = str.length().type();
298+
const typet &index_type = str.length_type();
299299
const typet &char_type = str.content().type().subtype();
300300
PRECONDITION(f.type() == index_type);
301301
const exprt from_index =
@@ -349,7 +349,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_last_index_of(
349349
const exprt &from_index)
350350
{
351351
string_constraintst constraints;
352-
const typet &index_type = str.length().type();
352+
const typet &index_type = str.length_type();
353353
const symbol_exprt index = fresh_symbol("last_index_of", index_type);
354354
const symbol_exprt contains = fresh_symbol("contains_in_last_index_of");
355355

@@ -420,7 +420,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_last_index_of(
420420
PRECONDITION(args.size() == 2 || args.size() == 3);
421421
const array_string_exprt str = get_string_expr(array_pool, args[0]);
422422
const exprt c = args[1];
423-
const typet &index_type = str.length().type();
423+
const typet &index_type = str.length_type();
424424
const typet &char_type = str.content().type().subtype();
425425
PRECONDITION(f.type() == index_type);
426426

src/solvers/strings/string_constraint_generator_insert.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert(
3838
const array_string_exprt &s2,
3939
const exprt &offset)
4040
{
41-
PRECONDITION(offset.type() == s1.length().type());
41+
PRECONDITION(offset.type() == s1.length_type());
4242

4343
string_constraintst constraints;
44-
const typet &index_type = s1.length().type();
44+
const typet &index_type = s1.length_type();
4545
const exprt offset1 =
4646
maximum(from_integer(0, index_type), minimum(s1.length(), offset));
4747

@@ -118,7 +118,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert(
118118
const exprt &start = f.arguments()[5];
119119
const exprt &end = f.arguments()[6];
120120
const typet &char_type = s1.content().type().subtype();
121-
const typet &index_type = s1.length().type();
121+
const typet &index_type = s1.length_type();
122122
const array_string_exprt substring =
123123
array_pool.fresh_string(index_type, char_type);
124124
return combine_results(
@@ -151,7 +151,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert_int(
151151
const array_string_exprt res =
152152
array_pool.find(f.arguments()[1], f.arguments()[0]);
153153
const exprt &offset = f.arguments()[3];
154-
const typet &index_type = s1.length().type();
154+
const typet &index_type = s1.length_type();
155155
const typet &char_type = s1.content().type().subtype();
156156
const array_string_exprt s2 = array_pool.fresh_string(index_type, char_type);
157157
return combine_results(
@@ -177,7 +177,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert_bool(
177177
const array_string_exprt res =
178178
array_pool.find(f.arguments()[1], f.arguments()[0]);
179179
const exprt &offset = f.arguments()[3];
180-
const typet &index_type = s1.length().type();
180+
const typet &index_type = s1.length_type();
181181
const typet &char_type = s1.content().type().subtype();
182182
const array_string_exprt s2 = array_pool.fresh_string(index_type, char_type);
183183
return combine_results(
@@ -202,7 +202,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert_char(
202202
array_pool.find(f.arguments()[1], f.arguments()[0]);
203203
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
204204
const exprt &offset = f.arguments()[3];
205-
const typet &index_type = s1.length().type();
205+
const typet &index_type = s1.length_type();
206206
const typet &char_type = s1.content().type().subtype();
207207
const array_string_exprt s2 = array_pool.fresh_string(index_type, char_type);
208208
return combine_results(
@@ -230,7 +230,7 @@ std::pair<exprt, string_constraintst> add_axioms_for_insert_double(
230230
array_pool.find(f.arguments()[1], f.arguments()[0]);
231231
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
232232
const exprt &offset = f.arguments()[3];
233-
const typet &index_type = s1.length().type();
233+
const typet &index_type = s1.length_type();
234234
const typet &char_type = s1.content().type().subtype();
235235
const array_string_exprt s2 = array_pool.fresh_string(index_type, char_type);
236236
return combine_results(

0 commit comments

Comments
 (0)