33Module: Expression Representation
44
55Author: Daniel Kroening, kroening@kroening.com
6+ Joel Allred, joel.allred@diffblue.com
67
78\*******************************************************************/
89
@@ -19,13 +20,20 @@ Author: Daniel Kroening, kroening@kroening.com
1920
2021#include < stack>
2122
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
2226void exprt::move_to_operands (exprt &expr)
2327{
2428 operandst &op=operands ();
2529 op.push_back (static_cast <const exprt &>(get_nil_irep ()));
2630 op.back ().swap (expr);
2731}
2832
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
2937void exprt::move_to_operands (exprt &e1 , exprt &e2 )
3038{
3139 operandst &op=operands ();
@@ -38,6 +46,11 @@ void exprt::move_to_operands(exprt &e1, exprt &e2)
3846 op.back ().swap (e2 );
3947}
4048
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: second `exprt` to append to the operands
4154void exprt::move_to_operands (exprt &e1 , exprt &e2 , exprt &e3 )
4255{
4356 operandst &op=operands ();
@@ -52,11 +65,16 @@ void exprt::move_to_operands(exprt &e1, exprt &e2, exprt &e3)
5265 op.back ().swap (e3 );
5366}
5467
68+ // / Copy the given argument to the end of `exprt`'s operands.
69+ // / \param expr: `exprt` to append to the operands
5570void exprt::copy_to_operands (const exprt &expr)
5671{
5772 operands ().push_back (expr);
5873}
5974
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
6078void exprt::copy_to_operands (const exprt &e1 , const exprt &e2 )
6179{
6280 operandst &op=operands ();
@@ -67,6 +85,10 @@ void exprt::copy_to_operands(const exprt &e1, const exprt &e2)
6785 op.push_back (e2 );
6886}
6987
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: second `exprt` to append to the operands
7092void exprt::copy_to_operands (
7193 const exprt &e1 ,
7294 const exprt &e2 ,
@@ -81,13 +103,21 @@ void exprt::copy_to_operands(
81103 op.push_back (e3 );
82104}
83105
106+ // / Create a \ref typecast_exprt to the given type.
107+ // / \param _type: cast destination type
108+ // / \deprecated use constructors instead
84109void exprt::make_typecast (const typet &_type)
85110{
86111 typecast_exprt new_expr (*this , _type);
87112
88113 swap (new_expr);
89114}
90115
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
91121void exprt::make_not ()
92122{
93123 if (is_true ())
@@ -116,48 +146,71 @@ void exprt::make_not()
116146 swap (new_expr);
117147}
118148
149+ // / Return whether the expression is a constant.
150+ // / \return True if is a constant, false otherwise
119151bool exprt::is_constant () const
120152{
121153 return id ()==ID_constant;
122154}
123155
156+ // / Return whether the expression is a constant representing `true`.
157+ // / \return True if is a boolean constant representing `true`, false otherwise.
124158bool exprt::is_true () const
125159{
126160 return is_constant () &&
127161 type ().id ()==ID_bool &&
128162 get (ID_value)!=ID_false;
129163}
130164
165+ // / Return whether the expression is a constant representing `false`.
166+ // / \return True if is a boolean constant representing `false`, false otherwise.
131167bool exprt::is_false () const
132168{
133169 return is_constant () &&
134170 type ().id ()==ID_bool &&
135171 get (ID_value)==ID_false;
136172}
137173
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
138177void exprt::make_bool (bool value)
139178{
140179 *this =exprt (ID_constant, typet (ID_bool));
141180 set (ID_value, value?ID_true:ID_false);
142181}
143182
183+ // / Replace the expression by a boolean expression representing true.
184+ // / \deprecated use constructors instead
144185void exprt::make_true ()
145186{
146187 *this =exprt (ID_constant, typet (ID_bool));
147188 set (ID_value, ID_true);
148189}
149190
191+ // / Replace the expression by a boolean expression representing false.
192+ // / \deprecated use constructors instead
150193void exprt::make_false ()
151194{
152195 *this =exprt (ID_constant, typet (ID_bool));
153196 set (ID_value, ID_false);
154197}
155198
199+ // / Return whether the expression represents a boolean.
200+ // / \return True if is a boolean, false otherwise.
156201bool exprt::is_boolean () const
157202{
158203 return type ().id ()==ID_bool;
159204}
160205
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.
161214bool exprt::is_zero () const
162215{
163216 if (is_constant ())
@@ -202,6 +255,12 @@ bool exprt::is_zero() const
202255 return false ;
203256}
204257
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.
205264bool exprt::is_one () const
206265{
207266 if (is_constant ())
@@ -243,6 +302,11 @@ bool exprt::is_one() const
243302 return false ;
244303}
245304
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.
246310const source_locationt &exprt::find_source_location () const
247311{
248312 const source_locationt &l=source_location ();
0 commit comments