cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
string_constraint.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: String solver
4
5
Author: Diffblue Ltd.
6
7
\*******************************************************************/
8
9
#include "
string_constraint.h
"
10
11
#include <
util/namespace.h
>
12
#include <
util/symbol_table.h
>
13
14
#include <
solvers/flattening/bv_pointers.h
>
15
#include <
solvers/sat/satcheck.h
>
16
22
static
bool
cannot_be_neg
(
const
exprt
&expr,
message_handlert
&message_handler)
23
{
24
satcheck_no_simplifiert sat_check(message_handler);
25
symbol_tablet
symbol_table;
26
namespacet
ns(symbol_table);
27
bv_pointerst
solver
{ns, sat_check, message_handler};
28
const
exprt
zero =
from_integer
(0, expr.
type
());
29
const
binary_relation_exprt
non_neg(expr, ID_lt, zero);
30
solver
<< non_neg;
31
return
solver
() ==
decision_proceduret::resultt::D_UNSATISFIABLE
;
32
}
33
34
string_constraintt::string_constraintt
(
35
const
symbol_exprt
&_univ_var,
36
const
exprt
&
lower_bound
,
37
const
exprt
&
upper_bound
,
38
const
exprt
&
body
,
39
message_handlert
&message_handler)
40
:
univ_var
(_univ_var),
41
lower_bound
(
lower_bound
),
42
upper_bound
(
upper_bound
),
43
body
(
body
)
44
{
45
INVARIANT
(
46
cannot_be_neg
(
lower_bound
, message_handler),
47
"String constraints must have non-negative lower bound.\n"
+
48
lower_bound
.pretty());
49
INVARIANT
(
50
cannot_be_neg
(
upper_bound
, message_handler),
51
"String constraints must have non-negative upper bound.\n"
+
52
upper_bound
.pretty());
53
}
54
58
std::string
to_string
(
const
string_not_contains_constraintt
&expr)
59
{
60
std::ostringstream out;
61
out <<
"forall x in ["
<<
format
(expr.
univ_lower_bound
) <<
", "
62
<<
format
(expr.
univ_upper_bound
) <<
"). "
<<
format
(expr.
premise
)
63
<<
" => ("
64
<<
"exists y in ["
<<
format
(expr.
exists_lower_bound
) <<
", "
65
<<
format
(expr.
exists_upper_bound
) <<
"). "
<<
format
(expr.
s0
)
66
<<
"[x+y] != "
<<
format
(expr.
s1
) <<
"[y])"
;
67
return
out.str();
68
}
69
70
void
replace
(
71
const
union_find_replacet
&replace_map,
72
string_not_contains_constraintt
&constraint)
73
{
74
replace_map.
replace_expr
(constraint.
univ_lower_bound
);
75
replace_map.
replace_expr
(constraint.
univ_upper_bound
);
76
replace_map.
replace_expr
(constraint.
premise
);
77
replace_map.
replace_expr
(constraint.
exists_lower_bound
);
78
replace_map.
replace_expr
(constraint.
exists_upper_bound
);
79
replace_map.
replace_expr
(constraint.
s0
);
80
replace_map.
replace_expr
(constraint.
s1
);
81
}
82
83
bool
operator==
(
84
const
string_not_contains_constraintt
&left,
85
const
string_not_contains_constraintt
&right)
86
{
87
return
left.
univ_upper_bound
== right.
univ_upper_bound
&&
88
left.
univ_lower_bound
== right.
univ_lower_bound
&&
89
left.
exists_lower_bound
== right.
exists_lower_bound
&&
90
left.
exists_upper_bound
== right.
exists_upper_bound
&&
91
left.
premise
== right.
premise
&& left.
s0
== right.
s0
&&
92
left.
s1
== right.
s1
;
93
}
from_integer
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition
arith_tools.cpp:99
bv_pointers.h
binary_relation_exprt
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition
std_expr.h:774
bv_pointerst
Definition
bv_pointers.h:17
decision_proceduret::resultt::D_UNSATISFIABLE
@ D_UNSATISFIABLE
Definition
decision_procedure.h:47
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
message_handlert
Definition
message.h:27
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
string_constraintt::body
exprt body
Definition
string_constraint.h:63
string_constraintt::string_constraintt
string_constraintt(const symbol_exprt &_univ_var, const exprt &lower_bound, const exprt &upper_bound, const exprt &body, message_handlert &message_handler)
Definition
string_constraint.cpp:34
string_constraintt::univ_var
symbol_exprt univ_var
Definition
string_constraint.h:60
string_constraintt::lower_bound
exprt lower_bound
Definition
string_constraint.h:61
string_constraintt::upper_bound
exprt upper_bound
Definition
string_constraint.h:62
symbol_exprt
Expression to hold a symbol (variable).
Definition
std_expr.h:132
symbol_tablet
The symbol table.
Definition
symbol_table.h:14
union_find_replacet
Similar interface to union-find for expressions, with a function for replacing sub-expressions by the...
Definition
union_find_replace.h:17
union_find_replacet::replace_expr
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by the representative element of the set they belong to.
Definition
union_find_replace.cpp:28
format
static format_containert< T > format(const T &o)
Definition
format.h:37
namespace.h
satcheck.h
solver
void solver(std::vector< framet > &frames, const std::unordered_set< symbol_exprt, irep_hash > &address_taken, const solver_optionst &solver_options, const namespacet &ns, std::vector< propertyt > &properties, std::size_t property_index)
Definition
solver.cpp:44
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
replace
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
Definition
string_constraint.cpp:70
cannot_be_neg
static bool cannot_be_neg(const exprt &expr, message_handlert &message_handler)
Runs a solver instance to verify whether an expression can only be non-negative.
Definition
string_constraint.cpp:22
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition
string_constraint.cpp:58
operator==
bool operator==(const string_not_contains_constraintt &left, const string_not_contains_constraintt &right)
Definition
string_constraint.cpp:83
string_constraint.h
Defines string constraints.
string_not_contains_constraintt
Constraints to encode non containement of strings.
Definition
string_constraint.h:127
string_not_contains_constraintt::premise
exprt premise
Definition
string_constraint.h:130
string_not_contains_constraintt::exists_lower_bound
exprt exists_lower_bound
Definition
string_constraint.h:131
string_not_contains_constraintt::exists_upper_bound
exprt exists_upper_bound
Definition
string_constraint.h:132
string_not_contains_constraintt::s0
array_string_exprt s0
Definition
string_constraint.h:133
string_not_contains_constraintt::univ_lower_bound
exprt univ_lower_bound
Definition
string_constraint.h:128
string_not_contains_constraintt::univ_upper_bound
exprt univ_upper_bound
Definition
string_constraint.h:129
string_not_contains_constraintt::s1
array_string_exprt s1
Definition
string_constraint.h:134
symbol_table.h
Author: Diffblue Ltd.
solvers
strings
string_constraint.cpp
Generated by
1.17.0