Skip to content

Commit 1cff5ea

Browse files
committed
Make constant_exprt variant of operator== member functions
This provides access to methods that may eventually become private.
1 parent 0900508 commit 1cff5ea

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

src/util/std_expr.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ bool operator!=(const exprt &lhs, bool rhs)
3939
return !lhs.is_constant() || to_constant_expr(lhs) != rhs;
4040
}
4141

42-
bool operator==(const constant_exprt &lhs, bool rhs)
42+
bool constant_exprt::operator==(bool rhs) const
4343
{
44-
return lhs.is_boolean() && (lhs.get_value() != ID_false) == rhs;
44+
return is_boolean() && (get_value() != ID_false) == rhs;
4545
}
4646

47-
bool operator!=(const constant_exprt &lhs, bool rhs)
47+
bool constant_exprt::operator!=(bool rhs) const
4848
{
49-
return !lhs.is_boolean() || (lhs.get_value() != ID_false) != rhs;
49+
return !is_boolean() || (get_value() != ID_false) != rhs;
5050
}
5151

5252
bool operator==(const exprt &lhs, int rhs)
@@ -65,94 +65,94 @@ bool operator!=(const exprt &lhs, int rhs)
6565
return true;
6666
}
6767

68-
bool operator==(const constant_exprt &lhs, int rhs)
68+
bool constant_exprt::operator==(int rhs) const
6969
{
7070
if(rhs == 0)
7171
{
72-
const irep_idt &type_id = lhs.type().id();
72+
const irep_idt &type_id = type().id();
7373

7474
if(type_id == ID_integer)
7575
{
76-
return integer_typet{}.zero_expr() == lhs;
76+
return integer_typet{}.zero_expr() == *this;
7777
}
7878
else if(type_id == ID_natural)
7979
{
80-
return natural_typet{}.zero_expr() == lhs;
80+
return natural_typet{}.zero_expr() == *this;
8181
}
8282
else if(type_id == ID_real)
8383
{
84-
return real_typet{}.zero_expr() == lhs;
84+
return real_typet{}.zero_expr() == *this;
8585
}
8686
else if(type_id == ID_rational)
8787
{
8888
rationalt rat_value;
89-
if(to_rational(lhs, rat_value))
89+
if(to_rational(*this, rat_value))
9090
CHECK_RETURN(false);
9191
return rat_value.is_zero();
9292
}
9393
else if(
9494
type_id == ID_unsignedbv || type_id == ID_signedbv ||
9595
type_id == ID_c_bool || type_id == ID_c_bit_field)
9696
{
97-
return lhs.value_is_zero_string();
97+
return value_is_zero_string();
9898
}
9999
else if(type_id == ID_fixedbv)
100100
{
101-
return fixedbvt(lhs).is_zero();
101+
return fixedbvt(*this).is_zero();
102102
}
103103
else if(type_id == ID_floatbv)
104104
{
105-
return ieee_float_valuet(lhs).is_zero();
105+
return ieee_float_valuet(*this).is_zero();
106106
}
107107
else if(type_id == ID_pointer)
108108
{
109-
return lhs == nullptr;
109+
return *this == nullptr;
110110
}
111111
else
112112
return false;
113113
}
114114
else if(rhs == 1)
115115
{
116-
const irep_idt &type_id = lhs.type().id();
116+
const irep_idt &type_id = type().id();
117117

118118
if(type_id == ID_integer)
119119
{
120-
return integer_typet{}.one_expr() == lhs;
120+
return integer_typet{}.one_expr() == *this;
121121
}
122122
else if(type_id == ID_natural)
123123
{
124-
return natural_typet{}.one_expr() == lhs;
124+
return natural_typet{}.one_expr() == *this;
125125
}
126126
else if(type_id == ID_real)
127127
{
128-
return real_typet{}.one_expr() == lhs;
128+
return real_typet{}.one_expr() == *this;
129129
}
130130
else if(type_id == ID_rational)
131131
{
132132
rationalt rat_value;
133-
if(to_rational(lhs, rat_value))
133+
if(to_rational(*this, rat_value))
134134
CHECK_RETURN(false);
135135
return rat_value.is_one();
136136
}
137137
else if(
138138
type_id == ID_unsignedbv || type_id == ID_signedbv ||
139139
type_id == ID_c_bool || type_id == ID_c_bit_field)
140140
{
141-
const auto width = to_bitvector_type(lhs.type()).get_width();
141+
const auto width = to_bitvector_type(type()).get_width();
142142
mp_integer int_value =
143-
bvrep2integer(id2string(lhs.get_value()), width, false);
143+
bvrep2integer(id2string(get_value()), width, false);
144144
return int_value == 1;
145145
}
146146
else if(type_id == ID_fixedbv)
147147
{
148-
fixedbv_spect spec{to_fixedbv_type(lhs.type())};
148+
fixedbv_spect spec{to_fixedbv_type(type())};
149149
fixedbvt one{spec};
150150
one.from_integer(1);
151-
return one == fixedbvt{lhs};
151+
return one == fixedbvt{*this};
152152
}
153153
else if(type_id == ID_floatbv)
154154
{
155-
return ieee_float_valuet(lhs) == 1;
155+
return ieee_float_valuet(*this) == 1;
156156
}
157157
else
158158
return false;
@@ -161,10 +161,10 @@ bool operator==(const constant_exprt &lhs, int rhs)
161161
PRECONDITION(false);
162162
}
163163

164-
bool operator!=(const constant_exprt &lhs, int rhs) const
164+
bool constant_exprt::operator!=(int rhs) const
165165
{
166166
PRECONDITION(rhs == 0 || rhs == 1);
167-
return !(lhs == rhs);
167+
return !(*this == rhs);
168168
}
169169

170170
bool constant_exprt::is_null_pointer() const
@@ -195,16 +195,16 @@ bool operator!=(const exprt &lhs, std::nullptr_t rhs)
195195
return !lhs.is_constant() || !to_constant_expr(lhs).is_null_pointer();
196196
}
197197

198-
bool operator==(const constant_exprt &lhs, std::nullptr_t rhs)
198+
bool constant_exprt::operator==(std::nullptr_t rhs) const
199199
{
200200
(void)rhs; // unused parameter
201-
return lhs.is_null_pointer();
201+
return is_null_pointer();
202202
}
203203

204-
bool operator!=(const constant_exprt &lhs, std::nullptr_t rhs) const
204+
bool constant_exprt::operator!=(std::nullptr_t rhs) const
205205
{
206206
(void)rhs; // unused parameter
207-
return !lhs.is_null_pointer();
207+
return !is_null_pointer();
208208
}
209209

210210
void constant_exprt::check(const exprt &expr, const validation_modet vm)

src/util/std_expr.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,21 @@ class constant_exprt : public nullary_exprt
31443144
/// false in all other cases.
31453145
bool is_null_pointer() const;
31463146

3147+
using irept::operator==;
3148+
using irept::operator!=;
3149+
/// \copydoc operator==(const exprt &, bool)
3150+
bool operator==(bool rhs) const;
3151+
/// \copydoc operator!=(const exprt &, bool)
3152+
bool operator!=(bool rhs) const;
3153+
/// \copydoc operator==(const exprt &, int)
3154+
bool operator==(int rhs) const;
3155+
/// \copydoc operator!=(const exprt &, int)
3156+
bool operator!=(int rhs) const;
3157+
/// \copydoc operator==(const exprt &, std::nullptr_t)
3158+
bool operator==(std::nullptr_t) const;
3159+
/// \copydoc operator!=(const exprt &, std::nullptr_t)
3160+
bool operator!=(std::nullptr_t) const;
3161+
31473162
static void check(
31483163
const exprt &expr,
31493164
const validation_modet vm = validation_modet::INVARIANT);
@@ -3192,14 +3207,10 @@ inline constant_exprt &to_constant_expr(exprt &expr)
31923207
/// Return whether the expression \p lhs is a constant of Boolean type that is
31933208
/// representing the Boolean value \p rhs.
31943209
bool operator==(const exprt &lhs, bool rhs);
3195-
/// \copydoc operator==(const exprt &, bool)
3196-
bool operator==(const constant_exprt &lhs, bool rhs);
31973210

31983211
/// Return whether the expression \p lhs is not a constant of Boolean type or is
31993212
/// not representing the Boolean value \p rhs.
32003213
bool operator!=(const exprt &lhs, bool rhs);
3201-
/// \copydoc operator!=(const exprt &, bool)
3202-
bool operator!=(const constant_exprt &lhs, bool rhs);
32033214

32043215
/// Return whether the expression \p lhs is a constant representing the numeric
32053216
/// value \p rhs; only values 0 and 1 are supported for \p rhs.
@@ -3213,24 +3224,16 @@ bool operator!=(const constant_exprt &lhs, bool rhs);
32133224
/// ID_fixedbv, ID_floatbv.<br>
32143225
/// For all other types, return false.
32153226
bool operator==(const exprt &lhs, int rhs);
3216-
/// \copydoc operator==(const exprt &, int)
3217-
bool operator==(const constant_exprt &lhs, int rhs);
32183227

32193228
/// Returns the negation of \ref operator==(const exprt &, int).
32203229
bool operator!=(const exprt &lhs, int rhs);
3221-
/// \copydoc operator!=(const exprt &, int)
3222-
bool operator!=(const constant_exprt &lhs, int rhs);
32233230

32243231
/// Return whether the expression \p lhs is a constant representing the NULL
32253232
/// pointer.
32263233
bool operator==(const exprt &lhs, std::nullptr_t);
3227-
/// \copydoc operator==(const exprt &, std::nullptr_t)
3228-
bool operator==(const constant_exprt &lhs, std::nullptr_t);
32293234

32303235
/// Returns the negation of \ref operator==(const exprt &, std::nullptr_t).
32313236
bool operator!=(const exprt &lhs, std::nullptr_t);
3232-
/// \copydoc operator!=(const exprt &, std::nullptr_t)
3233-
bool operator!=(const constant_exprt &lhs, std::nullptr_t);
32343237

32353238
/// \brief The Boolean constant true
32363239
class true_exprt:public constant_exprt

0 commit comments

Comments
 (0)