Skip to content

Commit 2d865b2

Browse files
committed
SMV: enums are global
SMV's enum name space is global, i.e., crosses modules. There is now only one global set of enums.
1 parent c5ef5a1 commit 2d865b2

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE broken-smt-backend
22
module_with_enum1.smv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
The enum literal is not found.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
module_with_enum2.smv
3+
4+
^file .* line 11: enum a already declared, at file .* line 7$
5+
^EXIT=2$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
MODULE main
2+
3+
VAR sub : my-module;
4+
5+
-- There is an enum in another module with the same identifier,
6+
-- which is an error!
7+
VAR a : boolean;
8+
9+
MODULE my-module
10+
11+
VAR some_enum : { a, b };
12+
13+
ASSIGN some_enum := a;

src/smvlang/parser.y

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ enum_list : enum_element
664664
enum_element: IDENTIFIER_Token
665665
{
666666
$$=$1;
667-
PARSER.module->enum_set.insert(stack_expr($1).id_string());
667+
PARSER.parse_tree.enum_set.insert(stack_expr($1).id_string());
668668
PARSER.module->add_enum(
669669
smv_identifier_exprt{stack_expr($1).id(), PARSER.source_location()});
670670
}
@@ -907,6 +907,7 @@ identifier : IDENTIFIER_Token
907907

908908
variable_identifier: complex_identifier
909909
{
910+
// Could be a variable, or an enum
910911
auto id = merge_complex_identifier(stack_expr($1));
911912
init($$, ID_smv_identifier);
912913
stack_expr($$).set(ID_identifier, id);

src/smvlang/smv_parse_tree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void smv_parse_treet::swap(smv_parse_treet &smv_parse_tree)
3030
{
3131
smv_parse_tree.module_list.swap(module_list);
3232
smv_parse_tree.module_map.swap(module_map);
33+
smv_parse_tree.enum_set.swap(enum_set);
3334
}
3435

3536
/*******************************************************************\

src/smvlang/smv_parse_tree.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ class smv_parse_treet
291291
elements.emplace_back(
292292
elementt::ENUM, std::move(expr), std::move(location));
293293
}
294-
295-
enum_sett enum_set;
296294
};
297295

298296
using module_listt = std::list<modulet>;
@@ -302,7 +300,10 @@ class smv_parse_treet
302300
std::unordered_map<irep_idt, module_listt::iterator, irep_id_hash>;
303301
module_mapt module_map;
304302

305-
void swap(smv_parse_treet &smv_parse_tree);
303+
// enums are global
304+
enum_sett enum_set;
305+
306+
void swap(smv_parse_treet &);
306307
void clear();
307308

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

src/smvlang/smv_typecheck.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,25 @@ void smv_typecheckt::instantiate(
277277
auto copy = src_element;
278278

279279
// replace the parameter identifiers,
280-
// and add the prefix to non-parameter identifiers
280+
// and add the prefix to non-parameter, non-enum identifiers
281281
copy.expr.visit_post(
282-
[&parameter_map, &prefix](exprt &expr)
282+
[&parameter_map, &prefix, this](exprt &expr)
283283
{
284284
if(expr.id() == ID_smv_identifier)
285285
{
286286
auto identifier = to_smv_identifier_expr(expr).identifier();
287287
auto parameter_it = parameter_map.find(identifier);
288288
if(parameter_it != parameter_map.end())
289289
{
290+
// It's a parameter
290291
expr = parameter_it->second;
291292
}
293+
else if(
294+
smv_parse_tree.enum_set.find(identifier) !=
295+
smv_parse_tree.enum_set.end())
296+
{
297+
// It's an enum, leave as is
298+
}
292299
else
293300
{
294301
// add the prefix
@@ -1774,7 +1781,8 @@ void smv_typecheckt::convert(exprt &expr)
17741781
identifier.find("::") == std::string::npos, "conversion is done once");
17751782

17761783
// enum or variable?
1777-
if(modulep->enum_set.find(identifier) == modulep->enum_set.end())
1784+
if(
1785+
smv_parse_tree.enum_set.find(identifier) == smv_parse_tree.enum_set.end())
17781786
{
17791787
std::string id = module + "::var::" + identifier;
17801788

0 commit comments

Comments
 (0)