Skip to content

Commit 05e1fd6

Browse files
committed
Refactor the std::all_of checks in several bitwise operators into a function.
1 parent 0652b4e commit 05e1fd6

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ static smt_termt convert_multiary_operator_to_terms(
4949
factory);
5050
}
5151

52+
/// \brief Ensures that all operands of the argument expression have related
53+
/// types.
54+
/// \param expr: The expression of which the operands we evaluate for type
55+
/// equality.
56+
template <typename target_typet>
57+
static bool operands_are_of_type(const exprt &expr)
58+
{
59+
return std::all_of(
60+
expr.operands().cbegin(), expr.operands().cend(), [](const exprt &operand) {
61+
return can_cast_type<target_typet>(operand.type());
62+
});
63+
}
64+
5265
static smt_sortt convert_type_to_smt_sort(const bool_typet &type)
5366
{
5467
return smt_bool_sortt{};
@@ -154,12 +167,7 @@ static smt_termt convert_expr_to_smt(const concatenation_exprt &concatenation)
154167

155168
static smt_termt convert_expr_to_smt(const bitand_exprt &bitwise_and_expr)
156169
{
157-
if(std::all_of(
158-
bitwise_and_expr.operands().cbegin(),
159-
bitwise_and_expr.operands().cend(),
160-
[](exprt operand) {
161-
return can_cast_type<integer_bitvector_typet>(operand.type());
162-
}))
170+
if(operands_are_of_type<integer_bitvector_typet>(bitwise_and_expr))
163171
{
164172
return convert_multiary_operator_to_terms(
165173
bitwise_and_expr, smt_bit_vector_theoryt::make_and);
@@ -174,12 +182,7 @@ static smt_termt convert_expr_to_smt(const bitand_exprt &bitwise_and_expr)
174182

175183
static smt_termt convert_expr_to_smt(const bitor_exprt &bitwise_or_expr)
176184
{
177-
if(std::all_of(
178-
bitwise_or_expr.operands().cbegin(),
179-
bitwise_or_expr.operands().cend(),
180-
[](exprt operand) {
181-
return can_cast_type<integer_bitvector_typet>(operand.type());
182-
}))
185+
if(operands_are_of_type<integer_bitvector_typet>(bitwise_or_expr))
183186
{
184187
return convert_multiary_operator_to_terms(
185188
bitwise_or_expr, smt_bit_vector_theoryt::make_or);
@@ -194,12 +197,7 @@ static smt_termt convert_expr_to_smt(const bitor_exprt &bitwise_or_expr)
194197

195198
static smt_termt convert_expr_to_smt(const bitxor_exprt &bitwise_xor)
196199
{
197-
if(std::all_of(
198-
bitwise_xor.operands().cbegin(),
199-
bitwise_xor.operands().cend(),
200-
[](exprt operand) {
201-
return can_cast_type<integer_bitvector_typet>(operand.type());
202-
}))
200+
if(operands_are_of_type<integer_bitvector_typet>(bitwise_xor))
203201
{
204202
return convert_multiary_operator_to_terms(
205203
bitwise_xor, smt_bit_vector_theoryt::make_xor);

0 commit comments

Comments
 (0)