Skip to content

Commit da965b7

Browse files
authored
Merge pull request #1374 from diffblue/smv-enum-vs-var
SMV: move logic that distinguishes enums and vars to type checker
2 parents 9dc994a + 0996885 commit da965b7

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

src/smvlang/parser.y

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -952,32 +952,8 @@ identifier : IDENTIFIER_Token
952952
variable_identifier: complex_identifier
953953
{
954954
auto id = merge_complex_identifier(stack_expr($1));
955-
956-
bool is_enum=(PARSER.module->enum_set.find(id)!=
957-
PARSER.module->enum_set.end());
958-
bool is_var=(PARSER.module->vars.find(id)!=
959-
PARSER.module->vars.end());
960-
961-
if(is_var && is_enum)
962-
{
963-
yyerror("identifier `"+id2string(id)+"' is ambiguous");
964-
YYERROR;
965-
}
966-
else if(is_enum)
967-
{
968-
init($$, ID_constant);
969-
stack_expr($$).type()=typet(ID_smv_enumeration);
970-
stack_expr($$).set(ID_value, id);
971-
}
972-
else // not an enum, probably a variable
973-
{
974-
init($$, ID_smv_identifier);
975-
stack_expr($$).set(ID_identifier, id);
976-
auto var_it = PARSER.module->vars.find(id);
977-
if(var_it!= PARSER.module->vars.end())
978-
stack_expr($$).type()=var_it->second.type;
979-
//PARSER.module->vars[stack_expr($1).id()];
980-
}
955+
init($$, ID_smv_identifier);
956+
stack_expr($$).set(ID_identifier, id);
981957
}
982958
| STRING_Token
983959
{

src/smvlang/smv_typecheck.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,10 +1708,21 @@ void smv_typecheckt::convert(exprt &expr)
17081708
DATA_INVARIANT(
17091709
identifier.find("::") == std::string::npos, "conversion is done once");
17101710

1711-
std::string id = module + "::var::" + identifier;
1711+
// enum or variable?
1712+
if(modulep->enum_set.find(identifier) == modulep->enum_set.end())
1713+
{
1714+
std::string id = module + "::var::" + identifier;
17121715

1713-
expr.set(ID_identifier, id);
1714-
expr.id(ID_symbol);
1716+
expr.set(ID_identifier, id);
1717+
expr.id(ID_symbol);
1718+
}
1719+
else
1720+
{
1721+
expr.id(ID_constant);
1722+
expr.type() = typet(ID_smv_enumeration);
1723+
expr.set(ID_value, identifier);
1724+
expr.remove(ID_identifier);
1725+
}
17151726
}
17161727
else if(expr.id()=="smv_nondet_choice" ||
17171728
expr.id()=="smv_union")

0 commit comments

Comments
 (0)