CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
string_constraint_generator_constants.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Generates string constraints for constant strings
4
5Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7\*******************************************************************/
8
11
13
15#include <util/unicode.h>
16
23std::pair<exprt, string_constraintst>
27 const exprt &guard)
28{
29 string_constraintst constraints;
30 const typet index_type = array_pool.get_or_create_length(res).type();
31 const typet &char_type = to_type_with_subtype(res.content().type()).subtype();
32 std::string c_str = id2string(sval);
33 std::wstring str;
34
37#if 0
38 if(mode==ID_java)
40 else
41#endif
42 str = widen(c_str);
43
44 for(std::size_t i = 0; i < str.size(); i++)
45 {
46 const exprt idx = from_integer(i, index_type);
47 const exprt c = from_integer(str[i], char_type);
48 const equal_exprt lemma(res[idx], c);
49 constraints.existential.push_back(implies_exprt(guard, lemma));
50 }
51
52 const exprt s_length = from_integer(str.size(), index_type);
53
54 constraints.existential.push_back(implies_exprt(
56 return {from_integer(0, get_return_code_type()), std::move(constraints)};
57}
58
63std::pair<exprt, string_constraintst>
66{
67 PRECONDITION(f.arguments().size() == 2);
68 string_constraintst constraints;
69 exprt length = f.arguments()[0];
70 constraints.existential.push_back(
71 equal_exprt(length, from_integer(0, length.type())));
72 return {from_integer(0, get_return_code_type()), std::move(constraints)};
73}
74
82std::pair<exprt, string_constraintst>
101
110std::pair<exprt, string_constraintst>
113{
115 PRECONDITION(args.size() == 3); // Bad args to string literal?
116 const array_string_exprt res = array_pool.find(args[1], args[0]);
117 return add_axioms_for_cprover_string(res, args[2], true_exprt());
118}
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
static exprt guard(const exprt::operandst &guards, exprt cond)
bitvector_typet char_type()
Definition c_types.cpp:106
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Boolean AND.
Definition std_expr.h:2125
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.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Equality.
Definition std_expr.h:1366
Base class for all expressions.
Definition expr.h:56
typet & type()
Return the type of the expression.
Definition expr.h:84
Application of (mathematical) function.
Boolean implication.
Definition std_expr.h:2225
Boolean negation.
Definition std_expr.h:2454
std::pair< exprt, string_constraintst > add_axioms_for_empty_string(const function_application_exprt &f)
Add axioms to say that the returned string expression is empty.
std::pair< exprt, string_constraintst > add_axioms_for_cprover_string(const array_string_exprt &res, const exprt &arg, const exprt &guard)
Convert an expression of type string_typet to a string_exprt.
std::pair< exprt, string_constraintst > add_axioms_from_literal(const function_application_exprt &f)
String corresponding to an internal cprover string.
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.
std::pair< exprt, string_constraintst > combine_results(std::pair< exprt, string_constraintst > result1, std::pair< exprt, string_constraintst > result2)
Combine the results of two add_axioms function by taking the maximum of the return codes and merging ...
The Boolean constant true.
Definition std_expr.h:3190
The type of an expression, extends irept.
Definition type.h:29
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
API to expression classes for 'mathematical' expressions.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
Generates string constraints to link results from string functions with their arguments.
signedbv_typet get_return_code_type()
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)
Definition type.h:208
std::wstring widen(const char *s)
Definition unicode.cpp:49