Skip to content

Commit 369dd62

Browse files
Unit test: adapte instantiate_nc for new signature
Also remove useless include and debug output.
1 parent dcae158 commit 369dd62

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

unit/solvers/refinement/string_constraint_instantiation/instantiate_not_contains.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,28 @@ constant_exprt from_integer(const mp_integer &i)
5656
array_string_exprt make_string_exprt(const std::string &str)
5757
{
5858
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));
6060

6161
for(const char c : str)
6262
content.copy_to_operands(from_integer(c, t.char_type()));
6363

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));
6581
}
6682

6783
/// 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)
97113
{
98114
// Conjunction of new lemmas
99115
exprt conj=conjunction(lemmas);
100-
101116
// Simplify
102117
simplify(conj, ns);
103118

@@ -146,12 +161,20 @@ SCENARIO("instantiate_not_contains",
146161
symbol_tablet symtbl;
147162
const namespacet ns(symtbl);
148163

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+
149176
GIVEN("The not_contains axioms of String.lastIndexOf(String, Int)")
150177
{
151-
// Creating strings
152-
const string_exprt ab=make_string_exprt("ab");
153-
const string_exprt b=make_string_exprt("b");
154-
155178
// Creating "ab".lastIndexOf("b", 0)
156179
function_application_exprt func(
157180
symbol_exprt(ID_cprover_string_last_index_of_func), t.length_type());
@@ -194,8 +217,8 @@ SCENARIO("instantiate_not_contains",
194217
WHEN("we instantiate and simplify")
195218
{
196219
// 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);
199222

200223
// List of new lemmas to be returned
201224
std::vector<exprt> lemmas;
@@ -228,9 +251,6 @@ SCENARIO("instantiate_not_contains",
228251

229252
GIVEN("A vacuously true not_contains axioms")
230253
{
231-
// Creating strings
232-
const string_exprt a=make_string_exprt("a");
233-
234254
// Make
235255
// forall x in [0, 0). true => (exists y in [0, 1).
236256
// { .=1, .={ (char)'a' } }[x+y] != { .=1, .={ (char)'b' } }[y]
@@ -242,8 +262,8 @@ SCENARIO("instantiate_not_contains",
242262
true_exprt(),
243263
from_integer(0),
244264
from_integer(1),
245-
a,
246-
a);
265+
a_array,
266+
a_array);
247267

248268
// Create witness for axiom
249269
symbol_tablet symtab;
@@ -259,7 +279,7 @@ SCENARIO("instantiate_not_contains",
259279
WHEN("we instantiate and simplify")
260280
{
261281
// 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);
263283

264284
// Instantiate the lemmas
265285
std::vector<exprt> lemmas=instantiate_not_contains(
@@ -285,10 +305,6 @@ SCENARIO("instantiate_not_contains",
285305

286306
GIVEN("A trivially false (via empty existential) not_contains axioms")
287307
{
288-
// Creating strings
289-
const string_exprt a=make_string_exprt("a");
290-
const string_exprt b=make_string_exprt("b");
291-
292308
// Make
293309
// forall x in [0, 1). true => (exists y in [0, 0).
294310
// { .=1, .={ (char)'a' } }[x+y] != { .=1, .={ (char)'b' } }[y]
@@ -300,8 +316,8 @@ SCENARIO("instantiate_not_contains",
300316
true_exprt(),
301317
from_integer(0),
302318
from_integer(0),
303-
a,
304-
b);
319+
a_array,
320+
b_array);
305321

306322
// Create witness for axiom
307323
symbol_tablet symtab;
@@ -317,8 +333,8 @@ SCENARIO("instantiate_not_contains",
317333
WHEN("we instantiate and simplify")
318334
{
319335
// 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);
322338

323339
// Instantiate the lemmas
324340
std::vector<exprt> lemmas=instantiate_not_contains(
@@ -344,10 +360,6 @@ SCENARIO("instantiate_not_contains",
344360

345361
GIVEN("A not_contains axioms with an non-empty and empty string")
346362
{
347-
// Creating strings
348-
const string_exprt a=make_string_exprt("a");
349-
const string_exprt empty=make_string_exprt("");
350-
351363
// Make
352364
// forall x in [0, 1). true => (exists y in [0, 0).
353365
// { .=1, .={ (char)'a' } }[x+y] != { .=0, .={ } }[y]
@@ -359,8 +371,8 @@ SCENARIO("instantiate_not_contains",
359371
true_exprt(),
360372
from_integer(0),
361373
from_integer(0),
362-
a,
363-
empty);
374+
a_array,
375+
empty_array);
364376

365377
// Create witness for axiom
366378
symbol_tablet symtab;
@@ -376,7 +388,7 @@ SCENARIO("instantiate_not_contains",
376388
WHEN("we instantiate and simplify")
377389
{
378390
// 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);
380392
const std::set<exprt> index_set_empty=
381393
{generator.fresh_exist_index("z", t.length_type())};
382394

@@ -404,9 +416,6 @@ SCENARIO("instantiate_not_contains",
404416

405417
GIVEN("A not_contains on the same string twice (hence is false)")
406418
{
407-
// Creating strings
408-
const string_exprt ab=make_string_exprt("ab");
409-
410419
// Make
411420
// forall x in [0, 2). true => (exists y in [0, 2).
412421
// { .=2, .={ (char)'a', (char)'b'} }[x+y] !=
@@ -419,8 +428,8 @@ SCENARIO("instantiate_not_contains",
419428
true_exprt(),
420429
from_integer(0),
421430
from_integer(2),
422-
ab,
423-
ab);
431+
ab_array,
432+
ab_array);
424433

425434
// Create witness for axiom
426435
symbol_tablet symtab;
@@ -437,7 +446,7 @@ SCENARIO("instantiate_not_contains",
437446
WHEN("we instantiate and simplify")
438447
{
439448
// 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);
441450

442451
// Instantiate the lemmas
443452
std::vector<exprt> lemmas=instantiate_not_contains(
@@ -463,10 +472,6 @@ SCENARIO("instantiate_not_contains",
463472

464473
GIVEN("A not_contains on two string with no chars in common (hence is true)")
465474
{
466-
// Creating strings
467-
const string_exprt ab=make_string_exprt("ab");
468-
const string_exprt cd=make_string_exprt("cd");
469-
470475
// Make
471476
// forall x in [0, 2). true => (exists y in [0, 2).
472477
// { .=2, .={ (char)'a', (char)'b'} }[x+y] !=
@@ -479,8 +484,8 @@ SCENARIO("instantiate_not_contains",
479484
true_exprt(),
480485
from_integer(0),
481486
from_integer(2),
482-
ab,
483-
cd);
487+
ab_array,
488+
cd_array);
484489

485490
// Create witness for axiom
486491
symbol_tablet symtab;
@@ -496,8 +501,8 @@ SCENARIO("instantiate_not_contains",
496501
WHEN("we instantiate and simplify")
497502
{
498503
// 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);
501506

502507
// Instantiate the lemmas
503508
std::vector<exprt> lemmas=instantiate_not_contains(

unit/solvers/refinement/string_refinement/concretize_array.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <util/arith_tools.h>
1313
#include <util/std_types.h>
1414
#include <util/std_expr.h>
15+
#include <util/symbol_table.h>
1516
#include <solvers/refinement/string_refinement.h>
1617

1718
SCENARIO("concretize_array_expression",
@@ -46,7 +47,9 @@ SCENARIO("concretize_array_expression",
4647
index2));
4748

4849
// String max length is 50, so index 100 should get ignored.
49-
const exprt concrete=concretize_arrays_in_expression(input_expr, 50);
50+
symbol_tablet symbol_table;
51+
namespacet ns(symbol_table);
52+
const exprt concrete = concretize_arrays_in_expression(input_expr, 50, ns);
5053

5154
// The expected result is `'0' + { 'x', 'x', 'y', 'y', 'y' }`
5255
array_exprt array(array_type);

0 commit comments

Comments
 (0)