Skip to content

Commit 448abb6

Browse files
author
Owen Jones
committed
Refactor helper functions
1 parent 527c282 commit 448abb6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/solvers/refinement/string_constraint_generator_valueof.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ string_exprt string_constraint_generatort::add_axioms_for_value_of(
365365
/// \param radix: the radix
366366
/// \param max_size: maximum number of characters
367367
void string_constraint_generatort::add_axioms_for_correct_number_format(
368-
const string_exprt &str, const exprt &radix, std::size_t max_size)
368+
const string_exprt &str, const exprt &radix_char_type, std::size_t max_size)
369369
{
370370
const refined_string_typet &ref_type=to_refined_string_type(str.type());
371371
const typet &char_type=ref_type.get_char_type();
@@ -378,7 +378,7 @@ void string_constraint_generatort::add_axioms_for_correct_number_format(
378378
exprt chr=str[0];
379379
equal_exprt starts_with_minus(chr, minus_char);
380380
equal_exprt starts_with_plus(chr, plus_char);
381-
exprt starts_with_digit=is_digit_with_radix(chr, radix);
381+
exprt starts_with_digit=is_digit_with_radix(chr, radix_char_type);
382382

383383
// TODO: we should have implications in the other direction for correct
384384
// correct => |str| > 0
@@ -408,7 +408,7 @@ void string_constraint_generatort::add_axioms_for_correct_number_format(
408408
/// index < length && correct => is_digit(str[index])
409409
implies_exprt character_at_index_is_digit(
410410
binary_relation_exprt(index_expr, ID_lt, str.length()),
411-
is_digit_with_radix(str[index], radix));
411+
is_digit_with_radix(str[index], radix_char_type));
412412
axioms.push_back(character_at_index_is_digit);
413413
}
414414
}
@@ -443,7 +443,8 @@ exprt string_constraint_generatort::add_axioms_for_parse_int(
443443
/// TODO: we should throw an exception when this does not hold:
444444
/// Note that the only thing stopping us from taking longer strings with many
445445
/// leading zeros is the axioms for correct number format
446-
add_axioms_for_correct_number_format(str, radix, max_string_length);
446+
add_axioms_for_correct_number_format(
447+
str, typecast_exprt(radix, char_type), max_string_length);
447448

448449
/// TODO(OJones): Fix the below algorithm to make it work for min_int. There
449450
/// are two problems. (1) Because we build i as positive and then negate it if
@@ -513,21 +514,21 @@ exprt string_constraint_generatort::add_axioms_for_parse_int(
513514
/// \param chr: the character
514515
/// \param radix: the radix
515516
/// \return an expression for the condition
516-
exprt is_digit_with_radix(exprt chr, exprt radix)
517+
exprt is_digit_with_radix(exprt chr, exprt radix_char_type)
517518
{
518519
const typet &char_type=chr.type();
519520
exprt zero_char=from_integer('0', char_type);
520521
exprt nine_char=from_integer('9', char_type);
521522
exprt a_char=from_integer('a', char_type);
522523
exprt A_char=from_integer('A', char_type);
524+
constant_exprt ten_char_type=from_integer(10, char_type);
523525

524526
and_exprt is_digit_when_radix_le_10(
525527
binary_relation_exprt(chr, ID_ge, zero_char),
526528
binary_relation_exprt(
527-
chr, ID_lt, plus_exprt(zero_char, typecast_exprt(radix, char_type))));
529+
chr, ID_lt, plus_exprt(zero_char, radix_char_type)));
528530

529-
minus_exprt radix_minus_ten(
530-
typecast_exprt(radix, char_type), from_integer(10, char_type));
531+
minus_exprt radix_minus_ten(radix_char_type, ten_char_type);
531532

532533
or_exprt is_digit_when_radix_gt_10(
533534
and_exprt(
@@ -541,7 +542,7 @@ exprt is_digit_with_radix(exprt chr, exprt radix)
541542
binary_relation_exprt(chr, ID_lt, plus_exprt(A_char, radix_minus_ten))));
542543

543544
return if_exprt(
544-
binary_relation_exprt(radix, ID_le, from_integer(10, radix.type())),
545+
binary_relation_exprt(radix_char_type, ID_le, ten_char_type),
545546
is_digit_when_radix_le_10,
546547
is_digit_when_radix_gt_10);
547548
}

0 commit comments

Comments
 (0)