Skip to content

Commit 5ed7010

Browse files
committed
SMV: move mechanism for next(...)
This moves the mechanism for converting next(...) into next_symbol expressions from convert(...) to typecheck(...). This will enable conversion of complex identifiers.
1 parent e31efbf commit 5ed7010

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/smvlang/smv_typecheck.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class smv_typecheckt:public typecheckt
5353
INIT,
5454
INVAR,
5555
TRANS,
56+
TRANS_NEXT,
5657
OTHER,
5758
LTL,
5859
CTL
@@ -65,8 +66,7 @@ class smv_typecheckt:public typecheckt
6566
void convert_defines(exprt::operandst &invar);
6667
void convert_define(const irep_idt &identifier);
6768

68-
typedef enum { NORMAL, NEXT } expr_modet;
69-
void convert(exprt &, expr_modet);
69+
void convert(exprt &);
7070

7171
void typecheck(exprt &, modet);
7272
void typecheck_op(exprt &, const typet &, modet);
@@ -201,7 +201,7 @@ void smv_typecheckt::flatten_hierarchy(smv_parse_treet::modulet &smv_module)
201201
static_cast<exprt &>(static_cast<irept &>(item.expr.type()));
202202

203203
for(auto &op : inst.operands())
204-
convert(op, NORMAL);
204+
convert(op);
205205

206206
auto instance_base_name = to_symbol_expr(item.expr).get_identifier();
207207

@@ -594,17 +594,27 @@ Function: smv_typecheckt::typecheck_expr_rec
594594

595595
void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
596596
{
597-
if(expr.id()==ID_symbol ||
598-
expr.id()==ID_next_symbol)
597+
if(expr.id() == ID_smv_next)
599598
{
599+
if(mode == TRANS_NEXT)
600+
{
601+
throw errort().with_location(expr.find_source_location())
602+
<< "next(next(...)) encountered";
603+
}
604+
600605
// next_symbol is only allowed in TRANS mode
601-
if(expr.id() == ID_next_symbol && mode != TRANS && mode != OTHER)
606+
if(mode != TRANS && mode != OTHER)
602607
throw errort().with_location(expr.find_source_location())
603608
<< "next(...) is not allowed here";
604609

605-
const irep_idt &identifier=expr.get(ID_identifier);
606-
bool next=expr.id()==ID_next_symbol;
607-
610+
expr = to_unary_expr(expr).op();
611+
612+
typecheck_expr_rec(expr, TRANS_NEXT);
613+
}
614+
else if(expr.id() == ID_symbol || expr.id() == ID_next_symbol)
615+
{
616+
const irep_idt &identifier = expr.get(ID_identifier);
617+
608618
if(define_map.find(identifier)!=define_map.end())
609619
convert_define(identifier);
610620

@@ -616,12 +626,15 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
616626
<< "variable `" << identifier << "' not found";
617627
}
618628

629+
if(mode == TRANS_NEXT)
630+
expr.id(ID_next_symbol);
631+
619632
symbolt &symbol=*s_it;
620633

621634
assert(symbol.type.is_not_nil());
622635
expr.type()=symbol.type;
623636

624-
if(mode==INIT || (mode==TRANS && next))
637+
if(mode == INIT || mode == TRANS_NEXT)
625638
{
626639
if(symbol.module==module)
627640
{
@@ -1683,28 +1696,10 @@ Function: smv_typecheckt::convert
16831696
16841697
\*******************************************************************/
16851698

1686-
void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
1699+
void smv_typecheckt::convert(exprt &expr)
16871700
{
1688-
if(expr.id() == ID_smv_next)
1689-
{
1690-
if(expr_mode!=NORMAL)
1691-
{
1692-
throw errort().with_location(expr.find_source_location())
1693-
<< "next(next(...)) encountered";
1694-
}
1695-
1696-
assert(expr.operands().size()==1);
1697-
1698-
exprt tmp;
1699-
tmp.swap(to_unary_expr(expr).op());
1700-
expr.swap(tmp);
1701-
1702-
convert(expr, NEXT);
1703-
return;
1704-
}
1705-
17061701
for(auto &op : expr.operands())
1707-
convert(op, expr_mode);
1702+
convert(op);
17081703

17091704
if(expr.id()==ID_symbol)
17101705
{
@@ -1716,9 +1711,6 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
17161711
std::string id = module + "::var::" + identifier;
17171712

17181713
expr.set(ID_identifier, id);
1719-
1720-
if(expr_mode == NEXT)
1721-
expr.id(ID_next_symbol);
17221714
}
17231715
else if(expr.id()=="smv_nondet_choice" ||
17241716
expr.id()=="smv_union")
@@ -1898,7 +1890,7 @@ Function: smv_typecheckt::convert
18981890
void smv_typecheckt::convert(
18991891
smv_parse_treet::modulet::itemt &item)
19001892
{
1901-
convert(item.expr, NORMAL);
1893+
convert(item.expr);
19021894
}
19031895

19041896
/*******************************************************************\

0 commit comments

Comments
 (0)