Skip to content

Commit 61b3910

Browse files
Add length_constraint method to builtin functions
This give the constraints that ensure the length of the result of a buitin function is correct. Will be used when we don't need the constraints about the actual content of the strings.
1 parent 8684e6d commit 61b3910

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/solvers/refinement/string_builtin_function.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class string_builtin_functiont
3838
virtual exprt
3939
add_constraints(string_constraint_generatort &constraint_generator) const = 0;
4040

41+
/// Constraint ensuring that the length of the strings are coherent with
42+
/// the function call.
43+
virtual exprt length_constraint() const = 0;
44+
4145
exprt return_code;
4246

4347
/// Tells whether the builtin function can be a testing function, that is a
@@ -128,7 +132,12 @@ class string_concat_char_builtin_functiont
128132
exprt add_constraints(string_constraint_generatort &generator) const override
129133
{
130134
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+
}
132141
};
133142

134143
/// String inserting a string into another one
@@ -183,6 +192,15 @@ class string_insertion_builtin_functiont : public string_builtin_functiont
183192
UNREACHABLE;
184193
};
185194

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+
186204
bool maybe_testing_function() const override
187205
{
188206
return false;
@@ -229,6 +247,16 @@ class string_concatenation_builtin_functiont final
229247
result, input1, input2, args[0], args[1]);
230248
UNREACHABLE;
231249
};
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+
}
232260
};
233261

234262
/// String creation from other types
@@ -303,6 +331,13 @@ class string_builtin_function_with_no_evalt : public string_builtin_functiont
303331
{
304332
return generator.add_axioms_for_function_application(function_application);
305333
};
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+
}
306341
};
307342

308343
#endif // CPROVER_SOLVERS_REFINEMENT_STRING_BUILTIN_FUNCTION_H

0 commit comments

Comments
 (0)