3
3
Module: Expression Representation
4
4
5
5
Author: Daniel Kroening, [email protected]
6
+
6
7
7
8
\*******************************************************************/
8
9
19
20
20
21
#include < stack>
21
22
23
+ // / Move the given argument to the end of `exprt`'s operands.
24
+ // / The argument is destroyed and mutated to a reference to a nil `irept`.
25
+ // / \param expr: `exprt` to append to the operands
22
26
void exprt::move_to_operands (exprt &expr)
23
27
{
24
28
operandst &op=operands ();
25
29
op.push_back (static_cast <const exprt &>(get_nil_irep ()));
26
30
op.back ().swap (expr);
27
31
}
28
32
33
+ // / Move the given arguments to the end of `exprt`'s operands.
34
+ // / The arguments are destroyed and mutated to a reference to a nil `irept`.
35
+ // / \param e1: first `exprt` to append to the operands
36
+ // / \param e2: second `exprt` to append to the operands
29
37
void exprt::move_to_operands (exprt &e1 , exprt &e2 )
30
38
{
31
39
operandst &op=operands ();
@@ -38,6 +46,11 @@ void exprt::move_to_operands(exprt &e1, exprt &e2)
38
46
op.back ().swap (e2 );
39
47
}
40
48
49
+ // / Move the given arguments to the end of `exprt`'s operands.
50
+ // / The arguments are destroyed and mutated to a reference to a nil `irept`.
51
+ // / \param e1: first `exprt` to append to the operands
52
+ // / \param e2: second `exprt` to append to the operands
53
+ // / \param e3: third `exprt` to append to the operands
41
54
void exprt::move_to_operands (exprt &e1 , exprt &e2 , exprt &e3 )
42
55
{
43
56
operandst &op=operands ();
@@ -52,11 +65,16 @@ void exprt::move_to_operands(exprt &e1, exprt &e2, exprt &e3)
52
65
op.back ().swap (e3 );
53
66
}
54
67
68
+ // / Copy the given argument to the end of `exprt`'s operands.
69
+ // / \param expr: `exprt` to append to the operands
55
70
void exprt::copy_to_operands (const exprt &expr)
56
71
{
57
72
operands ().push_back (expr);
58
73
}
59
74
75
+ // / Copy the given arguments to the end of `exprt`'s operands.
76
+ // / \param e1: first `exprt` to append to the operands
77
+ // / \param e2: second `exprt` to append to the operands
60
78
void exprt::copy_to_operands (const exprt &e1 , const exprt &e2 )
61
79
{
62
80
operandst &op=operands ();
@@ -67,6 +85,10 @@ void exprt::copy_to_operands(const exprt &e1, const exprt &e2)
67
85
op.push_back (e2 );
68
86
}
69
87
88
+ // / Copy the given arguments to the end of `exprt`'s operands.
89
+ // / \param e1: first `exprt` to append to the operands
90
+ // / \param e2: second `exprt` to append to the operands
91
+ // / \param e3: third `exprt` to append to the operands
70
92
void exprt::copy_to_operands (
71
93
const exprt &e1 ,
72
94
const exprt &e2 ,
@@ -81,13 +103,21 @@ void exprt::copy_to_operands(
81
103
op.push_back (e3 );
82
104
}
83
105
106
+ // / Create a \ref typecast_exprt to the given type.
107
+ // / \param _type: cast destination type
108
+ // / \deprecated use constructors instead
84
109
void exprt::make_typecast (const typet &_type)
85
110
{
86
111
typecast_exprt new_expr (*this , _type);
87
112
88
113
swap (new_expr);
89
114
}
90
115
116
+ // / Negate the expression.
117
+ // / Simplifications:
118
+ // / - If the expression is trivially true, make it false, and vice versa.
119
+ // / - If the expression is an `ID_not`, remove the not.
120
+ // / \deprecated use constructors instead
91
121
void exprt::make_not ()
92
122
{
93
123
if (is_true ())
@@ -116,48 +146,71 @@ void exprt::make_not()
116
146
swap (new_expr);
117
147
}
118
148
149
+ // / Return whether the expression is a constant.
150
+ // / \return True if is a constant, false otherwise
119
151
bool exprt::is_constant () const
120
152
{
121
153
return id ()==ID_constant;
122
154
}
123
155
156
+ // / Return whether the expression is a constant representing `true`.
157
+ // / \return True if is a Boolean constant representing `true`, false otherwise.
124
158
bool exprt::is_true () const
125
159
{
126
160
return is_constant () &&
127
161
type ().id ()==ID_bool &&
128
162
get (ID_value)!=ID_false;
129
163
}
130
164
165
+ // / Return whether the expression is a constant representing `false`.
166
+ // / \return True if is a Boolean constant representing `false`, false otherwise.
131
167
bool exprt::is_false () const
132
168
{
133
169
return is_constant () &&
134
170
type ().id ()==ID_bool &&
135
171
get (ID_value)==ID_false;
136
172
}
137
173
174
+ // / Replace the expression by a Boolean expression representing \p value.
175
+ // / \param value: the Boolean value to give to the expression
176
+ // / \deprecated use constructors instead
138
177
void exprt::make_bool (bool value)
139
178
{
140
179
*this =exprt (ID_constant, typet (ID_bool));
141
180
set (ID_value, value?ID_true:ID_false);
142
181
}
143
182
183
+ // / Replace the expression by a Boolean expression representing true.
184
+ // / \deprecated use constructors instead
144
185
void exprt::make_true ()
145
186
{
146
187
*this =exprt (ID_constant, typet (ID_bool));
147
188
set (ID_value, ID_true);
148
189
}
149
190
191
+ // / Replace the expression by a Boolean expression representing false.
192
+ // / \deprecated use constructors instead
150
193
void exprt::make_false ()
151
194
{
152
195
*this =exprt (ID_constant, typet (ID_bool));
153
196
set (ID_value, ID_false);
154
197
}
155
198
199
+ // / Return whether the expression represents a Boolean.
200
+ // / \return True if is a Boolean, false otherwise.
156
201
bool exprt::is_boolean () const
157
202
{
158
203
return type ().id ()==ID_bool;
159
204
}
160
205
206
+ // / Return whether the expression is a constant representing 0.
207
+ // / Will consider the following types: ID_integer, ID_natural, ID_rational,
208
+ // / ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv,
209
+ // / ID_floatbv, ID_pointer.<br>
210
+ // / For ID_pointer, returns true iff the value is a zero string or a null
211
+ // / pointer.
212
+ // / For everything not in the above list, return false.
213
+ // / \return True if has value 0, false otherwise.
161
214
bool exprt::is_zero () const
162
215
{
163
216
if (is_constant ())
@@ -202,6 +255,12 @@ bool exprt::is_zero() const
202
255
return false ;
203
256
}
204
257
258
+ // / Return whether the expression is a constant representing 1.
259
+ // / Will consider the following types: ID_integer, ID_natural, ID_rational,
260
+ // / ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv,
261
+ // / ID_floatbv.<br>
262
+ // / For all other types, return false.
263
+ // / \return True if has value 1, false otherwise.
205
264
bool exprt::is_one () const
206
265
{
207
266
if (is_constant ())
@@ -243,6 +302,11 @@ bool exprt::is_one() const
243
302
return false ;
244
303
}
245
304
305
+ // / Get a \ref source_locationt from the expression or from its operands
306
+ // / (non-recursively).
307
+ // / If no source location is found, a nil `source_locationt` is returned.
308
+ // / \return A source location if found in the expression or its operands, nil
309
+ // / otherwise.
246
310
const source_locationt &exprt::find_source_location () const
247
311
{
248
312
const source_locationt &l=source_location ();
0 commit comments