Skip to content

Commit 3854199

Browse files
committed
SMV: typechecking for unary minus
1 parent f8aa6bd commit 3854199

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Diff for: regression/ebmc/range_type/range_type8.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ range_type8.smv
66
^SIGNAL=0$
77
--
88
--
9-
We do not have type checking for unary minus.
9+
We do not have solver support for unary minus on ranges.

Diff for: src/smvlang/smv_range.h

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ class smv_ranget
8484

8585
return *this;
8686
}
87+
88+
// unary minus
89+
smv_ranget operator-() const
90+
{
91+
return smv_ranget{-to, -from};
92+
}
8793
};
8894

8995
#endif // CPROVER_SMV_RANGE_H

Diff for: src/smvlang/smv_typecheck.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,29 @@ void smv_typecheckt::typecheck_expr_rec(
752752
<< "Expected number type for " << to_string(expr);
753753
}
754754
}
755+
else if(expr.id() == ID_unary_minus)
756+
{
757+
typecheck_op(expr, dest_type, mode);
758+
759+
if(expr.operands().size() != 1)
760+
{
761+
error().source_location = expr.find_source_location();
762+
error() << "Expected one operand for " << expr.id() << eom;
763+
throw 0;
764+
}
765+
766+
if(dest_type.is_nil())
767+
{
768+
if(expr.type().id() == ID_range || expr.type().id() == ID_bool)
769+
{
770+
// find proper type for precise arithmetic
771+
smv_ranget smv_range_op =
772+
convert_type(to_unary_minus_expr(expr).op().type());
773+
smv_ranget new_range = -smv_range_op;
774+
new_range.to_type(expr.type());
775+
}
776+
}
777+
}
755778
else if(expr.id()==ID_constant)
756779
{
757780
if(expr.type().id()==ID_integer)

0 commit comments

Comments
 (0)