27
27
#include < util/format_type.h>
28
28
#include < util/refined_string_type.h>
29
29
#include < util/string_expr.h>
30
+ #include < util/union_find_replace.h>
30
31
31
32
// / ### Universally quantified string constraint
32
33
// /
54
55
// / \f$f\f$ [explicitly stated, implied].
55
56
// /
56
57
// / \todo The fact that we follow this grammar is not enforced at the moment.
57
- class string_constraintt : public exprt
58
+ class string_constraintt final
58
59
{
59
60
public:
60
61
// String constraints are of the form
61
- // forall univ_var in [lower_bound,upper_bound[. premise => body
62
+ // forall univ_var in [lower_bound,upper_bound[. body
63
+ symbol_exprt univ_var;
64
+ exprt lower_bound;
65
+ exprt upper_bound;
66
+ exprt body;
62
67
63
- const exprt &premise () const
64
- {
65
- return op0 ();
66
- }
68
+ string_constraintt () = delete ;
67
69
68
- const exprt &body () const
70
+ string_constraintt (
71
+ symbol_exprt _univ_var,
72
+ exprt lower_bound,
73
+ exprt upper_bound,
74
+ exprt body)
75
+ : univ_var(_univ_var),
76
+ lower_bound (lower_bound),
77
+ upper_bound(upper_bound),
78
+ body(body)
69
79
{
70
- return op1 ();
71
80
}
72
81
73
- const symbol_exprt &univ_var () const
82
+ // Default bound inferior is 0
83
+ string_constraintt (symbol_exprt univ_var, exprt upper_bound, exprt body)
84
+ : string_constraintt(
85
+ univ_var,
86
+ from_integer (0 , univ_var.type()),
87
+ upper_bound,
88
+ body)
74
89
{
75
- return to_symbol_expr (op2 ());
76
90
}
77
91
78
- const exprt & upper_bound () const
92
+ exprt univ_within_bounds () const
79
93
{
80
- return op3 ();
94
+ return and_exprt (
95
+ binary_relation_exprt (lower_bound, ID_le, univ_var),
96
+ binary_relation_exprt (upper_bound, ID_gt, univ_var));
81
97
}
82
98
83
- const exprt & lower_bound () const
99
+ void replace_expr (union_find_replacet &replace_map)
84
100
{
85
- return operands ()[4 ];
101
+ replace_map.replace_expr (lower_bound);
102
+ replace_map.replace_expr (upper_bound);
103
+ replace_map.replace_expr (body);
86
104
}
87
105
88
- private:
89
- string_constraintt ();
90
-
91
- public:
92
- string_constraintt (
93
- const symbol_exprt &_univ_var,
94
- const exprt &bound_inf,
95
- const exprt &bound_sup,
96
- const exprt &body):
97
- exprt (ID_string_constraint)
106
+ exprt negation () const
98
107
{
99
- copy_to_operands (true_exprt (), body);
100
- copy_to_operands (_univ_var, bound_sup, bound_inf);
101
- }
102
-
103
- // Default bound inferior is 0
104
- string_constraintt (
105
- const symbol_exprt &_univ_var,
106
- const exprt &bound_sup,
107
- const exprt &body):
108
- string_constraintt (
109
- _univ_var,
110
- from_integer (0 , _univ_var.type()),
111
- bound_sup,
112
- body)
113
- {}
114
-
115
- exprt univ_within_bounds () const
116
- {
117
- return and_exprt (
118
- binary_relation_exprt (lower_bound (), ID_le, univ_var ()),
119
- binary_relation_exprt (upper_bound (), ID_gt, univ_var ()));
108
+ return and_exprt (univ_within_bounds (), not_exprt (body));
120
109
}
121
110
};
122
111
123
- extern inline const string_constraintt &to_string_constraint (const exprt &expr)
124
- {
125
- PRECONDITION (expr.id ()==ID_string_constraint && expr.operands ().size ()==5 );
126
- return static_cast <const string_constraintt &>(expr);
127
- }
128
-
129
- extern inline string_constraintt &to_string_constraint (exprt &expr)
130
- {
131
- PRECONDITION (expr.id ()==ID_string_constraint && expr.operands ().size ()==5 );
132
- return static_cast <string_constraintt &>(expr);
133
- }
134
-
135
112
// / Used for debug printing.
136
113
// / \param [in] ns: namespace for `from_expr`
137
114
// / \param [in] identifier: identifier for `from_expr`
@@ -140,9 +117,9 @@ extern inline string_constraintt &to_string_constraint(exprt &expr)
140
117
inline std::string to_string (const string_constraintt &expr)
141
118
{
142
119
std::ostringstream out;
143
- out << " forall " << format (expr.univ_var () ) << " in ["
144
- << format (expr.lower_bound ()) << " , " << format (expr.upper_bound ())
145
- << " ). " << format (expr.premise ()) << " => " << format (expr. body () );
120
+ out << " forall " << format (expr.univ_var ) << " in ["
121
+ << format (expr.lower_bound ) << " , " << format (expr.upper_bound ) << " ). "
122
+ << format (expr.body );
146
123
return out.str ();
147
124
}
148
125
0 commit comments