33 if(
const auto i = numeric_cast<unsigned long>(
simplify_expr(expr, ns)))
42 DEPRECATED(
SINCE(2017, 10, 5,
"use add_axioms_for_string_of_int instead"))
47 PRECONDITION(f.arguments().size() == 3 || f.arguments().size() == 4);
49 array_pool.
find(f.arguments()[1], f.arguments()[0]);
50 if(f.arguments().size() == 4)
51 return add_axioms_for_string_of_int_with_radix(
52 res, f.arguments()[2], f.arguments()[3], 0);
54 return add_axioms_for_string_of_int(res, f.arguments()[2], 0);
63 DEPRECATED(
SINCE(2017, 10, 5,
"Java specific, should be implemented in Java"))
80 std::string str_true =
"true";
82 eq,
equal_to(array_pool.get_or_create_length(res), str_true.length()));
85 for(std::size_t i = 0; i < str_true.length(); i++)
92 std::string str_false =
"false";
95 equal_to(array_pool.get_or_create_length(res), str_false.length()));
98 for(std::size_t i = 0; i < str_false.length(); i++)
116 std::pair<exprt, string_constraintst>
119 const exprt &input_int,
124 res, input_int, radix, max_size);
136 std::pair<exprt, string_constraintst>
139 const exprt &input_int,
143 PRECONDITION(max_size < std::numeric_limits<size_t>::max());
150 CHECK_RETURN((radix_ul >= 2 && radix_ul <= 36) || radix_ul == 0);
155 CHECK_RETURN(max_size < std::numeric_limits<size_t>::max());
161 const bool strict_formatting =
true;
164 res, radix_as_char, radix_ul, max_size, strict_formatting);
173 result2.existential.push_back(
conjunction(std::move(result1)));
198 DEPRECATED(
SINCE(2017, 10, 5,
"use add_axioms_for_string_of_int_with_radix"))
204 const typet &type = i.type();
207 const typet &index_type = res.length_type();
221 for(
size_t size = 1; size <= max_size; size++)
227 for(
size_t j = 0; j < size; j++)
243 equal_to(array_pool.get_or_create_length(res), size);
258 std::pair<exprt, string_constraintst>
281 const exprt &radix_as_char,
282 const unsigned long radix_ul,
283 const std::size_t max_size,
284 const bool strict_formatting)
286 std::vector<exprt> conjuncts;
290 const exprt &chr = str[0];
293 const exprt starts_with_digit =
299 conjuncts.push_back(non_empty);
301 if(strict_formatting)
304 const or_exprt correct_first(starts_with_minus, starts_with_digit);
305 conjuncts.push_back(correct_first);
311 starts_with_minus, starts_with_digit, starts_with_plus);
312 conjuncts.push_back(correct_first);
317 or_exprt(starts_with_minus, starts_with_plus),
320 conjuncts.push_back(contains_digit);
329 for(std::size_t index = 1; index < max_size; ++index)
337 str[index], strict_formatting, radix_as_char, radix_ul));
338 conjuncts.push_back(character_at_index_is_digit);
341 if(strict_formatting)
350 conjuncts.push_back(no_leading_zero);
355 conjuncts.push_back(no_leading_zero_after_minus);
374 const exprt &input_int,
376 const bool strict_formatting,
378 const std::size_t max_string_length,
380 const unsigned long radix_ul)
389 str[0],
char_type, type, strict_formatting, radix_ul);
398 for(
size_t size = 2; size <= max_string_length; size++)
418 str[size - 1],
char_type, type, strict_formatting, radix_ul));
424 std::optional<exprt> no_overflow;
425 if(size - 1 >= max_string_length - 2 || radix_ul == 0)
434 if(no_overflow.has_value())
450 and_exprt(string_length_equals_size, starts_with_minus),
460 const typet &target_int_type)
473 PRECONDITION((radix_ul >= 2 && radix_ul <= 36) || radix_ul == 0);
475 const std::size_t max_string_length =
478 return {str, radix, radix_ul, max_string_length};
488 std::pair<exprt, string_constraintst>
494 called_function == ID_cprover_string_is_valid_int_func ||
495 called_function == ID_cprover_string_is_valid_long_func);
497 called_function == ID_cprover_string_is_valid_int_func ? 32 : 64)};
503 const bool strict_formatting =
false;
511 args.max_string_length,
524 std::pair<exprt, string_constraintst>
533 const bool strict_formatting =
false;
540 args.max_string_length,
544 return {input_int, std::move(constraints2)};
557 const bool strict_formatting,
558 const exprt &radix_as_char,
559 const unsigned long radix_ul)
561 PRECONDITION((radix_ul >= 2 && radix_ul <= 36) || radix_ul == 0);
565 const and_exprt is_digit_when_radix_le_10(
569 if(radix_ul <= 10 && radix_ul != 0)
571 return is_digit_when_radix_le_10;
579 const minus_exprt radix_minus_ten(radix_as_char, ten_char_type);
588 chr, ID_lt,
plus_exprt(a_char, radix_minus_ten))));
590 if(!strict_formatting)
596 chr, ID_lt,
plus_exprt(A_char, radix_minus_ten))));
603 is_digit_when_radix_le_10,
604 is_digit_when_radix_gt_10);
608 return std::move(is_digit_when_radix_gt_10);
627 const bool strict_formatting,
628 const unsigned long radix_ul)
635 chr, ID_ge, zero_char);
637 if(radix_ul <= 10 && radix_ul != 0)
642 upper_case_lower_case_or_digit,
655 if(strict_formatting)
664 upper_case_lower_case_or_digit,
679 upper_case_or_lower_case,
682 upper_case_lower_case_or_digit,
704 double radix =
static_cast<double>(radix_ul);
705 bool signed_type = type.
id() == ID_signedbv;
724 double max = signed_type
725 ?
floor(
static_cast<double>(n_bits - 1) /
log2(radix)) + 2.0
726 :
ceil(
static_cast<double>(n_bits) /
log2(radix));
727 return static_cast<size_t>(max);
array_string_exprt get_string_expr(array_poolt &array_pool, const exprt &expr)
Fetch the string_exprt corresponding to the given refined_string_exprt.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
bitvector_typet char_type()
exprt get_or_create_length(const array_string_exprt &s)
Get the length of an array_string_exprt from the array_pool.
array_string_exprt find(const exprt &pointer, const exprt &length)
Creates a new array if the pointer is not pointing to an array.
const typet & length_type() const
A base class for expressions that are predicates, i.e., Boolean-typed, and that take exactly two argu...
A base class for relations, i.e., binary predicates whose two operands have the same type.
std::size_t get_width() const
A constant literal expression.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
typet & type()
Return the type of the expression.
Application of (mathematical) function.
The trinary if-then-else operator.
const irept & find(const irep_idt &name) const
const irep_idt & id() const
Binary multiplication Associativity is not specified.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The plus expression Associativity is not specified.
Fixed-width bit-vector with two's complement interpretation.
std::pair< exprt, string_constraintst > add_axioms_for_is_valid_int(const function_application_exprt &f)
Check a string is a valid integer, using the same rules as Java Integer.parseInt.
std::pair< exprt, string_constraintst > add_axioms_from_int_hex(const array_string_exprt &res, const exprt &i)
Add axioms stating that the string res corresponds to the integer argument written in hexadecimal.
std::vector< exprt > get_conjuncts_for_correct_number_format(const array_string_exprt &str, const exprt &radix_as_char, const unsigned long radix_ul, const std::size_t max_size, const bool strict_formatting)
Add axioms making the return value true if the given string is a correct number in the given radix.
parseint_argumentst unpack_parseint_arguments(const function_application_exprt &f, const typet &target_int_type)
std::pair< exprt, string_constraintst > add_axioms_for_string_of_int_with_radix(const array_string_exprt &res, const exprt &input_int, const exprt &radix, size_t max_size)
Add axioms enforcing that the string corresponds to the result of String.valueOf(II) or String....
std::pair< exprt, string_constraintst > add_axioms_for_string_of_int(const array_string_exprt &res, const exprt &input_int, size_t max_size)
Add axioms enforcing that the string corresponds to the result of String.valueOf(I) or String....
string_constraintst add_axioms_for_characters_in_integer_string(const exprt &input_int, const typet &type, const bool strict_formatting, const array_string_exprt &str, const std::size_t max_string_length, const exprt &radix, const unsigned long radix_ul)
Add axioms connecting the characters in the input string to the value of the output integer.
std::pair< exprt, string_constraintst > add_axioms_for_parse_int(const function_application_exprt &f)
Integer value represented by a string.
symbol_generatort fresh_symbol
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
The Boolean constant true.
const typet & subtype() const
Semantic type conversion.
The type of an expression, extends irept.
The unary minus expression.
#define SINCE(year, month, day, msg)
API to expression classes for 'mathematical' expressions.
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
exprt simplify_expr(exprt src, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
#define PRECONDITION(CONDITION)
exprt conjunction(const exprt::operandst &op)
1) generates a conjunction for two or more operands 2) for one operand, returns the operand 3) return...
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Generates string constraints to link results from string functions with their arguments.
signedbv_typet get_return_code_type()
size_t max_printed_string_length(const typet &type, unsigned long radix_ul)
Calculate the string length needed to represent any value of the given type using the given radix.
static unsigned long to_integer_or_default(const exprt &expr, unsigned long def, const namespacet &ns)
If the expression is a constant expression then we get the value of it as an unsigned long.
static exprt int_of_hex_char(const exprt &chr)
Returns the integer value represented by the character.
exprt get_numeric_value_from_character(const exprt &chr, const typet &char_type, const typet &type, const bool strict_formatting, const unsigned long radix_ul)
Get the numeric value of a character, assuming that the radix is large enough.
exprt is_digit_with_radix(const exprt &chr, const bool strict_formatting, const exprt &radix_as_char, const unsigned long radix_ul)
Check if a character is a digit with respect to the given radix, e.g.
binary_relation_exprt less_than_or_equal_to(exprt lhs, exprt rhs)
binary_relation_exprt greater_or_equal_to(exprt lhs, exprt rhs)
binary_relation_exprt greater_than(exprt lhs, exprt rhs)
equal_exprt equal_to(exprt lhs, exprt rhs)
Argument block for parseInt and cousins, common to parseInt itself and CProverString....
Collection of constraints of different types: existential formulas, universal formulas,...
std::vector< exprt > existential
const type_with_subtypet & to_type_with_subtype(const typet &type)