@@ -364,12 +364,9 @@ string_exprt string_constraint_generatort::add_axioms_for_value_of(
364
364
// / \param str: string expression
365
365
// / \param radix: the radix
366
366
// / \param max_size: maximum number of characters
367
- // / \return a boolean expression saying whether the string does represent a
368
- // / number with the given radix
369
- exprt string_constraint_generatort::add_axioms_for_correct_number_format (
367
+ void string_constraint_generatort::add_axioms_for_correct_number_format (
370
368
const string_exprt &str, const exprt &radix, std::size_t max_size)
371
369
{
372
- symbol_exprt correct=fresh_boolean (" correct_number_format" );
373
370
const refined_string_typet &ref_type=to_refined_string_type (str.type ());
374
371
const typet &char_type=ref_type.get_char_type ();
375
372
const typet &index_type=ref_type.get_index_type ();
@@ -386,31 +383,34 @@ exprt string_constraint_generatort::add_axioms_for_correct_number_format(
386
383
// TODO: we should have implications in the other direction for correct
387
384
// correct => |str| > 0
388
385
exprt non_empty=str.axiom_for_is_longer_than (from_integer (1 , index_type));
389
- axioms.push_back (implies_exprt (correct, non_empty) );
386
+ axioms.push_back (non_empty);
390
387
391
388
// correct => (str[0] = '+' or '-' || is_digit_with_radix(str[0], radix))
392
389
or_exprt correct_first (
393
390
or_exprt (starts_with_minus, starts_with_plus), starts_with_digit);
394
- axioms.push_back (implies_exprt (correct, correct_first) );
391
+ axioms.push_back (correct_first);
395
392
396
393
// correct => str[0]='+' or '-' ==> |str| > 1
397
394
implies_exprt contains_digit (
398
395
or_exprt (starts_with_minus, starts_with_plus),
399
396
str.axiom_for_is_longer_than (from_integer (2 , index_type)));
400
- axioms.push_back (implies_exprt (correct, contains_digit) );
397
+ axioms.push_back (contains_digit);
401
398
402
399
// correct => |str| < max_size
403
- axioms.push_back (
404
- implies_exprt (correct, str.axiom_for_is_shorter_than (max_size)));
405
-
406
- // forall 1 <= qvar < |str| . correct => is_digit_with_radix(str[qvar], radix)
407
- symbol_exprt qvar=fresh_univ_index (" number_format" , index_type);
408
- exprt is_digit=is_digit_with_radix (str[qvar], radix);
409
- string_constraintt all_digits (
410
- qvar, from_integer (1 , index_type), str.length (), correct, is_digit);
411
- axioms.push_back (all_digits);
400
+ axioms.push_back (str.axiom_for_is_shorter_than (max_size));
412
401
413
- return correct;
402
+ // forall 1 <= i < |str| . correct => is_digit_with_radix(str[i], radix)
403
+ // We unfold the above because we know that it will be used for all i up to
404
+ // str.length()
405
+ for (std::size_t index=1 ; index<max_size; ++index)
406
+ {
407
+ const exprt index_expr=from_integer (index, index_type);
408
+ // / index < length && correct => is_digit(str[index])
409
+ implies_exprt character_at_index_is_digit (
410
+ binary_relation_exprt (index_expr, ID_lt, str.length ()),
411
+ is_digit_with_radix (str[index], radix));
412
+ axioms.push_back (character_at_index_is_digit);
413
+ }
414
414
}
415
415
416
416
// / add axioms corresponding to the Integer.parseInt java function
@@ -443,9 +443,7 @@ exprt string_constraint_generatort::add_axioms_for_parse_int(
443
443
444
444
// / TODO: we should throw an exception when this does not hold:
445
445
const std::size_t max_string_length=40 ;
446
- const exprt &correct=add_axioms_for_correct_number_format (
447
- str, radix, max_string_length);
448
- axioms.push_back (correct);
446
+ add_axioms_for_correct_number_format (str, radix, max_string_length);
449
447
450
448
// / TODO(OJones): size should depend on the radix
451
449
// / TODO(OJones): we should deal with overflow properly
0 commit comments