Skip to content

SMV: precedence of ! #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/smv/range-type/range_type4.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ range_type4.smv
--bound 10
^EXIT=0$
^SIGNAL=0$
^\[spec1\] AG \(!x = 6\): PROVED up to bound 10$
^\[spec1\] AG !\(x = 6\): PROVED up to bound 10$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/smv/word/bitwise1.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CORE
bitwise1.smv

^\[.*\] !0ud8_123 = 0ud8_132: PROVED$
^\[.*\] !0sd8_123 = -0sd8_124: PROVED$
^\[.*\] !\(0ud8_123 = 0ud8_132\): PROVED$
^\[.*\] !\(0sd8_123 = -0sd8_124\): PROVED$
^\[.*\] \(0ud8_123 \& 0ud8_7\) = 0ud8_3: PROVED$
^\[.*\] \(0ud8_123 \| 0ud8_7\) = 0ud8_127: PROVED$
^\[.*\] \(0ud8_123 xor 0ud8_7\) = 0ud8_124: PROVED$
Expand Down
21 changes: 18 additions & 3 deletions src/smvlang/expr2smv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,28 @@ expr2smvt::resultt expr2smvt::convert_unary(
const std::string &symbol,
precedencet precedence)
{
auto op_rec = convert_rec(src.op());
auto &op = src.op();

auto op_rec = convert_rec(op);

// We special-case negation (!), since the precedence
// of this operator changed between CMU SMV and NuSMV.

// clang-format off
bool parentheses =
op.operands().size() == 1 ? false
: src.id() == ID_not ? true
: precedence >= op_rec.p;
// clang-format on

std::string dest = symbol;
if(precedence > op_rec.p)

if(parentheses)
dest += '(';

dest += op_rec.s;
if(precedence > op_rec.p)

if(parentheses)
dest += ')';

return {precedence, std::move(dest)};
Expand Down
Loading