27
27
#include < util/constexpr.def>
28
28
#include < solvers/refinement/string_constraint.h>
29
29
30
+ // / Generation of fresh symbols of a given type
31
+ class symbol_generatort final
32
+ {
33
+ public:
34
+ symbol_exprt
35
+ operator ()(const irep_idt &prefix, const typet &type = bool_typet());
36
+
37
+ private:
38
+ unsigned symbol_count = 0 ;
39
+ };
40
+
41
+ // / Correspondance between arrays and pointers string representations
42
+ class array_poolt final
43
+ {
44
+ public:
45
+ explicit array_poolt (symbol_generatort &symbol_generator)
46
+ : fresh_symbol(symbol_generator)
47
+ {
48
+ }
49
+
50
+ const std::unordered_map<exprt, array_string_exprt, irep_hash> &
51
+ get_arrays_of_pointers () const
52
+ {
53
+ return arrays_of_pointers;
54
+ }
55
+
56
+ exprt get_length (const array_string_exprt &s) const ;
57
+
58
+ void insert (const exprt &pointer_expr, array_string_exprt &array);
59
+
60
+ array_string_exprt find (const exprt &pointer, const exprt &length);
61
+
62
+ array_string_exprt find (const refined_string_exprt &str);
63
+
64
+ // / Converts a struct containing a length and pointer to an array.
65
+ // / This allows to get a string expression from arguments of a string
66
+ // / builtion function, because string arguments in these function calls
67
+ // / are given as a struct containing a length and pointer to an array.
68
+ array_string_exprt of_argument (const exprt &arg);
69
+
70
+ private:
71
+ // associate arrays to char pointers
72
+ std::unordered_map<exprt, array_string_exprt, irep_hash> arrays_of_pointers;
73
+
74
+ // associate length to arrays of infinite size
75
+ std::unordered_map<array_string_exprt, symbol_exprt, irep_hash>
76
+ length_of_array;
77
+
78
+ // generates fresh symbols
79
+ symbol_generatort &fresh_symbol;
80
+
81
+ array_string_exprt make_char_array_for_char_pointer (
82
+ const exprt &char_pointer,
83
+ const typet &char_array_type);
84
+ };
85
+
30
86
class string_constraint_generatort final
31
87
{
32
88
public:
@@ -69,22 +125,22 @@ class string_constraint_generatort final
69
125
return index_exprt (witness.at (c), univ_val);
70
126
}
71
127
72
- symbol_exprt fresh_symbol (
73
- const irep_idt &prefix, const typet &type=bool_typet());
74
- symbol_exprt fresh_univ_index (const irep_idt &prefix, const typet &type);
75
-
76
-
77
128
exprt add_axioms_for_function_application (
78
129
const function_application_exprt &expr);
79
130
131
+ symbol_generatort fresh_symbol;
132
+
133
+ symbol_exprt fresh_univ_index (const irep_idt &prefix, const typet &type);
134
+
80
135
symbol_exprt fresh_exist_index (const irep_idt &prefix, const typet &type);
81
136
82
- const std::map<exprt, array_string_exprt> &get_arrays_of_pointers () const
83
- {
84
- return arrays_of_pointers_;
85
- }
137
+ array_poolt array_pool;
86
138
87
- exprt get_length_of_string_array (const array_string_exprt &s) const ;
139
+ // / Associate array to pointer, and array to length
140
+ // / \return an expression if the given function application is one of
141
+ // / associate pointer and associate length
142
+ optionalt<exprt>
143
+ make_array_pointer_association (const function_application_exprt &expr);
88
144
89
145
// Type used by primitives to signal errors
90
146
const signedbv_typet get_return_code_type ()
@@ -99,9 +155,6 @@ class string_constraint_generatort final
99
155
array_string_exprt get_string_expr (const exprt &expr);
100
156
plus_exprt plus_exprt_with_overflow_check (const exprt &op1, const exprt &op2);
101
157
102
- array_string_exprt associate_char_array_to_char_pointer (
103
- const exprt &char_pointer,
104
- const typet &char_array_type);
105
158
106
159
static constant_exprt constant_char (int i, const typet &char_type);
107
160
@@ -349,7 +402,6 @@ class string_constraint_generatort final
349
402
std::map<string_not_contains_constraintt, symbol_exprt> witness;
350
403
private:
351
404
std::set<array_string_exprt> created_strings;
352
- unsigned symbol_count=0 ;
353
405
const messaget message;
354
406
355
407
std::vector<exprt> lemmas;
@@ -364,12 +416,6 @@ class string_constraint_generatort final
364
416
365
417
// Pool used for the intern method
366
418
std::map<array_string_exprt, symbol_exprt> intern_of_string;
367
-
368
- // associate arrays to char pointers
369
- std::map<exprt, array_string_exprt> arrays_of_pointers_;
370
-
371
- // associate length to arrays of infinite size
372
- std::map<array_string_exprt, symbol_exprt> length_of_array_;
373
419
};
374
420
375
421
exprt is_digit_with_radix (
0 commit comments