@@ -380,19 +380,10 @@ exprt string_constraint_generatort::add_axioms_for_to_upper_case(
380
380
}
381
381
382
382
// / Set a character to a specific value at an index of the string
383
- // /
384
- // / Add axioms ensuring that the result `res` is similar to input string `str`
385
- // / where the character at index `pos` is set to `char`.
386
- // / These axioms are:
387
- // / 1. \f$ |{\tt res}| = |{\tt str}|\f$
388
- // / 2. \f$ {\tt res}[{\tt pos}]={\tt char}\f$
389
- // / 3. \f$ \forall i < min(|{\tt res}|, pos). {\tt res}[i] = {\tt str}[i]\f$
390
- // / 4. \f$ \forall pos+1 <= i < |{\tt res}|.\ {\tt res}[i] = {\tt str}[i]\f$
383
+ // / \copydoc string_constraint_generatort::add_axioms_for_set_char
391
384
// / \param f: function application with arguments integer `|res|`, character
392
385
// / pointer `&res[0]`, refined_string `str`, integer `pos`,
393
386
// / and character `char`
394
- // / \return an integer expression which is `1` when `pos` is out of bounds and
395
- // / `0` otherwise
396
387
exprt string_constraint_generatort::add_axioms_for_char_set (
397
388
const function_application_exprt &f)
398
389
{
@@ -402,28 +393,45 @@ exprt string_constraint_generatort::add_axioms_for_char_set(
402
393
char_array_of_pointer (f.arguments ()[1 ], f.arguments ()[0 ]);
403
394
const exprt &position = f.arguments ()[3 ];
404
395
const exprt &character = f.arguments ()[4 ];
396
+ return add_axioms_for_set_char (res, str, position, character);
397
+ }
405
398
399
+ // / Add axioms ensuring that the result `res` is similar to input string `str`
400
+ // / where the character at index `pos` is set to `char`.
401
+ // /
402
+ // / These axioms are:
403
+ // / 1. \f$ |{\tt res}| = |{\tt str}|\f$
404
+ // / 2. \f$ {\tt res}[{\tt pos}]={\tt char}\f$
405
+ // / 3. \f$ \forall i < min(|{\tt res}|, pos). {\tt res}[i] = {\tt str}[i]\f$
406
+ // / 4. \f$ \forall pos+1 <= i < |{\tt res}|.\ {\tt res}[i] = {\tt str}[i]\f$
407
+ // / \return an integer expression which is `1` when `pos` is out of bounds and
408
+ // / `0` otherwise
409
+ exprt string_constraint_generatort::add_axioms_for_set_char (
410
+ const array_string_exprt &res,
411
+ const array_string_exprt &str,
412
+ const exprt &position,
413
+ const exprt &character)
414
+ {
406
415
const binary_relation_exprt out_of_bounds (position, ID_ge, str.length ());
407
- const equal_exprt a1 (res.length (), str.length ());
408
- lemmas.push_back (a1);
409
- const equal_exprt a2 (res[position], character);
410
- lemmas.push_back (a2);
411
-
412
- const symbol_exprt q = fresh_univ_index (" QA_char_set" , position.type ());
413
- const equal_exprt a3_body (res[q], str[q]);
414
- const string_constraintt a3 (
415
- q, minimum (zero_if_negative (res.length ()), position), a3_body);
416
- constraints.push_back (a3);
417
-
418
- const symbol_exprt q2 = fresh_univ_index (" QA_char_set2" , position.type ());
419
- const plus_exprt lower_bound (position, from_integer (1 , position.type ()));
420
- const equal_exprt a4_body (res[q2], str[q2]);
421
- const string_constraintt a4 (
422
- q2, lower_bound, zero_if_negative (res.length ()), a4_body);
423
- constraints.push_back (a4);
424
-
416
+ lemmas.push_back (equal_exprt (res.length (), str.length ()));
417
+ lemmas.push_back (equal_exprt (res[position], character));
418
+ constraints.push_back ([&] {
419
+ const symbol_exprt q = fresh_univ_index (" QA_char_set" , position.type ());
420
+ const equal_exprt a3_body (res[q], str[q]);
421
+ return string_constraintt (
422
+ q, minimum (zero_if_negative (res.length ()), position), a3_body);
423
+ }());
424
+ constraints.push_back ([&] {
425
+ const symbol_exprt q2 = fresh_univ_index (" QA_char_set2" , position.type ());
426
+ const plus_exprt lower_bound (position, from_integer (1 , position.type ()));
427
+ const equal_exprt a4_body (res[q2], str[q2]);
428
+ return string_constraintt (
429
+ q2, lower_bound, zero_if_negative (res.length ()), a4_body);
430
+ }());
425
431
return if_exprt (
426
- out_of_bounds, from_integer (1 , f.type ()), from_integer (0 , f.type ()));
432
+ out_of_bounds,
433
+ from_integer (1 , get_return_code_type ()),
434
+ from_integer (0 , get_return_code_type ()));
427
435
}
428
436
429
437
// / Convert two expressions to pair of chars
0 commit comments