Skip to content

Commit 1a426db

Browse files
committed
SMV: enums are global
SMV's enum name space is global, i.e., crosses modules. This moves the resolution of identifier to variables or enums from the parser to the typechecking phase.
1 parent e31efbf commit 1a426db

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ IREP_ID_ONE(smv_extend)
2626
IREP_ID_ONE(smv_max)
2727
IREP_ID_ONE(smv_min)
2828
IREP_ID_ONE(smv_next)
29+
IREP_ID_ONE(smv_identifier)
2930
IREP_ID_ONE(smv_iff)
3031
IREP_ID_TWO(C_smv_iff, "#smv_iff")
3132
IREP_ID_ONE(smv_resize)

src/smvlang/parser.y

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ enum_list : enum_element
675675
enum_element: IDENTIFIER_Token
676676
{
677677
$$=$1;
678-
PARSER.module->enum_set.insert(stack_expr($1).id_string());
678+
PARSER.parse_tree.enum_set.insert(stack_expr($1).id_string());
679679

680680
exprt expr(ID_symbol);
681681
expr.set(ID_identifier, stack_expr($1).id());
@@ -950,33 +950,10 @@ identifier : IDENTIFIER_Token
950950

951951
variable_identifier: complex_identifier
952952
{
953+
// Could be a variable, or an enum
953954
auto id = merge_complex_identifier(stack_expr($1));
954-
955-
bool is_enum=(PARSER.module->enum_set.find(id)!=
956-
PARSER.module->enum_set.end());
957-
bool is_var=(PARSER.module->vars.find(id)!=
958-
PARSER.module->vars.end());
959-
960-
if(is_var && is_enum)
961-
{
962-
yyerror("identifier `"+id2string(id)+"' is ambiguous");
963-
YYERROR;
964-
}
965-
else if(is_enum)
966-
{
967-
init($$, ID_constant);
968-
stack_expr($$).type()=typet(ID_smv_enumeration);
969-
stack_expr($$).set(ID_value, id);
970-
}
971-
else // not an enum, probably a variable
972-
{
973-
init($$, ID_symbol);
974-
stack_expr($$).set(ID_identifier, id);
975-
auto var_it = PARSER.module->vars.find(id);
976-
if(var_it!= PARSER.module->vars.end())
977-
stack_expr($$).type()=var_it->second.type;
978-
//PARSER.module->vars[stack_expr($1).id()];
979-
}
955+
init($$, ID_smv_identifier);
956+
stack_expr($$).set(ID_identifier, id);
980957
}
981958
| STRING_Token
982959
{

src/smvlang/smv_parse_tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ class smv_parse_treet
274274
}
275275

276276
mc_varst vars;
277-
enum_sett enum_set;
278277

279278
std::list<irep_idt> ports;
280279
};
280+
281+
// enums are global
282+
enum_sett enum_set;
281283

282284
typedef std::unordered_map<irep_idt, modulet, irep_id_hash> modulest;
283285

0 commit comments

Comments
 (0)