Skip to content

Commit fba2cce

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

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/util/std_expr.cpp

Lines changed: 26 additions & 26 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)
@@ -57,94 +57,94 @@ bool operator==(const exprt &lhs, int rhs)
5757
return false;
5858
}
5959

60-
bool operator==(const constant_exprt &lhs, int rhs)
60+
bool constant_exprt::operator==(int rhs) const
6161
{
6262
if(rhs == 0)
6363
{
64-
const irep_idt &type_id = lhs.type().id();
64+
const irep_idt &type_id = type().id();
6565

6666
if(type_id == ID_integer)
6767
{
68-
return integer_typet{}.zero_expr() == lhs;
68+
return integer_typet{}.zero_expr() == *this;
6969
}
7070
else if(type_id == ID_natural)
7171
{
72-
return natural_typet{}.zero_expr() == lhs;
72+
return natural_typet{}.zero_expr() == *this;
7373
}
7474
else if(type_id == ID_real)
7575
{
76-
return real_typet{}.zero_expr() == lhs;
76+
return real_typet{}.zero_expr() == *this;
7777
}
7878
else if(type_id == ID_rational)
7979
{
8080
rationalt rat_value;
81-
if(to_rational(lhs, rat_value))
81+
if(to_rational(*this, rat_value))
8282
CHECK_RETURN(false);
8383
return rat_value.is_zero();
8484
}
8585
else if(
8686
type_id == ID_unsignedbv || type_id == ID_signedbv ||
8787
type_id == ID_c_bool || type_id == ID_c_bit_field)
8888
{
89-
return lhs.value_is_zero_string();
89+
return value_is_zero_string();
9090
}
9191
else if(type_id == ID_fixedbv)
9292
{
93-
return fixedbvt(lhs).is_zero();
93+
return fixedbvt(*this).is_zero();
9494
}
9595
else if(type_id == ID_floatbv)
9696
{
97-
return ieee_float_valuet(lhs).is_zero();
97+
return ieee_float_valuet(*this).is_zero();
9898
}
9999
else if(type_id == ID_pointer)
100100
{
101-
return lhs == nullptr;
101+
return *this == nullptr;
102102
}
103103
else
104104
return false;
105105
}
106106
else if(rhs == 1)
107107
{
108-
const irep_idt &type_id = lhs.type().id();
108+
const irep_idt &type_id = type().id();
109109

110110
if(type_id == ID_integer)
111111
{
112-
return integer_typet{}.one_expr() == lhs;
112+
return integer_typet{}.one_expr() == *this;
113113
}
114114
else if(type_id == ID_natural)
115115
{
116-
return natural_typet{}.one_expr() == lhs;
116+
return natural_typet{}.one_expr() == *this;
117117
}
118118
else if(type_id == ID_real)
119119
{
120-
return real_typet{}.one_expr() == lhs;
120+
return real_typet{}.one_expr() == *this;
121121
}
122122
else if(type_id == ID_rational)
123123
{
124124
rationalt rat_value;
125-
if(to_rational(lhs, rat_value))
125+
if(to_rational(*this, rat_value))
126126
CHECK_RETURN(false);
127127
return rat_value.is_one();
128128
}
129129
else if(
130130
type_id == ID_unsignedbv || type_id == ID_signedbv ||
131131
type_id == ID_c_bool || type_id == ID_c_bit_field)
132132
{
133-
const auto width = to_bitvector_type(lhs.type()).get_width();
133+
const auto width = to_bitvector_type(type()).get_width();
134134
mp_integer int_value =
135-
bvrep2integer(id2string(lhs.get_value()), width, false);
135+
bvrep2integer(id2string(get_value()), width, false);
136136
return int_value == 1;
137137
}
138138
else if(type_id == ID_fixedbv)
139139
{
140-
fixedbv_spect spec{to_fixedbv_type(lhs.type())};
140+
fixedbv_spect spec{to_fixedbv_type(type())};
141141
fixedbvt one{spec};
142142
one.from_integer(1);
143-
return one == fixedbvt{lhs};
143+
return one == fixedbvt{*this};
144144
}
145145
else if(type_id == ID_floatbv)
146146
{
147-
return ieee_float_valuet(lhs) == 1;
147+
return ieee_float_valuet(*this) == 1;
148148
}
149149
else
150150
return false;
@@ -175,10 +175,10 @@ bool operator==(const exprt &lhs, std::nullptr_t rhs)
175175
return lhs.is_constant() && to_constant_expr(lhs).is_null_pointer();
176176
}
177177

178-
bool operator==(const constant_exprt &lhs, std::nullptr_t rhs)
178+
bool constant_exprt::operator==(std::nullptr_t rhs) const
179179
{
180180
(void)rhs; // unused parameter
181-
return lhs.is_null_pointer();
181+
return is_null_pointer();
182182
}
183183

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

src/util/std_expr.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,17 @@ 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 &, std::nullptr_t)
3156+
bool operator==(std::nullptr_t) const;
3157+
31473158
static void check(
31483159
const exprt &expr,
31493160
const validation_modet vm = validation_modet::INVARIANT);
@@ -3192,14 +3203,10 @@ inline constant_exprt &to_constant_expr(exprt &expr)
31923203
/// Return whether the expression \p lhs is a constant of Boolean type that is
31933204
/// representing the Boolean value \p rhs.
31943205
bool operator==(const exprt &lhs, bool rhs);
3195-
/// \copydoc operator==(const exprt &, bool)
3196-
bool operator==(const constant_exprt &lhs, bool rhs);
31973206

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

32043211
/// Return whether the expression \p lhs is a constant representing the numeric
32053212
/// value \p rhs; only values 0 and 1 are supported for \p rhs.
@@ -3213,14 +3220,10 @@ bool operator!=(const constant_exprt &lhs, bool rhs);
32133220
/// ID_fixedbv, ID_floatbv.<br>
32143221
/// For all other types, return false.
32153222
bool operator==(const exprt &lhs, int rhs);
3216-
/// \copydoc operator==(const exprt &, int)
3217-
bool operator==(const constant_exprt &lhs, int rhs);
32183223

32193224
/// Return whether the expression \p lhs is a constant representing the NULL
32203225
/// pointer.
32213226
bool operator==(const exprt &lhs, std::nullptr_t);
3222-
/// \copydoc operator==(const exprt &, std::nullptr_t)
3223-
bool operator==(const constant_exprt &lhs, std::nullptr_t);
32243227

32253228
/// \brief The Boolean constant true
32263229
class true_exprt:public constant_exprt

0 commit comments

Comments
 (0)