Go to the documentation of this file.
30 const exprt &return_code,
31 const std::vector<exprt> &fun_args,
42 .map([&](
const exprt &arg) {
45 "arguments of format should be strings");
48 .collect<std::vector<array_string_exprt>>();
53 format_string_expr.
content().
id() == ID_array)
55 const auto length = numeric_cast_v<std::size_t>(
69 static bool check_format_string(std::string s)
71 std::string format_specifier=
72 "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])";
73 std::regex regex(format_specifier);
76 while(std::regex_search(s, match, regex))
78 if(match.position()!= 0)
79 for(
const auto &c : match.str())
85 for(
const auto &c : s)
117 static std::pair<array_string_exprt, string_constraintst>
129 std::pair<exprt, string_constraintst> return_code;
135 return {res, std::move(return_code.second)};
142 return {res, std::move(return_code.second)};
146 return {res, std::move(return_code.second)};
150 return {res, std::move(return_code.second)};
157 const exprt is_null_literal =
is_null(string_expr, array_pool);
172 return {res, constraints};
177 return {res, std::move(return_code.second)};
180 const exprt arg_string = string_arg;
182 return {std::move(string_expr), {}};
187 return {res, std::move(return_code.second)};
191 return {res, std::move(return_code.second)};
194 return {res, std::move(return_code.second)};
209 const exprt return_code_upper_case =
212 return_code_upper_case, res, format_specifier_result.first, array_pool);
213 auto upper_case_constraints =
215 merge(upper_case_constraints, std::move(format_specifier_result.second));
216 return {res, std::move(upper_case_constraints)};
229 message.warning() <<
"unimplemented format specifier: " << fs.
conversion
235 INVARIANT(
false,
"format specifier must belong to [bBhHsScCdoxXeEfgGaAtT%n]");
251 if(
id ==
"string_expr")
299 const std::string &s,
300 const std::vector<array_string_exprt> &args,
306 std::vector<array_string_exprt> intermediary_strings;
307 std::size_t arg_count = 0;
315 if(fe.is_format_specifier())
326 arg_count < args.size(),
"number of format must match specifiers");
327 string_arg = args[arg_count++];
333 static_cast<std::size_t
>(fs.
index) <= args.size(),
334 "number of format must match specifiers");
337 string_arg = args[fs.
index - 1];
343 merge(constraints, std::move(result.second));
344 intermediary_strings.push_back(result.first);
351 str, fe.get_format_text().get_content());
352 merge(constraints, result.second);
353 intermediary_strings.push_back(str);
359 if(intermediary_strings.empty())
363 return {return_code, constraints};
368 if(intermediary_strings.size() == 1)
376 merge(constraints, std::move(result.second));
377 return {result.first, std::move(constraints)};
381 for(std::size_t i = 1; i < intermediary_strings.size() - 1; ++i)
387 return_code =
maximum(return_code, result.first);
388 merge(constraints, std::move(result.second));
394 merge(constraints, std::move(result.second));
395 return {
maximum(result.first, return_code), std::move(constraints)};
399 const std::vector<mp_integer> serialized,
405 for(std::size_t i = 0; i < 4; i++)
408 serialized[i] <= 0xFFFF,
409 "Component of serialized value to"
410 "format must be bounded by 0xFFFF");
413 const int64_t int64_value =
414 (serialized[0] << 48).to_long() | (serialized[1] << 32).to_long() |
415 (serialized[2] << 16).to_long() | serialized[3].to_long();
416 const mp_integer mp_integer_value{int64_value};
417 const std::string long_as_string =
integer2string(mp_integer_value, base);
424 return string.size() == 4 &&
string[0] ==
'n' &&
string[1] ==
'u' &&
425 string[2] ==
'l' &&
string[3] ==
'l';
432 const std::vector<mp_integer> &arg)
439 return std::vector<mp_integer>{
'n',
'u',
'l',
'l'};
445 return std::vector<mp_integer>{
'n',
'u',
'l',
'l'};
449 if(
'A' <= c && c <=
'Z')
457 return std::vector<mp_integer>{
'n',
'u',
'l',
'l'};
467 return std::vector<mp_integer>{
'n',
'u',
'l',
'l'};
468 return std::vector<mp_integer>{arg[3]};
473 return std::vector<mp_integer>{
't',
'r',
'u',
'e'};
474 return std::vector<mp_integer>{
'f',
'a',
'l',
's',
'e'};
482 return std::vector<mp_integer>{
'\n'};
484 return std::vector<mp_integer>{
'%'};
499 if(
'a' <= c && c <=
'z')
515 INVARIANT(
false,
"format specifier must belong to [bBhHsScCdoxXeEfgGaAtT%n]");
519 const std::function<
exprt(
const exprt &)> &get_value)
const
524 const std::vector<format_elementt> format_strings =
526 std::vector<mp_integer> result_vector;
527 std::size_t arg_count = 0;
531 if(fe.is_format_specifier())
538 std::vector<mp_integer> evaluated_char_vector;
543 arg_count <
inputs.size(),
544 "number of format must match specifiers");
554 static_cast<std::size_t
>(fs.
index) <=
inputs.size(),
555 "number of format must match specifiers");
564 evaluated_char_vector.begin(),
565 evaluated_char_vector.end(),
566 std::back_inserter(result_vector));
570 result_vector.push_back(
'%');
576 result_vector.push_back(
'\n');
581 for(
char c : fe.get_format_text().get_content())
582 result_vector.emplace_back(c);
600 "add_axioms_for_format should return 0, meaning that formatting was"
602 result_constraint_pair.second.existential.push_back(
604 return result_constraint_pair.second;
623 const exprt &pos_integer,
625 const typet &length_type,
626 const unsigned long radix)
640 pos_integer, max_length - 1, length_type, radix),
651 const exprt &integer,
652 const typet &length_type,
653 const unsigned long radix)
655 int max_pos_int_length;
659 max_pos_int_length = 10;
661 max_pos_int_length = 8;
674 integer, max_pos_int_length, length_type, radix),
730 const exprt arg_string =
762 INVARIANT(
false,
"format specifier must belong to [bBhHsScCdoxXeEfgGaAtT%n]");
771 const std::vector<format_elementt> format_strings =
773 std::vector<exprt> intermediary_string_lengths;
774 std::size_t arg_count = 0;
779 if(fe.is_format_specifier())
790 arg_count <
inputs.size(),
791 "number of format must match specifiers");
792 arg =
inputs[arg_count++];
798 static_cast<std::size_t
>(fs.
index) <=
inputs.size(),
799 "number of format must match specifiers");
805 intermediary_string_lengths.push_back(
818 if(intermediary_string_lengths.empty())
825 exprt total_length = intermediary_string_lengths[0];
826 for(std::size_t i = 1; i < intermediary_string_lengths.size(); ++i)
829 plus_exprt{std::move(total_length), intermediary_string_lengths[i]};
832 std::move(total_length)});
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const typet & length_type() const
exprt conjunction(const exprt::operandst &op)
1) generates a conjunction for two or more operands 2) for one operand, returns the operand 3) return...
binary_relation_exprt greater_or_equal_to(exprt lhs, exprt rhs)
std::pair< exprt, string_constraintst > add_axioms_for_substring(const array_string_exprt &res, const array_string_exprt &str, const exprt &start, const exprt &end)
Add axioms ensuring that res corresponds to the substring of str between indexes ‘start’ = max(start,...
const array_exprt & to_array_expr(const exprt &expr)
Cast an exprt to an array_exprt.
array_string_exprt find(const exprt &pointer, const exprt &length)
Creates a new array if the pointer is not pointing to an array.
The type of an expression, extends irept.
string_constraintst constraints(class symbol_generatort &fresh_symbol, message_handlert &message_handler) const
Set of constraints ensuring result corresponds to input in which lowercase characters of Basic Latin ...
Correspondance between arrays and pointers string representations.
The trinary if-then-else operator.
Fixed-width bit-vector with IEEE floating-point interpretation.
symbol_generatort fresh_symbol
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 get_string_expr(array_poolt &array_pool, const exprt &expr)
Fetch the string_exprt corresponding to the given refined_string_exprt.
const type_with_subtypet & to_type_with_subtype(const typet &type)
The plus expression Associativity is not specified.
Base class for all expressions.
Collection of constraints of different types: existential formulas, universal formulas,...
std::pair< exprt, string_constraintst > add_axioms_for_string_of_float(const function_application_exprt &f)
String representation of a float value.
bitvector_typet index_type()
std::string utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
Construct a string from a constant array.
Fixed-width bit-vector with unsigned binary interpretation.
void merge(string_constraintst &result, string_constraintst other)
Merge two sets of constraints by appending to the first one.
typet & type()
Return the type of the expression.
exprt maximum(const exprt &a, const exprt &b)
Converting each lowercase character of Basic Latin and Latin-1 supplement to the corresponding upperc...
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
Fixed-width bit-vector with two's complement interpretation.
static array_string_exprt make_string(Iter begin, Iter end, const array_typet &array_type)
exprt simplify_expr(exprt src, const namespacet &ns)
The unary minus expression.
const irep_idt & id() const
std::vector< exprt > operandst
The Boolean constant false.
array_string_exprt & to_array_string_expr(exprt &expr)
nonstd::optional< T > optionalt
signedbv_typet get_return_code_type()
Base class for string functions that are built in the solver.
bitvector_typet char_type()
bool is_zero() const
Return whether the expression is a constant representing 0.
std::pair< exprt, string_constraintst > add_axioms_for_constant(const array_string_exprt &res, irep_idt sval, const exprt &guard=true_exprt())
Add axioms ensuring that the provided string expression and constant are equal.
optionalt< std::vector< mp_integer > > eval_string(const array_string_exprt &a, const std::function< exprt(const exprt &)> &get_value)
Given a function get_value which gives a valuation to expressions, attempt to find the current value ...
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
bool is_refined_string_type(const typet &type)
std::pair< exprt, string_constraintst > add_axioms_from_bool(const function_application_exprt &f)
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....
const typet & subtype() const
std::pair< exprt, string_constraintst > add_axioms_from_float_scientific_notation(const array_string_exprt &res, const exprt &f)
Add axioms to write the float in scientific notation.
std::pair< exprt, string_constraintst > add_axioms_for_concat(const array_string_exprt &res, const array_string_exprt &s1, const array_string_exprt &s2)
Add axioms enforcing that res is equal to the concatenation of s1 and s2.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Semantic type conversion.
The Boolean constant true.
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....
binary_relation_exprt less_than(exprt lhs, exprt rhs)
ranget< iteratort > make_range(iteratort begin, iteratort end)
array_string_exprt fresh_string(const typet &index_type, const typet &char_type)
Construct a string expression whose length and content are new variables.
std::vector< exprt > existential
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const std::string integer2string(const mp_integer &n, unsigned base)