File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 88
99#include " string_constraint.h"
1010
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+
1130string_constraintt::string_constraintt (
1231 symbol_exprt _univ_var,
1332 exprt lower_bound,
@@ -18,4 +37,12 @@ string_constraintt::string_constraintt(
1837 upper_bound(upper_bound),
1938 body(body)
2039{
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 ());
2148}
You can’t perform that action at this time.
0 commit comments