Skip to content

Commit 2622669

Browse files
committed
SMV: add lhs() and rhs() helper methods
This adds lhs() and rhs() helper methods to the SMV parse tree node class.
1 parent 618dd08 commit 2622669

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

src/smvlang/smv_parse_tree.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,37 @@ class smv_parse_treet
142142
}
143143

144144
// for ASSIGN_CURRENT, ASSIGN_INIT, ASSIGN_NEXT, DEFINE
145-
const equal_exprt &equal_expr() const
145+
const exprt &lhs() const
146146
{
147147
PRECONDITION(
148148
is_assign_current() || is_assign_init() || is_assign_next() ||
149149
is_define());
150-
return to_equal_expr(expr);
150+
return to_equal_expr(expr).lhs();
151151
}
152152

153-
equal_exprt &equal_expr()
153+
exprt &lhs()
154154
{
155155
PRECONDITION(
156156
is_assign_current() || is_assign_init() || is_assign_next() ||
157157
is_define());
158-
return to_equal_expr(expr);
158+
return to_equal_expr(expr).lhs();
159+
}
160+
161+
// for ASSIGN_CURRENT, ASSIGN_INIT, ASSIGN_NEXT, DEFINE
162+
const exprt &rhs() const
163+
{
164+
PRECONDITION(
165+
is_assign_current() || is_assign_init() || is_assign_next() ||
166+
is_define());
167+
return to_equal_expr(expr).rhs();
168+
}
169+
170+
exprt &rhs()
171+
{
172+
PRECONDITION(
173+
is_assign_current() || is_assign_init() || is_assign_next() ||
174+
is_define());
175+
return to_equal_expr(expr).rhs();
159176
}
160177

161178
void show(std::ostream &) const;

src/smvlang/smv_typecheck.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class smv_typecheckt:public typecheckt
6262

6363
void create_var_symbols(const smv_parse_treet::modulet::element_listt &);
6464

65-
void collect_define(const equal_exprt &);
65+
void collect_define(const exprt &lhs, const exprt &rhs);
6666
void convert_defines(exprt::operandst &invar);
6767
void convert_define(const irep_idt &identifier);
6868

@@ -1966,33 +1966,30 @@ void smv_typecheckt::typecheck(smv_parse_treet::modulet::elementt &element)
19661966
return;
19671967

19681968
case smv_parse_treet::modulet::elementt::ASSIGN_CURRENT:
1969-
typecheck(element.equal_expr().lhs(), OTHER);
1970-
typecheck(element.equal_expr().rhs(), OTHER);
1971-
convert_expr_to(
1972-
element.equal_expr().rhs(), element.equal_expr().lhs().type());
1973-
element.equal_expr().type() = bool_typet{};
1969+
typecheck(element.lhs(), OTHER);
1970+
typecheck(element.rhs(), OTHER);
1971+
convert_expr_to(element.rhs(), element.lhs().type());
1972+
element.expr.type() = bool_typet{};
19741973
return;
19751974

19761975
case smv_parse_treet::modulet::elementt::ASSIGN_INIT:
1977-
typecheck(element.equal_expr().lhs(), INIT);
1978-
typecheck(element.equal_expr().rhs(), INIT);
1979-
convert_expr_to(
1980-
element.equal_expr().rhs(), element.equal_expr().lhs().type());
1981-
element.equal_expr().type() = bool_typet{};
1982-
no_next_allowed(element.equal_expr().rhs());
1976+
typecheck(element.lhs(), INIT);
1977+
typecheck(element.rhs(), INIT);
1978+
convert_expr_to(element.rhs(), element.lhs().type());
1979+
no_next_allowed(element.rhs());
1980+
element.expr.type() = bool_typet{};
19831981
return;
19841982

19851983
case smv_parse_treet::modulet::elementt::ASSIGN_NEXT:
1986-
typecheck(element.equal_expr().lhs(), TRANS);
1987-
typecheck(element.equal_expr().rhs(), TRANS);
1988-
convert_expr_to(
1989-
element.equal_expr().rhs(), element.equal_expr().lhs().type());
1990-
element.equal_expr().type() = bool_typet{};
1984+
typecheck(element.lhs(), TRANS);
1985+
typecheck(element.rhs(), TRANS);
1986+
convert_expr_to(element.rhs(), element.lhs().type());
1987+
element.expr.type() = bool_typet{};
19911988
return;
19921989

19931990
case smv_parse_treet::modulet::elementt::DEFINE:
19941991
typecheck(element.expr, OTHER);
1995-
element.equal_expr().type() = bool_typet{};
1992+
element.expr.type() = bool_typet{};
19961993
return;
19971994

19981995
case smv_parse_treet::modulet::elementt::ENUM:
@@ -2077,8 +2074,7 @@ void smv_typecheckt::variable_checks(const smv_parse_treet::modulet &module)
20772074
}
20782075
else if(element.is_define())
20792076
{
2080-
const auto &identifier_expr =
2081-
to_smv_identifier_expr(to_equal_expr(element.expr).lhs());
2077+
const auto &identifier_expr = to_smv_identifier_expr(element.lhs());
20822078
irep_idt base_name = identifier_expr.identifier();
20832079

20842080
// already used as enum?
@@ -2202,8 +2198,7 @@ void smv_typecheckt::create_var_symbols(
22022198
}
22032199
else if(element.is_define())
22042200
{
2205-
const auto &identifier_expr =
2206-
to_smv_identifier_expr(to_equal_expr(element.expr).lhs());
2201+
const auto &identifier_expr = to_smv_identifier_expr(element.lhs());
22072202
irep_idt base_name = identifier_expr.identifier();
22082203
irep_idt identifier = module + "::var::" + id2string(base_name);
22092204

@@ -2264,11 +2259,8 @@ Function: smv_typecheckt::collect_define
22642259
22652260
\*******************************************************************/
22662261

2267-
void smv_typecheckt::collect_define(const equal_exprt &expr)
2262+
void smv_typecheckt::collect_define(const exprt &lhs, const exprt &rhs)
22682263
{
2269-
const exprt &lhs = expr.lhs();
2270-
const exprt &rhs = expr.rhs();
2271-
22722264
if(lhs.id() != ID_symbol)
22732265
throw errort() << "collect_define expects symbol on left hand side";
22742266

@@ -2294,9 +2286,9 @@ void smv_typecheckt::collect_define(const equal_exprt &expr)
22942286

22952287
if(!result.second)
22962288
{
2297-
throw errort().with_location(expr.find_source_location())
2289+
throw errort().with_location(lhs.source_location())
22982290
<< "variable `" << symbol.display_name() << "' already defined";
2299-
}
2291+
}
23002292
}
23012293

23022294
/*******************************************************************\
@@ -2475,7 +2467,7 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
24752467
for(auto &element : smv_module.elements)
24762468
{
24772469
if(element.is_define() || element.is_assign_current())
2478-
collect_define(element.equal_expr());
2470+
collect_define(element.lhs(), element.rhs());
24792471
}
24802472
// now turn them into INVARs
24812473
convert_defines(trans_invar);

0 commit comments

Comments
 (0)