Generates string constraints for functions generating strings from other types, in particular int, long, float, double, char, bool. More...
#include "string_constraint_generator.h"#include <util/deprecate.h>#include <util/mathematical_expr.h>#include <util/simplify_expr.h>#include <cmath>Go to the source code of this file.
Generates string constraints for functions generating strings from other types, in particular int, long, float, double, char, bool.
Definition in file string_constraint_generator_valueof.cpp.
Get the numeric value of a character, assuming that the radix is large enough.
'+' and '-' yield 0.
There are four cases, which occur in ASCII in the following order: '+' and '-', digits, upper case letters, lower case letters
return char >= '0' ? (char - '0') : 0
return char >= 'a' ? (char - 'a' + 10) : char >= '0' ? (char - '0') : 0
return char >= 'a' ? (char - 'a' + 10) : char >= 'A' ? (char - 'A' + 10) : char >= '0' ? (char - '0') : 0
Definition at line 623 of file string_constraint_generator_valueof.cpp.
Returns the integer value represented by the character.
Definition at line 181 of file string_constraint_generator_valueof.cpp.
Check if a character is a digit with respect to the given radix, e.g.
if the radix is 10 then check if the character is in the range 0-9.
Definition at line 555 of file string_constraint_generator_valueof.cpp.
Calculate the string length needed to represent any value of the given type using the given radix.
Due to floating point rounding errors we sometimes return a value 1 larger than needed, which is fine for our purposes.
We want to calculate max, the maximum number of characters needed to represent any value of the given type.
For signed types, the longest string will be for -2^(n_bits-1), so max = 1 + min{k: 2^(n_bits-1) < radix^k} (the 1 is for the minus sign) = 1 + min{k: n_bits-1 < k log_2(radix)} = 1 + min{k: k > (n_bits-1) / log_2(radix)} = 1 + min{k: k > floor((n_bits-1) / log_2(radix))} = 1 + (1 + floor((n_bits-1) / log_2(radix))) = 2 + floor((n_bits-1) / log_2(radix))
For unsigned types, the longest string will be for (2^n_bits)-1, so max = min{k: (2^n_bits)-1 < radix^k} = min{k: 2^n_bits <= radix^k} = min{k: n_bits <= k log_2(radix)} = min{k: k >= n_bits / log_2(radix)} = min{k: k >= ceil(n_bits / log_2(radix))} = ceil(n_bits / log_2(radix))
Definition at line 697 of file string_constraint_generator_valueof.cpp.
If the expression is a constant expression then we get the value of it as an unsigned long.
If not we return a default value.
Definition at line 28 of file string_constraint_generator_valueof.cpp.