Skip to content

Commit 741e1ea

Browse files
committed
SMV: clean up parse tree
This replaces the mechanism used for parsing an SMV expression. Assignments are now stored explicitly in the parse tree.
1 parent 8b88a47 commit 741e1ea

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/hw_cbmc_irep_ids.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ IREP_ID_ONE(F)
1717
IREP_ID_ONE(E)
1818
IREP_ID_ONE(G)
1919
IREP_ID_ONE(X)
20-
IREP_ID_ONE(smv_next)
2120
IREP_ID_ONE(smv_iff)
21+
IREP_ID_ONE(smv_assign_current)
22+
IREP_ID_ONE(smv_assign_init)
23+
IREP_ID_ONE(smv_assign_next)
24+
IREP_ID_ONE(smv_next)
2225
IREP_ID_TWO(C_smv_iff, "#smv_iff")
2326
IREP_ID_ONE(smv_setin)
2427
IREP_ID_ONE(smv_setnotin)

src/smvlang/parser.y

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ assignment : assignment_head '(' assignment_var ')' BECOMES_Token formula ';'
468468
assignment_var: variable_name
469469
;
470470

471-
assignment_head: init_Token { init($$, ID_init); }
472-
| NEXT_Token { init($$, ID_smv_next); }
471+
assignment_head: init_Token { init($$, ID_smv_assign_init); }
472+
| NEXT_Token { init($$, ID_smv_assign_next); }
473473
;
474474

475475
defines: define

src/smvlang/smv_parse_tree.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class smv_parse_treet
106106
}
107107

108108
// for ASSIGN_CURRENT, ASSIGN_INIT, ASSIGN_NEXT, DEFINE
109-
const equal_exprt &equal_expr()
109+
equal_exprt &equal_expr()
110110
{
111111
PRECONDITION(
112112
is_assign_current() || is_assign_init() || is_assign_next() ||
@@ -223,7 +223,7 @@ class smv_parse_treet
223223
typedef std::unordered_map<irep_idt, modulet, irep_id_hash> modulest;
224224

225225
modulest modules;
226-
226+
227227
void swap(smv_parse_treet &smv_parse_tree);
228228
void clear();
229229
};

src/smvlang/smv_typecheck.cpp

+26-12
Original file line numberDiff line numberDiff line change
@@ -1167,46 +1167,60 @@ Function: smv_typecheckt::typecheck
11671167
void smv_typecheckt::typecheck(
11681168
smv_parse_treet::modulet::itemt &item)
11691169
{
1170-
modet mode;
1171-
11721170
switch(item.item_type)
11731171
{
11741172
case smv_parse_treet::modulet::itemt::ASSIGN_CURRENT:
1175-
mode = OTHER;
1173+
{
1174+
auto &equal_expr = item.equal_expr();
1175+
auto &symbol_expr = to_symbol_expr(equal_expr.lhs());
1176+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1177+
typecheck(symbol_expr, nil_type, OTHER);
1178+
typecheck(equal_expr.rhs(), symbol_expr.type(), OTHER);
1179+
}
11761180
break;
11771181

11781182
case smv_parse_treet::modulet::itemt::ASSIGN_INIT:
1179-
mode = INIT;
1183+
{
1184+
auto &equal_expr = item.equal_expr();
1185+
auto &symbol_expr = to_symbol_expr(to_unary_expr(equal_expr.lhs()).op());
1186+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1187+
typecheck(symbol_expr, nil_type, OTHER);
1188+
typecheck(equal_expr.rhs(), symbol_expr.type(), INIT);
1189+
}
11801190
break;
11811191

11821192
case smv_parse_treet::modulet::itemt::ASSIGN_NEXT:
1183-
mode = TRANS;
1193+
{
1194+
auto &equal_expr = item.equal_expr();
1195+
auto &symbol_expr = to_symbol_expr(to_unary_expr(equal_expr.lhs()).op());
1196+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1197+
typecheck(symbol_expr, nil_type, OTHER);
1198+
typecheck(equal_expr.rhs(), symbol_expr.type(), TRANS);
1199+
}
11841200
break;
11851201

11861202
case smv_parse_treet::modulet::itemt::INIT:
1187-
mode=INIT;
1203+
typecheck(item.expr, bool_typet(), INIT);
11881204
break;
11891205

11901206
case smv_parse_treet::modulet::itemt::TRANS:
1191-
mode=TRANS;
1207+
typecheck(item.expr, bool_typet(), TRANS);
11921208
break;
11931209

11941210
case smv_parse_treet::modulet::itemt::CTLSPEC:
1195-
mode = CTL;
1211+
typecheck(item.expr, bool_typet(), CTL);
11961212
break;
11971213

11981214
case smv_parse_treet::modulet::itemt::LTLSPEC:
1199-
mode = LTL;
1215+
typecheck(item.expr, bool_typet(), LTL);
12001216
break;
12011217

12021218
case smv_parse_treet::modulet::itemt::DEFINE:
12031219
case smv_parse_treet::modulet::itemt::INVAR:
12041220
case smv_parse_treet::modulet::itemt::FAIRNESS:
12051221
default:
1206-
mode=OTHER;
1222+
typecheck(item.expr, bool_typet(), OTHER);
12071223
}
1208-
1209-
typecheck(item.expr, bool_typet(), mode);
12101224
}
12111225

12121226
/*******************************************************************\

0 commit comments

Comments
 (0)