File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 8
8
9
9
#include " string_constraint.h"
10
10
11
+ #include < solvers/sat/satcheck.h>
12
+ #include < util/symbol_table.h>
13
+
14
+ // / Runs a solver instance to verify whether an expression can only be
15
+ // non-negative.
16
+ // / \param expr: the expression to check for negativity
17
+ // / \return true if `expr < 0` is unsatisfiable, false otherwise
18
+ static bool cannot_be_neg (const exprt &expr)
19
+ {
20
+ satcheck_no_simplifiert sat_check;
21
+ symbol_tablet symbol_table;
22
+ namespacet ns (symbol_table);
23
+ boolbvt solver (ns, sat_check);
24
+ const exprt zero = from_integer (0 , expr.type ());
25
+ const binary_relation_exprt non_neg (expr, ID_lt, zero);
26
+ solver << non_neg;
27
+ return solver () == decision_proceduret::resultt::D_UNSATISFIABLE;
28
+ }
29
+
11
30
string_constraintt::string_constraintt (
12
31
symbol_exprt _univ_var,
13
32
exprt lower_bound,
@@ -18,4 +37,12 @@ string_constraintt::string_constraintt(
18
37
upper_bound(upper_bound),
19
38
body(body)
20
39
{
40
+ INVARIANT (
41
+ cannot_be_neg (lower_bound),
42
+ " String constraints must have non-negative lower bound.\n " +
43
+ lower_bound.pretty ());
44
+ INVARIANT (
45
+ cannot_be_neg (upper_bound),
46
+ " String constraints must have non-negative upper bound.\n " +
47
+ upper_bound.pretty ());
21
48
}
You can’t perform that action at this time.
0 commit comments