Skip to content

Commit 24a9ee3

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#2931 from danpoe/refactor/introduce-unary-plus-expr
Introduce unary_plus_exprt
2 parents cd593bb + 083561f commit 24a9ee3

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
249249
return convert_unary_minus(to_unary_expr(expr));
250250
else if(expr.id()==ID_unary_plus)
251251
{
252-
assert(expr.operands().size()==1);
253-
return convert_bitvector(expr.op0());
252+
return convert_bitvector(to_unary_plus_expr(expr).op());
254253
}
255254
else if(expr.id()==ID_abs)
256255
return convert_abs(to_abs_expr(expr));

src/solvers/smt2/smt2_conv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,7 @@ void smt2_convt::convert_expr(const exprt &expr)
10531053
else if(expr.id()==ID_unary_plus)
10541054
{
10551055
// A no-op (apart from type promotion)
1056-
assert(expr.operands().size()==1);
1057-
convert_expr(expr.op0());
1056+
convert_expr(to_unary_plus_expr(expr).op());
10581057
}
10591058
else if(expr.id()==ID_sign)
10601059
{

src/util/std_expr.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,49 @@ inline void validate_expr(const unary_minus_exprt &value)
438438
validate_operands(value, 1, "Unary minus must have one operand");
439439
}
440440

441+
/// \brief The unary plus expression
442+
class unary_plus_exprt : public unary_exprt
443+
{
444+
public:
445+
explicit unary_plus_exprt(const exprt &op)
446+
: unary_exprt(ID_unary_plus, op, op.type())
447+
{
448+
}
449+
};
450+
451+
/// \brief Cast an exprt to a \ref unary_plus_exprt
452+
///
453+
/// \a expr must be known to be \ref unary_plus_exprt.
454+
///
455+
/// \param expr: Source expression
456+
/// \return Object of type \ref unary_plus_exprt
457+
inline const unary_plus_exprt &to_unary_plus_expr(const exprt &expr)
458+
{
459+
PRECONDITION(expr.id() == ID_unary_plus);
460+
DATA_INVARIANT(
461+
expr.operands().size() == 1, "unary plus must have one operand");
462+
return static_cast<const unary_plus_exprt &>(expr);
463+
}
464+
465+
/// \copydoc to_unary_minus_expr(const exprt &)
466+
inline unary_plus_exprt &to_unary_plus_expr(exprt &expr)
467+
{
468+
PRECONDITION(expr.id() == ID_unary_plus);
469+
DATA_INVARIANT(
470+
expr.operands().size() == 1, "unary plus must have one operand");
471+
return static_cast<unary_plus_exprt &>(expr);
472+
}
473+
474+
template <>
475+
inline bool can_cast_expr<unary_plus_exprt>(const exprt &base)
476+
{
477+
return base.id() == ID_unary_plus;
478+
}
479+
inline void validate_expr(const unary_plus_exprt &value)
480+
{
481+
validate_operands(value, 1, "unary plus must have one operand");
482+
}
483+
441484
/// \brief The byte swap expression
442485
class bswap_exprt: public unary_exprt
443486
{

0 commit comments

Comments
 (0)