Skip to content

Commit cafb6b4

Browse files
committed
SMV: further support for assignments of sets to scalars
This extends the support for assignments of sets to scalars in the SMV type checker, via recursive conversion to a predicate.
1 parent ff4f5fb commit cafb6b4

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

src/smvlang/smv_typecheck.cpp

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class smv_typecheckt:public typecheckt
9696
void typecheck_expr_rec(exprt &, modet, bool next);
9797
void convert_expr_to(exprt &, const typet &dest);
9898
void typecheck_assignment(exprt &);
99+
exprt assign_set_rec(const exprt &lhs, const exprt &set_expression);
99100
exprt convert_word_constant(const constant_exprt &) const;
100101

101102
smv_parse_treet::modulet *modulep;
@@ -1868,25 +1869,56 @@ void smv_typecheckt::typecheck_assignment(exprt &expr)
18681869
auto &lhs = equal_expr.lhs();
18691870
auto &rhs = equal_expr.rhs();
18701871

1871-
if(rhs.type().id() == ID_smv_set && rhs.id() == ID_smv_set)
1872+
if(rhs.type().id() == ID_smv_set)
18721873
{
18731874
// Sets can be assigned to scalars, which yields a nondeterministic
1874-
// choice. First check the set elements.
1875-
for(auto &op : rhs.operands())
1876-
convert_expr_to(op, lhs.type());
1875+
// choice. This converts the rhs into a predicate over the lhs.
1876+
expr = assign_set_rec(lhs, rhs);
1877+
}
1878+
else
1879+
{
1880+
convert_expr_to(rhs, lhs.type());
1881+
}
1882+
}
18771883

1878-
// Now turn the nondeterministic choice into a top-level
1879-
// disjunctive constraint.
1880-
exprt::operandst disjuncts;
1884+
/*******************************************************************\
18811885
1882-
for(auto &op : rhs.operands())
1883-
disjuncts.push_back(equal_exprt{lhs, op});
1886+
Function: smv_typecheckt::assign_set_rec
18841887
1885-
expr = disjunction(disjuncts);
1886-
return;
1887-
}
1888+
Inputs:
1889+
1890+
Outputs:
1891+
1892+
Purpose:
1893+
1894+
\*******************************************************************/
1895+
1896+
exprt smv_typecheckt::assign_set_rec(
1897+
const exprt &lhs,
1898+
const exprt &set_expression)
1899+
{
1900+
if(set_expression.type().id() == ID_smv_set)
1901+
{
1902+
if(set_expression.id() == ID_smv_set)
1903+
{
1904+
// Turn the nondeterministic choice into a
1905+
// disjunctive constraint.
1906+
exprt::operandst disjuncts;
1907+
1908+
for(auto &element : set_expression.operands())
1909+
disjuncts.push_back(assign_set_rec(lhs, element));
18881910

1889-
convert_expr_to(rhs, lhs.type());
1911+
return disjunction(disjuncts);
1912+
}
1913+
else
1914+
PRECONDITION(false);
1915+
}
1916+
else
1917+
{
1918+
exprt copy = set_expression;
1919+
convert_expr_to(copy, lhs.type());
1920+
return equal_exprt{lhs, copy};
1921+
}
18901922
}
18911923

18921924
/*******************************************************************\

0 commit comments

Comments
 (0)