CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
string_constraint.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Defines string constraints. These are formulas talking about strings.
4 We implemented two forms of constraints: `string_constraintt`
5 are formulas of the form $\forall univ_var \in [lb,ub[. prem => body$,
6 and not_contains_constraintt of the form:
7 $\forall x in [lb,ub[. p(x) => \exists y in [lb,ub[. s1[x+y] != s2[y]$.
8
9Author: Romain Brenguier, romain.brenguier@diffblue.com
10
11\*******************************************************************/
12
19
20#ifndef CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_H
21#define CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_H
22
23#include <util/format_expr.h>
24#include <util/string_expr.h>
26
28
56{
57public:
58 // String constraints are of the form
59 // forall univ_var in [lower_bound,upper_bound[. body
64
67 const exprt &lower_bound,
68 const exprt &upper_bound,
69 const exprt &body,
70 message_handlert &message_handler);
71
72 // Default bound inferior is 0
76 exprt body,
77 message_handlert &message_handler)
80 from_integer(0, univ_var.type()),
82 body,
83 message_handler)
84 {
85 }
86
93
95 {
96 replace_map.replace_expr(lower_bound);
97 replace_map.replace_expr(upper_bound);
98 replace_map.replace_expr(body);
99 }
100
102 {
104 }
105};
106
110inline std::string to_string(const string_constraintt &expr)
111{
112 std::ostringstream out;
113 out << "forall " << format(expr.univ_var) << " in ["
114 << format(expr.lower_bound) << ", " << format(expr.upper_bound) << "). "
115 << format(expr.body);
116 return out.str();
117}
118
136
137std::string to_string(const string_not_contains_constraintt &expr);
138
139void replace(
142
143bool operator==(
146
147// NOLINTNEXTLINE [allow specialization within 'std']
148namespace std
149{
150template <>
151// NOLINTNEXTLINE [struct identifier 'hash' does not end in t]
153{
154 size_t operator()(const string_not_contains_constraintt &constraint) const
155 {
156 return irep_hash()(constraint.univ_lower_bound) ^
157 irep_hash()(constraint.univ_upper_bound) ^
158 irep_hash()(constraint.exists_lower_bound) ^
159 irep_hash()(constraint.exists_upper_bound) ^
160 irep_hash()(constraint.premise) ^ irep_hash()(constraint.s0) ^
161 irep_hash()(constraint.s1);
162 }
163};
164} // namespace std
165
166#endif
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Boolean AND.
Definition std_expr.h:2125
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition std_expr.h:762
Base class for all expressions.
Definition expr.h:56
Boolean negation.
Definition std_expr.h:2454
string_constraintt(symbol_exprt univ_var, exprt upper_bound, exprt body, message_handlert &message_handler)
void replace_expr(union_find_replacet &replace_map)
exprt univ_within_bounds() const
Expression to hold a symbol (variable)
Definition std_expr.h:131
Similar interface to union-find for expressions, with a function for replacing sub-expressions by the...
static format_containert< T > format(const T &o)
Definition format.h:37
STL namespace.
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
std::string to_string(const string_constraintt &expr)
Used for debug printing.
bool operator==(const string_not_contains_constraintt &left, const string_not_contains_constraintt &right)
String expressions for the string solver.
size_t operator()(const string_not_contains_constraintt &constraint) const
Constraints to encode non containement of strings.