@@ -38,6 +38,10 @@ class string_builtin_functiont
38
38
virtual exprt
39
39
add_constraints (string_constraint_generatort &constraint_generator) const = 0 ;
40
40
41
+ // / Constraint ensuring that the length of the strings are coherent with
42
+ // / the function call.
43
+ virtual exprt length_constraint () const = 0;
44
+
41
45
exprt return_code;
42
46
43
47
// / Tells whether the builtin function can be a testing function, that is a
@@ -128,7 +132,12 @@ class string_concat_char_builtin_functiont
128
132
exprt add_constraints (string_constraint_generatort &generator) const override
129
133
{
130
134
return generator.add_axioms_for_concat_char (result, input, args[0 ]);
131
- };
135
+ }
136
+
137
+ exprt length_constraint () const override
138
+ {
139
+ return length_constraint_for_concat_char (result, input);
140
+ }
132
141
};
133
142
134
143
// / String inserting a string into another one
@@ -183,6 +192,15 @@ class string_insertion_builtin_functiont : public string_builtin_functiont
183
192
UNREACHABLE;
184
193
};
185
194
195
+ exprt length_constraint () const override
196
+ {
197
+ if (args.size () == 1 )
198
+ return length_constraint_for_insert (result, input1, input2, args[0 ]);
199
+ if (args.size () == 3 )
200
+ UNIMPLEMENTED;
201
+ UNREACHABLE;
202
+ };
203
+
186
204
bool maybe_testing_function () const override
187
205
{
188
206
return false ;
@@ -229,6 +247,16 @@ class string_concatenation_builtin_functiont final
229
247
result, input1, input2, args[0 ], args[1 ]);
230
248
UNREACHABLE;
231
249
};
250
+
251
+ exprt length_constraint () const override
252
+ {
253
+ if (args.size () == 0 )
254
+ return length_constraint_for_concat (result, input1, input2);
255
+ if (args.size () == 2 )
256
+ return length_constraint_for_concat_substr (
257
+ result, input1, input2, args[0 ], args[1 ]);
258
+ UNREACHABLE;
259
+ }
232
260
};
233
261
234
262
// / String creation from other types
@@ -303,6 +331,13 @@ class string_builtin_function_with_no_evalt : public string_builtin_functiont
303
331
{
304
332
return generator.add_axioms_for_function_application (function_application);
305
333
};
334
+
335
+ exprt length_constraint () const override
336
+ {
337
+ // For now, there is no need for implementing that as `add_constraints`
338
+ // should always be called on these functions
339
+ UNIMPLEMENTED;
340
+ }
306
341
};
307
342
308
343
#endif // CPROVER_SOLVERS_REFINEMENT_STRING_BUILTIN_FUNCTION_H
0 commit comments