@@ -56,12 +56,28 @@ constant_exprt from_integer(const mp_integer &i)
56
56
array_string_exprt make_string_exprt (const std::string &str)
57
57
{
58
58
const constant_exprt length=from_integer (str.length (), t.length_type ());
59
- array_exprt content (t. array_type ( ));
59
+ array_exprt content (array_typet (t. char_type (), length ));
60
60
61
61
for (const char c : str)
62
62
content.copy_to_operands (from_integer (c, t.char_type ()));
63
63
64
- return array_string_exprt (length, content, t.string_type ());
64
+ return to_array_string_expr (content);
65
+ }
66
+
67
+ // / Return a pointer to the data array of an array_string_exprt
68
+ // / \param arr: char array representing a string
69
+ // / \return pointer to the first character of the array
70
+ exprt get_data_pointer (const array_string_exprt &arr)
71
+ {
72
+ return address_of_exprt (index_exprt (arr, from_integer (0 , t.length_type ())));
73
+ }
74
+
75
+ // / Creates a `string_exprt` of the proper string type.
76
+ // / \param [in] str: string to convert
77
+ // / \return corresponding `string_exprt`
78
+ refined_string_exprt make_refined_string_exprt (const array_string_exprt &arr)
79
+ {
80
+ return refined_string_exprt (arr.length (), get_data_pointer (arr));
65
81
}
66
82
67
83
// / For a constant `string_exprt`, creates a full index set.
@@ -97,7 +113,6 @@ exprt combine_lemmas(const std::vector<exprt> &lemmas, const namespacet &ns)
97
113
{
98
114
// Conjunction of new lemmas
99
115
exprt conj=conjunction (lemmas);
100
-
101
116
// Simplify
102
117
simplify (conj, ns);
103
118
@@ -146,12 +161,20 @@ SCENARIO("instantiate_not_contains",
146
161
symbol_tablet symtbl;
147
162
const namespacet ns (symtbl);
148
163
164
+ // Creating strings
165
+ const auto ab_array = make_string_exprt (" ab" );
166
+ const auto b_array = make_string_exprt (" b" );
167
+ const auto a_array = make_string_exprt (" a" );
168
+ const auto empty_array = make_string_exprt (" " );
169
+ const auto cd_array = make_string_exprt (" cd" );
170
+ const auto ab = make_refined_string_exprt (ab_array);
171
+ const auto b = make_refined_string_exprt (b_array);
172
+ const auto a = make_refined_string_exprt (a_array);
173
+ const auto empty = make_refined_string_exprt (empty_array);
174
+ const auto cd = make_refined_string_exprt (cd_array);
175
+
149
176
GIVEN (" The not_contains axioms of String.lastIndexOf(String, Int)" )
150
177
{
151
- // Creating strings
152
- const string_exprt ab=make_string_exprt (" ab" );
153
- const string_exprt b=make_string_exprt (" b" );
154
-
155
178
// Creating "ab".lastIndexOf("b", 0)
156
179
function_application_exprt func (
157
180
symbol_exprt (ID_cprover_string_last_index_of_func), t.length_type ());
@@ -194,8 +217,8 @@ SCENARIO("instantiate_not_contains",
194
217
WHEN (" we instantiate and simplify" )
195
218
{
196
219
// Making index sets
197
- const std::set<exprt> index_set_ab= full_index_set (ab );
198
- const std::set<exprt> index_set_b= full_index_set (b );
220
+ const std::set<exprt> index_set_ab = full_index_set (ab_array );
221
+ const std::set<exprt> index_set_b = full_index_set (b_array );
199
222
200
223
// List of new lemmas to be returned
201
224
std::vector<exprt> lemmas;
@@ -228,9 +251,6 @@ SCENARIO("instantiate_not_contains",
228
251
229
252
GIVEN (" A vacuously true not_contains axioms" )
230
253
{
231
- // Creating strings
232
- const string_exprt a=make_string_exprt (" a" );
233
-
234
254
// Make
235
255
// forall x in [0, 0). true => (exists y in [0, 1).
236
256
// { .=1, .={ (char)'a' } }[x+y] != { .=1, .={ (char)'b' } }[y]
@@ -242,8 +262,8 @@ SCENARIO("instantiate_not_contains",
242
262
true_exprt (),
243
263
from_integer (0 ),
244
264
from_integer (1 ),
245
- a ,
246
- a );
265
+ a_array ,
266
+ a_array );
247
267
248
268
// Create witness for axiom
249
269
symbol_tablet symtab;
@@ -259,7 +279,7 @@ SCENARIO("instantiate_not_contains",
259
279
WHEN (" we instantiate and simplify" )
260
280
{
261
281
// Making index sets
262
- const std::set<exprt> index_set_a= full_index_set (a );
282
+ const std::set<exprt> index_set_a = full_index_set (a_array );
263
283
264
284
// Instantiate the lemmas
265
285
std::vector<exprt> lemmas=instantiate_not_contains (
@@ -285,10 +305,6 @@ SCENARIO("instantiate_not_contains",
285
305
286
306
GIVEN (" A trivially false (via empty existential) not_contains axioms" )
287
307
{
288
- // Creating strings
289
- const string_exprt a=make_string_exprt (" a" );
290
- const string_exprt b=make_string_exprt (" b" );
291
-
292
308
// Make
293
309
// forall x in [0, 1). true => (exists y in [0, 0).
294
310
// { .=1, .={ (char)'a' } }[x+y] != { .=1, .={ (char)'b' } }[y]
@@ -300,8 +316,8 @@ SCENARIO("instantiate_not_contains",
300
316
true_exprt (),
301
317
from_integer (0 ),
302
318
from_integer (0 ),
303
- a ,
304
- b );
319
+ a_array ,
320
+ b_array );
305
321
306
322
// Create witness for axiom
307
323
symbol_tablet symtab;
@@ -317,8 +333,8 @@ SCENARIO("instantiate_not_contains",
317
333
WHEN (" we instantiate and simplify" )
318
334
{
319
335
// Making index sets
320
- const std::set<exprt> index_set_a= full_index_set (a );
321
- const std::set<exprt> index_set_b= full_index_set (b );
336
+ const std::set<exprt> index_set_a = full_index_set (a_array );
337
+ const std::set<exprt> index_set_b = full_index_set (b_array );
322
338
323
339
// Instantiate the lemmas
324
340
std::vector<exprt> lemmas=instantiate_not_contains (
@@ -344,10 +360,6 @@ SCENARIO("instantiate_not_contains",
344
360
345
361
GIVEN (" A not_contains axioms with an non-empty and empty string" )
346
362
{
347
- // Creating strings
348
- const string_exprt a=make_string_exprt (" a" );
349
- const string_exprt empty=make_string_exprt (" " );
350
-
351
363
// Make
352
364
// forall x in [0, 1). true => (exists y in [0, 0).
353
365
// { .=1, .={ (char)'a' } }[x+y] != { .=0, .={ } }[y]
@@ -359,8 +371,8 @@ SCENARIO("instantiate_not_contains",
359
371
true_exprt (),
360
372
from_integer (0 ),
361
373
from_integer (0 ),
362
- a ,
363
- empty );
374
+ a_array ,
375
+ empty_array );
364
376
365
377
// Create witness for axiom
366
378
symbol_tablet symtab;
@@ -376,7 +388,7 @@ SCENARIO("instantiate_not_contains",
376
388
WHEN (" we instantiate and simplify" )
377
389
{
378
390
// Making index sets
379
- const std::set<exprt> index_set_a= full_index_set (a );
391
+ const std::set<exprt> index_set_a = full_index_set (a_array );
380
392
const std::set<exprt> index_set_empty=
381
393
{generator.fresh_exist_index (" z" , t.length_type ())};
382
394
@@ -404,9 +416,6 @@ SCENARIO("instantiate_not_contains",
404
416
405
417
GIVEN (" A not_contains on the same string twice (hence is false)" )
406
418
{
407
- // Creating strings
408
- const string_exprt ab=make_string_exprt (" ab" );
409
-
410
419
// Make
411
420
// forall x in [0, 2). true => (exists y in [0, 2).
412
421
// { .=2, .={ (char)'a', (char)'b'} }[x+y] !=
@@ -419,8 +428,8 @@ SCENARIO("instantiate_not_contains",
419
428
true_exprt (),
420
429
from_integer (0 ),
421
430
from_integer (2 ),
422
- ab ,
423
- ab );
431
+ ab_array ,
432
+ ab_array );
424
433
425
434
// Create witness for axiom
426
435
symbol_tablet symtab;
@@ -437,7 +446,7 @@ SCENARIO("instantiate_not_contains",
437
446
WHEN (" we instantiate and simplify" )
438
447
{
439
448
// Making index sets
440
- const std::set<exprt> index_set_ab= full_index_set (ab );
449
+ const std::set<exprt> index_set_ab = full_index_set (ab_array );
441
450
442
451
// Instantiate the lemmas
443
452
std::vector<exprt> lemmas=instantiate_not_contains (
@@ -463,10 +472,6 @@ SCENARIO("instantiate_not_contains",
463
472
464
473
GIVEN (" A not_contains on two string with no chars in common (hence is true)" )
465
474
{
466
- // Creating strings
467
- const string_exprt ab=make_string_exprt (" ab" );
468
- const string_exprt cd=make_string_exprt (" cd" );
469
-
470
475
// Make
471
476
// forall x in [0, 2). true => (exists y in [0, 2).
472
477
// { .=2, .={ (char)'a', (char)'b'} }[x+y] !=
@@ -479,8 +484,8 @@ SCENARIO("instantiate_not_contains",
479
484
true_exprt (),
480
485
from_integer (0 ),
481
486
from_integer (2 ),
482
- ab ,
483
- cd );
487
+ ab_array ,
488
+ cd_array );
484
489
485
490
// Create witness for axiom
486
491
symbol_tablet symtab;
@@ -496,8 +501,8 @@ SCENARIO("instantiate_not_contains",
496
501
WHEN (" we instantiate and simplify" )
497
502
{
498
503
// Making index sets
499
- const std::set<exprt> index_set_ab= full_index_set (ab );
500
- const std::set<exprt> index_set_cd= full_index_set (cd );
504
+ const std::set<exprt> index_set_ab = full_index_set (ab_array );
505
+ const std::set<exprt> index_set_cd = full_index_set (cd_array );
501
506
502
507
// Instantiate the lemmas
503
508
std::vector<exprt> lemmas=instantiate_not_contains (
0 commit comments