Skip to content

Commit b53d468

Browse files
committed
SMV: move conversion of . and [...] to type checker
This moves the conversion of the . (dot) and [...] index operators from the SMV parser to the type checker, to enable array index and bit extract operators.
1 parent 4e11cbc commit b53d468

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/smvlang/parser.y

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static smv_parse_treet::modulet &new_module(YYSTYPE &module_name)
341341
%left TIMES_Token DIVIDE_Token
342342
%left COLONCOLON_Token
343343
%left UMINUS /* supplies precedence for unary minus */
344-
%left DOT_Token
344+
%left DOT_Token '['
345345

346346
%%
347347

@@ -820,6 +820,12 @@ constant : NUMBER_Token { init($$, ID_constant); stack_expr($$).se
820820

821821
basic_expr : constant
822822
| variable_identifier
823+
| basic_expr DOT_Token IDENTIFIER_Token
824+
{
825+
// This rule is part of "complex_identifier" in the NuSMV manual.
826+
unary($$, ID_member, $1);
827+
stack_expr($$).set(ID_component_name, stack_expr($3).id());
828+
}
823829
| '(' formula ')' { $$=$2; }
824830
| NOT_Token basic_expr { init($$, ID_not); mto($$, $2); }
825831
| "abs" '(' basic_expr ')' { unary($$, ID_smv_abs, $3); }
@@ -845,6 +851,9 @@ basic_expr : constant
845851
| basic_expr mod_Token basic_expr { binary($$, $1, ID_mod, $3); }
846852
| basic_expr GTGT_Token basic_expr { binary($$, $1, ID_shr, $3); }
847853
| basic_expr LTLT_Token basic_expr { binary($$, $1, ID_shl, $3); }
854+
| basic_expr '[' basic_expr ']' { binary($$, $1, ID_index, $3); }
855+
| basic_expr '[' basic_expr ':' basic_expr ']'
856+
{ init($$, ID_extractbits); mto($$, $1); mto($$, $3); mto($$, $5); }
848857
| basic_expr COLONCOLON_Token basic_expr { binary($$, $1, ID_concatenation, $3); }
849858
| "word1" '(' basic_expr ')' { unary($$, ID_smv_word1, $3); }
850859
| "bool" '(' basic_expr ')' { unary($$, ID_smv_bool, $3); }
@@ -973,6 +982,7 @@ complex_identifier:
973982
stack_expr($$).id(ID_smv_identifier);
974983
stack_expr($$).set(ID_identifier, identifier);
975984
}
985+
/*
976986
| complex_identifier DOT_Token QIDENTIFIER_Token
977987
{
978988
unary($$, ID_member, $1);
@@ -993,6 +1003,7 @@ complex_identifier:
9931003
// Not in the NuSMV grammar.
9941004
binary($$, $1, ID_index, $3);
9951005
}
1006+
*/
9961007
;
9971008

9981009
cases :

src/smvlang/smv_typecheck.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,32 @@ void smv_typecheckt::convert(exprt &expr)
17241724
expr.remove(ID_identifier);
17251725
}
17261726
}
1727+
else if(expr.id() == ID_member)
1728+
{
1729+
auto &member_expr = to_member_expr(expr);
1730+
if(member_expr.compound().id() != ID_smv_identifier)
1731+
DATA_INVARIANT_WITH_DIAGNOSTICS(
1732+
false, "unexpected complex_identifier", expr.pretty());
1733+
1734+
auto tmp = to_smv_identifier_expr(member_expr.compound());
1735+
tmp.identifier(
1736+
id2string(tmp.identifier()) + '.' +
1737+
id2string(member_expr.get_component_name()));
1738+
expr = tmp;
1739+
}
1740+
else if(expr.id() == ID_index)
1741+
{
1742+
auto &index_expr = to_index_expr(expr);
1743+
if(index_expr.array().id() != ID_smv_identifier)
1744+
DATA_INVARIANT_WITH_DIAGNOSTICS(
1745+
false, "unexpected complex_identifier", expr.pretty());
1746+
auto &index = index_expr.index();
1747+
PRECONDITION(index.is_constant());
1748+
auto index_string = id2string(to_constant_expr(index).get_value());
1749+
auto tmp = to_smv_identifier_expr(index_expr.array());
1750+
tmp.identifier(id2string(tmp.identifier()) + '.' + index_string);
1751+
expr = tmp;
1752+
}
17271753
else if(expr.id()=="smv_nondet_choice" ||
17281754
expr.id()=="smv_union")
17291755
{

0 commit comments

Comments
 (0)