Skip to content

Commit 4c66528

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 081b322 commit 4c66528

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
@@ -1162,46 +1162,60 @@ Function: smv_typecheckt::typecheck
11621162
void smv_typecheckt::typecheck(
11631163
smv_parse_treet::modulet::itemt &item)
11641164
{
1165-
modet mode;
1166-
11671165
switch(item.item_type)
11681166
{
11691167
case smv_parse_treet::modulet::itemt::ASSIGN_CURRENT:
1170-
mode = OTHER;
1168+
{
1169+
auto &equal_expr = item.equal_expr();
1170+
auto &symbol_expr = to_symbol_expr(equal_expr.lhs());
1171+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1172+
typecheck(symbol_expr, nil_type, OTHER);
1173+
typecheck(equal_expr.rhs(), symbol_expr.type(), OTHER);
1174+
}
11711175
break;
11721176

11731177
case smv_parse_treet::modulet::itemt::ASSIGN_INIT:
1174-
mode = INIT;
1178+
{
1179+
auto &equal_expr = item.equal_expr();
1180+
auto &symbol_expr = to_symbol_expr(to_unary_expr(equal_expr.lhs()).op());
1181+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1182+
typecheck(symbol_expr, nil_type, OTHER);
1183+
typecheck(equal_expr.rhs(), symbol_expr.type(), INIT);
1184+
}
11751185
break;
11761186

11771187
case smv_parse_treet::modulet::itemt::ASSIGN_NEXT:
1178-
mode = TRANS;
1188+
{
1189+
auto &equal_expr = item.equal_expr();
1190+
auto &symbol_expr = to_symbol_expr(to_unary_expr(equal_expr.lhs()).op());
1191+
auto &nil_type = static_cast<const typet &>(get_nil_irep());
1192+
typecheck(symbol_expr, nil_type, OTHER);
1193+
typecheck(equal_expr.rhs(), symbol_expr.type(), TRANS);
1194+
}
11791195
break;
11801196

11811197
case smv_parse_treet::modulet::itemt::INIT:
1182-
mode=INIT;
1198+
typecheck(item.expr, bool_typet(), INIT);
11831199
break;
11841200

11851201
case smv_parse_treet::modulet::itemt::TRANS:
1186-
mode=TRANS;
1202+
typecheck(item.expr, bool_typet(), TRANS);
11871203
break;
11881204

11891205
case smv_parse_treet::modulet::itemt::CTLSPEC:
1190-
mode = CTL;
1206+
typecheck(item.expr, bool_typet(), CTL);
11911207
break;
11921208

11931209
case smv_parse_treet::modulet::itemt::LTLSPEC:
1194-
mode = LTL;
1210+
typecheck(item.expr, bool_typet(), LTL);
11951211
break;
11961212

11971213
case smv_parse_treet::modulet::itemt::DEFINE:
11981214
case smv_parse_treet::modulet::itemt::INVAR:
11991215
case smv_parse_treet::modulet::itemt::FAIRNESS:
12001216
default:
1201-
mode=OTHER;
1217+
typecheck(item.expr, bool_typet(), OTHER);
12021218
}
1203-
1204-
typecheck(item.expr, bool_typet(), mode);
12051219
}
12061220

12071221
/*******************************************************************\

0 commit comments

Comments
 (0)