CBMC
string_constraint.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: 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 
9 Author: 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 
27 class message_handlert;
28 
55 class string_constraintt final
56 {
57 public:
58  // String constraints are of the form
59  // forall univ_var in [lower_bound,upper_bound[. body
64 
66  const symbol_exprt &_univ_var,
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)
79  univ_var,
80  from_integer(0, univ_var.type()),
82  body,
83  message_handler)
84  {
85  }
86 
88  {
89  return and_exprt(
92  }
93 
94  void replace_expr(union_find_replacet &replace_map)
95  {
96  replace_map.replace_expr(lower_bound);
97  replace_map.replace_expr(upper_bound);
98  replace_map.replace_expr(body);
99  }
100 
101  exprt negation() const
102  {
104  }
105 };
106 
110 inline 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 
127 {
135 };
136 
137 std::string to_string(const string_not_contains_constraintt &expr);
138 
139 void replace(
140  const union_find_replacet &replace_map,
141  string_not_contains_constraintt &constraint);
142 
143 bool operator==(
145  const string_not_contains_constraintt &right);
146 
147 // NOLINTNEXTLINE [allow specialization within 'std']
148 namespace std
149 {
150 template <>
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)
Definition: arith_tools.cpp:99
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:2337
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
string_constraintt(const symbol_exprt &_univ_var, const exprt &lower_bound, const exprt &upper_bound, const exprt &body, message_handlert &message_handler)
exprt negation() 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...
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by the representative element of the set they belong to.
static format_containert< T > format(const T &o)
Definition: format.h:37
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.