@@ -19,13 +19,20 @@ Author: Daniel Kroening, kroening@kroening.com
1919
2020#include < stack>
2121
22+ // / Move the given argument to the end of `exprt`'s operands.
23+ // / The argument is destroyed and mutated to a reference to a nil `irept`.
24+ // / \param expr: `exprt` to append to the operands
2225void exprt::move_to_operands (exprt &expr)
2326{
2427 operandst &op=operands ();
2528 op.push_back (static_cast <const exprt &>(get_nil_irep ()));
2629 op.back ().swap (expr);
2730}
2831
32+ // / Move the given arguments to the end of `exprt`'s operands.
33+ // / The argument is destroyed and mutated to a reference to a nil `irept`.
34+ // / \param e1: first `exprt` to append to the operands
35+ // / \param e2: second `exprt` to append to the operands
2936void exprt::move_to_operands (exprt &e1 , exprt &e2 )
3037{
3138 operandst &op=operands ();
@@ -38,6 +45,11 @@ void exprt::move_to_operands(exprt &e1, exprt &e2)
3845 op.back ().swap (e2 );
3946}
4047
48+ // / Move the given arguments to the end of `exprt`'s operands.
49+ // / The argument is destroyed and mutated to a reference to a nil `irept`.
50+ // / \param e1: first `exprt` to append to the operands
51+ // / \param e2: second `exprt` to append to the operands
52+ // / \param e3: second `exprt` to append to the operands
4153void exprt::move_to_operands (exprt &e1 , exprt &e2 , exprt &e3 )
4254{
4355 operandst &op=operands ();
@@ -52,11 +64,16 @@ void exprt::move_to_operands(exprt &e1, exprt &e2, exprt &e3)
5264 op.back ().swap (e3 );
5365}
5466
67+ // / Copy the given argument to the end of `exprt`'s operands.
68+ // / \param expr: `exprt` to append to the operands
5569void exprt::copy_to_operands (const exprt &expr)
5670{
5771 operands ().push_back (expr);
5872}
5973
74+ // / Copy the given argument to the end of `exprt`'s operands.
75+ // / \param e1: first `exprt` to append to the operands
76+ // / \param e2: second `exprt` to append to the operands
6077void exprt::copy_to_operands (const exprt &e1 , const exprt &e2 )
6178{
6279 operandst &op=operands ();
@@ -67,6 +84,10 @@ void exprt::copy_to_operands(const exprt &e1, const exprt &e2)
6784 op.push_back (e2 );
6885}
6986
87+ // / Copy the given argument to the end of `exprt`'s operands.
88+ // / \param e1: first `exprt` to append to the operands
89+ // / \param e2: second `exprt` to append to the operands
90+ // / \param e3: second `exprt` to append to the operands
7091void exprt::copy_to_operands (
7192 const exprt &e1 ,
7293 const exprt &e2 ,
@@ -81,13 +102,21 @@ void exprt::copy_to_operands(
81102 op.push_back (e3 );
82103}
83104
105+ // / Create a \ref typecast_exprt to the given type.
106+ // / \param _type: cast destination type
107+ // / \deprecated use constructors instead
84108void exprt::make_typecast (const typet &_type)
85109{
86110 typecast_exprt new_expr (*this , _type);
87111
88112 swap (new_expr);
89113}
90114
115+ // / Negate the expression.
116+ // / Simplifications:
117+ // / - If the expression is trivially true, make it false, and vice versa.
118+ // / - If the expression is an `ID_not`, remove the not.
119+ // / \deprecated use constructors instead
91120void exprt::make_not ()
92121{
93122 if (is_true ())
@@ -116,48 +145,71 @@ void exprt::make_not()
116145 swap (new_expr);
117146}
118147
148+ // / Return whether the expression is a constant.
149+ // / \return True if is a constant, false otherwise
119150bool exprt::is_constant () const
120151{
121152 return id ()==ID_constant;
122153}
123154
155+ // / Return whether the expression is a constant representing `true`.
156+ // / \return True if is a boolean constant representing `true`, false otherwise.
124157bool exprt::is_true () const
125158{
126159 return is_constant () &&
127160 type ().id ()==ID_bool &&
128161 get (ID_value)!=ID_false;
129162}
130163
164+ // / Return whether the expression is a constant representing `false`.
165+ // / \return True if is a boolean constant representing `false`, false otherwise.
131166bool exprt::is_false () const
132167{
133168 return is_constant () &&
134169 type ().id ()==ID_bool &&
135170 get (ID_value)==ID_false;
136171}
137172
173+ // / Replace the expression by a boolean expression representing \p value.
174+ // / \param value: the boolean value to give to the expression
175+ // / \deprecated use constructors instead
138176void exprt::make_bool (bool value)
139177{
140178 *this =exprt (ID_constant, typet (ID_bool));
141179 set (ID_value, value?ID_true:ID_false);
142180}
143181
182+ // / Replace the expression by a boolean expression representing true.
183+ // / \deprecated use constructors instead
144184void exprt::make_true ()
145185{
146186 *this =exprt (ID_constant, typet (ID_bool));
147187 set (ID_value, ID_true);
148188}
149189
190+ // / Replace the expression by a boolean expression representing false.
191+ // / \deprecated use constructors instead
150192void exprt::make_false ()
151193{
152194 *this =exprt (ID_constant, typet (ID_bool));
153195 set (ID_value, ID_false);
154196}
155197
198+ // / Return whether the expression represents a boolean.
199+ // / \return True if is a boolean, false otherwise.
156200bool exprt::is_boolean () const
157201{
158202 return type ().id ()==ID_bool;
159203}
160204
205+ // / Return whether the expression is a constant representing 0.
206+ // / Will consider the following types: ID_integer, ID_natural, ID_rational,
207+ // / ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv,
208+ // / ID_floatbv, ID_pointer.<br>
209+ // / For ID_pointer, returns true iff the value is a zero string or a null
210+ // / pointer.
211+ // / For all other types, return false.
212+ // / \return True if has value 0, false otherwise.
161213bool exprt::is_zero () const
162214{
163215 if (is_constant ())
@@ -202,6 +254,12 @@ bool exprt::is_zero() const
202254 return false ;
203255}
204256
257+ // / Return whether the expression is a constant representing 1.
258+ // / Will consider the following types: ID_integer, ID_natural, ID_rational,
259+ // / ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv,
260+ // / ID_floatbv.<br>
261+ // / For all other types, return false.
262+ // / \return True if has value 1, false otherwise.
205263bool exprt::is_one () const
206264{
207265 if (is_constant ())
@@ -243,6 +301,11 @@ bool exprt::is_one() const
243301 return false ;
244302}
245303
304+ // / Get a \ref source_locationt from the expression or from its operands
305+ // / (non-recursively).
306+ // / If no source location is found, a nil `source_locationt` is returned.
307+ // / \return A source location if found in the expression or its operands, nil
308+ // / otherwise.
246309const source_locationt &exprt::find_source_location () const
247310{
248311 const source_locationt &l=source_location ();
0 commit comments