Skip to content

SMV: make ASSIGN typed #1002

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
Feb 20, 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
4 changes: 2 additions & 2 deletions regression/smv/expressions/smv_if2.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
KNOWNBUG
CORE
smv_if2.smv

^\[.*\] X \(b = 2 \| b = 4\): PROVED up to bound 5$
^EXIT=0$
^SIGNAL=0$
--
--
This yields a type error.
2 changes: 2 additions & 0 deletions regression/smv/expressions/smv_if2.smv
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ VAR b : 1..4;

ASSIGN init(b) := 1;
ASSIGN next(b) := (input ? 1 : 3) + 1;

LTLSPEC X (b = 2 | b = 4)
4 changes: 2 additions & 2 deletions regression/smv/range-type/range_type5.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CORE broken-smt-backend
range_type5.smv
--bound 3
^EXIT=0$
^file .* line 14: Expected expression of type `5..10', but got expression `x', which is of type `0..6'$
^EXIT=2$
^SIGNAL=0$
^\[spec1\] AG \(!x = 6\): PROVED up to bound 3$
--
^warning: ignoring
10 changes: 9 additions & 1 deletion src/smvlang/smv_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ class smv_parse_treet
}

// for ASSIGN_CURRENT, ASSIGN_INIT, ASSIGN_NEXT, DEFINE
const equal_exprt &equal_expr()
const equal_exprt &equal_expr() const
{
PRECONDITION(
is_assign_current() || is_assign_init() || is_assign_next() ||
is_define());
return to_equal_expr(expr);
}

equal_exprt &equal_expr()
{
PRECONDITION(
is_assign_current() || is_assign_init() || is_assign_next() ||
Expand Down
66 changes: 38 additions & 28 deletions src/smvlang/smv_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,47 +1257,57 @@ Function: smv_typecheckt::typecheck
void smv_typecheckt::typecheck(
smv_parse_treet::modulet::itemt &item)
{
modet mode;

switch(item.item_type)
{
case smv_parse_treet::modulet::itemt::ASSIGN_CURRENT:
mode = OTHER;
break;

case smv_parse_treet::modulet::itemt::ASSIGN_INIT:
mode = INIT;
break;

case smv_parse_treet::modulet::itemt::ASSIGN_NEXT:
mode = TRANS;
break;

case smv_parse_treet::modulet::itemt::INIT:
mode=INIT;
break;
typecheck(item.expr, INIT);
convert_expr_to(item.expr, bool_typet{});
return;

case smv_parse_treet::modulet::itemt::TRANS:
mode=TRANS;
break;
typecheck(item.expr, TRANS);
convert_expr_to(item.expr, bool_typet{});
return;

case smv_parse_treet::modulet::itemt::CTLSPEC:
mode = CTL;
break;
typecheck(item.expr, CTL);
convert_expr_to(item.expr, bool_typet{});
return;

case smv_parse_treet::modulet::itemt::LTLSPEC:
mode = LTL;
break;
typecheck(item.expr, LTL);
convert_expr_to(item.expr, bool_typet{});
return;

case smv_parse_treet::modulet::itemt::DEFINE:
case smv_parse_treet::modulet::itemt::INVAR:
case smv_parse_treet::modulet::itemt::FAIRNESS:
default:
mode=OTHER;
}
typecheck(item.expr, OTHER);
convert_expr_to(item.expr, bool_typet{});
return;

case smv_parse_treet::modulet::itemt::ASSIGN_CURRENT:
typecheck(item.equal_expr().lhs(), OTHER);
typecheck(item.equal_expr().rhs(), item.equal_expr().lhs().type(), OTHER);
item.equal_expr().type() = bool_typet{};
return;

case smv_parse_treet::modulet::itemt::ASSIGN_INIT:
typecheck(item.equal_expr().lhs(), INIT);
typecheck(item.equal_expr().rhs(), item.equal_expr().lhs().type(), INIT);
item.equal_expr().type() = bool_typet{};
return;

typecheck(item.expr, mode);
convert_expr_to(item.expr, bool_typet{});
case smv_parse_treet::modulet::itemt::ASSIGN_NEXT:
typecheck(item.equal_expr().lhs(), TRANS);
typecheck(item.equal_expr().rhs(), item.equal_expr().lhs().type(), TRANS);
item.equal_expr().type() = bool_typet{};
return;

case smv_parse_treet::modulet::itemt::DEFINE:
typecheck(item.expr, OTHER);
item.equal_expr().type() = bool_typet{};
return;
}
}

/*******************************************************************\
Expand Down
Loading