6
6
7
7
\section string_solver_interface String solver interface
8
8
9
+ The string solver is particularly aimed at string logic, but since it inherits
10
+ from \ref bv_refinementt it is also capable of handling arithmetic, array logic,
11
+ floating point operations etc.
12
+ The backend uses the flattening of \ref boolbvt to convert expressions to boolean formula.
13
+
14
+ An example of a problem given to string solver could look like this:
15
+
16
+ ~~~~~
17
+ return_code == cprover_string_concat_func(
18
+ length1, array1,
19
+ { .length=length2, .content=content2 },
20
+ { .length=length3, .content=content3 })
21
+ length3 == length2
22
+ content3 == content2
23
+ is_equal == cprover_string_equals_func(length1, array1, 2, {'a', 'a'})
24
+ is_equal == 1
25
+ ~~~~~
26
+
27
+ Details about the meaning of the primitives ` cprover_string_concat_func ` and
28
+ ` cprover_string_equals_func ` are given in section \ref primitives "String Primitives".
29
+
30
+ The first equality means that the string represented by ` {length1, array1} ` is
31
+ the concatanation of the string represented by ` {length2, array2} ` and
32
+ ` {length3, array3} ` . The second and third mean that ` {length2, array2} ` and
33
+ ` {length3, array3} ` represent the same string. The fourth means that ` is_equal `
34
+ is 1 if and only if ` {length1, array1} ` is the string "aa". The last equation
35
+ ensures that ` is_equal ` has to be equal to 1 in the solution.
36
+
37
+ For this system of equations the string solver should answer that it is
38
+ satisfiable. It is then possible to recover which assignments make all
39
+ equation true, in that case ` length2 = length3 = 1 ` and
40
+ ` content2 = content3 = {'a'} ` .
41
+
42
+
9
43
\subsection general_interface General interface
10
44
11
- The common interface for solvers in CProver is inherited from
45
+ The common interface for solvers in CProver is inherited from
12
46
` decision_proceduret ` and is the common interface for all solvers.
13
47
It is essentially composed of these three functions:
14
48
15
- - ` string_refinementt::set_to(const exprt &expr, bool value) ` :
49
+ - ` string_refinementt::set_to(const exprt &expr, bool value) ` :
16
50
\copybrief string_refinementt::set_to
17
- - ` string_refinementt::dec_solve() ` :
51
+ - ` string_refinementt::dec_solve() ` :
18
52
\copybrief string_refinementt::dec_solve
19
- - ` string_refinementt::get(const exprt &expr) const ` :
53
+ - ` string_refinementt::get(const exprt &expr) const ` :
20
54
\copybrief string_refinementt::get
21
-
55
+
22
56
For each goal given to CProver:
23
- - ` set_to ` is called on several equations, roughly one for each step of the
57
+ - ` set_to ` is called on several equations, roughly one for each step of the
24
58
symbolic execution that leads to that goal;
25
59
- ` dec_solve ` is called to determine whether the goal is reachable given these
26
60
equations;
27
61
- ` get ` is called by the interpreter to obtain concrete value to build a trace
28
62
leading to the goal;
29
- - The same process can be repeated for further goals, in that case the
63
+ - The same process can be repeated for further goals, in that case the
30
64
constraints added by previous calls to ` set_to ` remain valid.
31
65
32
66
\subsection specificity Specificity of the string solver
33
67
34
- The specificity of the solver is in what kind of expressions ` set_to ` accepts
68
+ The specificity of the solver is in what kind of expressions ` set_to ` accepts
35
69
and understands. ` string_refinementt::set_to ` accepts all constraints that are
36
70
normally accepted by ` bv_refinementt ` .
37
71
38
72
` string_refinementt::set_to ` also understands constraints of the form:
39
- * ` char_pointer1 = b ? char_pointer2 : char_pointer3 ` where ` char_pointer<i> `
73
+ * ` char_pointer1 = b ? char_pointer2 : char_pointer3 ` where ` char_pointer<i> `
40
74
variables are of type pointer to characters and ` b ` is a Boolean
41
75
expression.
42
76
* ` i = cprover_primitive(args) ` where ` i ` is of signed bit vector type.
43
77
String primitives are listed in the next section.
44
78
45
- \note In the implementation, equations that are not of these forms are passed
79
+ \note In the implementation, equations that are not of these forms are passed
46
80
to an embedded ` bv_refinementt ` solver.
47
81
48
82
\subsection string-representation String representation in the solver
49
83
50
84
String primitives can have arguments which are pointers to characters.
51
- These pointers represent strings.
52
- To each of these pointers the string solver associate a char array
85
+ These pointers represent strings.
86
+ To each of these pointers the string solver associate a char array
53
87
which represents the content of the string.
54
- If the pointer is the address of an actual array in the program they should be
88
+ If the pointer is the address of an actual array in the program they should be
55
89
linked by using the primitive ` cprover_string_associate_array_to_pointer ` .
56
90
The length of the array can also be linked to a variable of the program using
57
91
` cprover_string_associate_length_to_array ` .
58
92
59
93
\warning The solver assumes the memory pointed by the arguments is immutable
60
94
which is not something that is true in general for C pointers for instance.
61
- Therefore for each transformation on a string, it is assumed the program
95
+ Therefore for each transformation on a string, it is assumed the program
62
96
allocates a new string before calling a primitive.
63
97
64
98
\section primitives String primitives
@@ -72,7 +106,7 @@ allocates a new string before calling a primitive.
72
106
* ` cprover_string_char_at ` :
73
107
\copybrief string_constraint_generatort::add_axioms_for_char_at(const function_application_exprt &f)
74
108
\link string_constraint_generatort::add_axioms_for_char_at(const function_application_exprt &f) More... \endlink
75
- * ` cprover_string_length ` :
109
+ * ` cprover_string_length ` :
76
110
\copybrief string_constraint_generatort::add_axioms_for_length(const function_application_exprt &f)
77
111
\link string_constraint_generatort::add_axioms_for_length(const function_application_exprt &f) More... \endlink
78
112
@@ -81,10 +115,10 @@ allocates a new string before calling a primitive.
81
115
* ` cprover_string_compare_to ` :
82
116
\copybrief string_constraint_generatort::add_axioms_for_compare_to(const function_application_exprt &f)
83
117
\link string_constraint_generatort::add_axioms_for_compare_to(const function_application_exprt &f) More... \endlink
84
- * ` cprover_string_contains ` :
118
+ * ` cprover_string_contains ` :
85
119
\copybrief string_constraint_generatort::add_axioms_for_contains(const function_application_exprt &f)
86
120
\link string_constraint_generatort::add_axioms_for_contains(const function_application_exprt &f) More... \endlink
87
- * ` cprover_string_equals ` :
121
+ * ` cprover_string_equals ` :
88
122
\copybrief string_constraint_generatort::add_axioms_for_equals(const function_application_exprt &f)
89
123
\link string_constraint_generatort::add_axioms_for_equals(const function_application_exprt &f) More... \endlink
90
124
* ` cprover_string_equals_ignore_case ` :
@@ -99,25 +133,25 @@ allocates a new string before calling a primitive.
99
133
* ` cprover_string_is_suffix ` :
100
134
\copybrief string_constraint_generatort::add_axioms_for_is_suffix
101
135
\link string_constraint_generatort::add_axioms_for_is_suffix More... \endlink
102
- * ` cprover_string_index_of ` :
136
+ * ` cprover_string_index_of ` :
103
137
\copybrief string_constraint_generatort::add_axioms_for_index_of(const function_application_exprt &f)
104
138
\link string_constraint_generatort::add_axioms_for_index_of(const function_application_exprt &f) More... \endlink
105
139
* ` cprover_string_last_index_of ` :
106
140
\copybrief string_constraint_generatort::add_axioms_for_last_index_of(const function_application_exprt &f)
107
141
\link string_constraint_generatort::add_axioms_for_last_index_of(const function_application_exprt &f) More... \endlink
108
142
109
- \subsection transformations Transformations:
143
+ \subsection transformations Transformations:
110
144
111
145
* ` cprover_string_char_set ` :
112
146
\copybrief string_constraint_generatort::add_axioms_for_char_set(const function_application_exprt &f)
113
147
\link string_constraint_generatort::add_axioms_for_char_set(const function_application_exprt &f) More... \endlink
114
- * ` cprover_string_concat ` :
148
+ * ` cprover_string_concat ` :
115
149
\copybrief string_constraint_generatort::add_axioms_for_concat(const function_application_exprt &f)
116
150
\link string_constraint_generatort::add_axioms_for_concat(const function_application_exprt &f) More... \endlink
117
151
* ` cprover_string_delete ` :
118
152
\copybrief string_constraint_generatort::add_axioms_for_delete(const function_application_exprt &f)
119
153
\link string_constraint_generatort::add_axioms_for_delete(const function_application_exprt &f) More... \endlink
120
- * ` cprover_string_insert ` :
154
+ * ` cprover_string_insert ` :
121
155
\copybrief string_constraint_generatort::add_axioms_for_insert(const function_application_exprt &f)
122
156
\link string_constraint_generatort::add_axioms_for_insert(const function_application_exprt &f) More... \endlink
123
157
* ` cprover_string_replace ` :
@@ -126,7 +160,7 @@ allocates a new string before calling a primitive.
126
160
* ` cprover_string_set_length ` :
127
161
\copybrief string_constraint_generatort::add_axioms_for_set_length(const function_application_exprt &f)
128
162
\link string_constraint_generatort::add_axioms_for_set_length(const function_application_exprt &f) More... \endlink
129
- * ` cprover_string_substring ` :
163
+ * ` cprover_string_substring ` :
130
164
\copybrief string_constraint_generatort::add_axioms_for_substring(const function_application_exprt &f)
131
165
\link string_constraint_generatort::add_axioms_for_substring(const function_application_exprt &f) More... \endlink
132
166
* ` cprover_string_to_lower_case ` :
@@ -166,18 +200,18 @@ allocates a new string before calling a primitive.
166
200
\subsection deprecated Deprecated primitives:
167
201
168
202
* ` cprover_string_concat_code_point ` , ` cprover_string_code_point_at ` ,
169
- ` cprover_string_code_point_before ` , ` cprover_string_code_point_count ` :
203
+ ` cprover_string_code_point_before ` , ` cprover_string_code_point_count ` :
170
204
Java specific, should be part of Java models.
171
- * ` cprover_string_offset_by_code_point ` , ` cprover_string_concat_char ` ,
172
- ` cprover_string_concat_int ` , ` cprover_string_concat_long ` ,
205
+ * ` cprover_string_offset_by_code_point ` , ` cprover_string_concat_char ` ,
206
+ ` cprover_string_concat_int ` , ` cprover_string_concat_long ` ,
173
207
` cprover_string_concat_bool ` , ` cprover_string_concat_double ` ,
174
- ` cprover_string_concat_float ` , ` cprover_string_insert_int ` ,
208
+ ` cprover_string_concat_float ` , ` cprover_string_insert_int ` ,
175
209
` cprover_string_insert_long ` , ` cprover_string_insert_bool ` ,
176
210
` cprover_string_insert_char ` , ` cprover_string_insert_double ` ,
177
- ` cprover_string_insert_float ` :
211
+ ` cprover_string_insert_float ` :
178
212
Should be done in two steps: conversion from primitive type and call
179
213
to the string primitive.
180
- * ` cprover_string_array_of_char_pointer ` , ` cprover_string_to_char_array ` :
214
+ * ` cprover_string_array_of_char_pointer ` , ` cprover_string_to_char_array ` :
181
215
Pointer to char array association
182
216
is now handled by ` string_constraint_generatort ` , there is no need for
183
217
explicit conversion.
@@ -186,15 +220,15 @@ allocates a new string before calling a primitive.
186
220
Should use ` cprover_string_length(s) == 0 ` instead.
187
221
* ` cprover_string_empty_string ` : Can use literal of empty string instead.
188
222
* ` cprover_string_of_long ` : Should be the same as ` cprover_string_of_int ` .
189
- * ` cprover_string_delete_char_at ` : A call to
190
- ` cprover_string_delete_char_at(s, i) ` would be the same thing as
223
+ * ` cprover_string_delete_char_at ` : A call to
224
+ ` cprover_string_delete_char_at(s, i) ` would be the same thing as
191
225
` cprover_string_delete(s, i, i+1) ` .
192
226
* ` cprover_string_of_bool ` :
193
227
Language dependent, should be implemented in the models.
194
228
* ` cprover_string_copy ` : Same as ` cprover_string_substring(s, 0) ` .
195
229
* ` cprover_string_of_int_hex ` : Same as ` cprover_string_of_int(s, 16) ` .
196
230
* ` cprover_string_of_double ` : Same as ` cprover_string_of_float ` .
197
-
231
+
198
232
\section algorithm Decision algorithm
199
233
200
234
\copydetails string_refinementt::dec_solve
@@ -203,9 +237,9 @@ allocates a new string before calling a primitive.
203
237
204
238
This is done by generate_instantiations(messaget::mstreamt &stream, const namespacet &ns, const string_constraint_generatort &generator, const index_set_pairt &index_set, const string_axiomst &axioms).
205
239
\copydetails generate_instantiations(messaget::mstreamt &stream, const namespacet &ns, const string_constraint_generatort &generator, const index_set_pairt &index_set, const string_axiomst &axioms)
206
-
240
+
207
241
\subsection axiom-check Axiom check
208
242
209
243
\copydetails check_axioms(const string_axiomst &axioms, string_constraint_generatort &generator, const std::function<exprt(const exprt &)> &get, messaget::mstreamt &stream, const namespacet &ns, std::size_t max_string_length, bool use_counter_example, ui_message_handlert::uit ui, const union_find_replacet &symbol_resolve)
210
- \link check_axioms(const string_axiomst &axioms, string_constraint_generatort &generator, const std::function<exprt(const exprt &)> &get, messaget::mstreamt &stream, const namespacet &ns, std::size_t max_string_length, bool use_counter_example, ui_message_handlert::uit ui, const union_find_replacet &symbol_resolve)
244
+ \link check_axioms(const string_axiomst &axioms, string_constraint_generatort &generator, const std::function<exprt(const exprt &)> &get, messaget::mstreamt &stream, const namespacet &ns, std::size_t max_string_length, bool use_counter_example, ui_message_handlert::uit ui, const union_find_replacet &symbol_resolve)
211
245
(See function documentation...) \endlink
0 commit comments