Skip to content

Commit 3509c42

Browse files
committed
Refactor the std::all_of checks in several bitwise operators into a function.
1 parent 0a327e2 commit 3509c42

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

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

52+
/// \brief Ensures that all operands of the argument expression are of the same
53+
/// type.
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_same_type(const exprt &expr)
58+
{
59+
return std::all_of(
60+
expr.operands().cbegin(),
61+
expr.operands().cend(),
62+
[](const exprt &operand)
63+
{ return can_cast_type<target_typet>(operand.type()); });
64+
}
65+
5266
static smt_sortt convert_type_to_smt_sort(const bool_typet &type)
5367
{
5468
return smt_bool_sortt{};
@@ -154,12 +168,7 @@ static smt_termt convert_expr_to_smt(const concatenation_exprt &concatenation)
154168

155169
static smt_termt convert_expr_to_smt(const bitand_exprt &bitwise_and_expr)
156170
{
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-
}))
171+
if(operands_are_of_same_type<integer_bitvector_typet>(bitwise_and_expr))
163172
{
164173
return convert_multiary_operator_to_terms(
165174
bitwise_and_expr, smt_bit_vector_theoryt::make_and);
@@ -174,12 +183,7 @@ static smt_termt convert_expr_to_smt(const bitand_exprt &bitwise_and_expr)
174183

175184
static smt_termt convert_expr_to_smt(const bitor_exprt &bitwise_or_expr)
176185
{
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-
}))
186+
if(operands_are_of_same_type<integer_bitvector_typet>(bitwise_or_expr))
183187
{
184188
return convert_multiary_operator_to_terms(
185189
bitwise_or_expr, smt_bit_vector_theoryt::make_or);
@@ -194,12 +198,7 @@ static smt_termt convert_expr_to_smt(const bitor_exprt &bitwise_or_expr)
194198

195199
static smt_termt convert_expr_to_smt(const bitxor_exprt &bitwise_xor)
196200
{
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-
}))
201+
if(operands_are_of_same_type<integer_bitvector_typet>(bitwise_xor))
203202
{
204203
return convert_multiary_operator_to_terms(
205204
bitwise_xor, smt_bit_vector_theoryt::make_xor);

0 commit comments

Comments
 (0)