Skip to content

Commit 6564d5c

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 f14862e commit 6564d5c

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/smvlang/parser.y

Lines changed: 22 additions & 2 deletions
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

@@ -842,7 +842,26 @@ integer_constant:
842842
;
843843

844844
basic_expr : constant
845-
| variable_identifier
845+
| identifier
846+
{
847+
// This rule is part of "complex_identifier" in the NuSMV manual.
848+
$$ = $1;
849+
irep_idt identifier = stack_expr($$).id();
850+
stack_expr($$).id(ID_smv_identifier);
851+
stack_expr($$).set(ID_identifier, identifier);
852+
PARSER.set_source_location(stack_expr($$));
853+
}
854+
| basic_expr DOT_Token IDENTIFIER_Token
855+
{
856+
// This rule is part of "complex_identifier" in the NuSMV manual.
857+
unary($$, ID_member, $1);
858+
stack_expr($$).set(ID_component_name, stack_expr($3).id());
859+
}
860+
| basic_expr '(' basic_expr ')'
861+
{
862+
// Not in the NuSMV grammar.
863+
binary($$, $1, ID_index, $3);
864+
}
846865
| '(' formula ')' { $$=$2; }
847866
| NOT_Token basic_expr { init($$, ID_not); mto($$, $2); }
848867
| "abs" '(' basic_expr ')' { unary($$, ID_smv_abs, $3); }
@@ -868,6 +887,7 @@ basic_expr : constant
868887
| basic_expr mod_Token basic_expr { binary($$, $1, ID_mod, $3); }
869888
| basic_expr GTGT_Token basic_expr { binary($$, $1, ID_shr, $3); }
870889
| basic_expr LTLT_Token basic_expr { binary($$, $1, ID_shl, $3); }
890+
| basic_expr '[' basic_expr ']' { binary($$, $1, ID_index, $3); }
871891
| basic_expr COLONCOLON_Token basic_expr { binary($$, $1, ID_concatenation, $3); }
872892
| "word1" '(' basic_expr ')' { unary($$, ID_smv_word1, $3); }
873893
| "bool" '(' basic_expr ')' { unary($$, ID_smv_bool, $3); }

src/smvlang/smv_typecheck.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,34 @@ 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+
DATA_INVARIANT_WITH_DIAGNOSTICS(
1731+
member_expr.compound().id() != ID_symbol,
1732+
"unexpected complex_identifier",
1733+
expr.pretty());
1734+
1735+
auto tmp = to_symbol_expr(member_expr.compound());
1736+
tmp.set_identifier(
1737+
id2string(tmp.get_identifier()) + '.' +
1738+
id2string(member_expr.get_component_name()));
1739+
expr = tmp;
1740+
}
1741+
else if(expr.id() == ID_index)
1742+
{
1743+
auto &index_expr = to_index_expr(expr);
1744+
DATA_INVARIANT_WITH_DIAGNOSTICS(
1745+
index_expr.array().id() == ID_symbol,
1746+
"unexpected complex_identifier",
1747+
expr.pretty());
1748+
auto &index = index_expr.index();
1749+
PRECONDITION(index.is_constant());
1750+
auto index_string = id2string(to_constant_expr(index).get_value());
1751+
auto tmp = to_symbol_expr(index_expr.array());
1752+
tmp.set_identifier(id2string(tmp.get_identifier()) + '.' + index_string);
1753+
expr = tmp;
1754+
}
17271755
else if(expr.id()=="smv_nondet_choice" ||
17281756
expr.id()=="smv_union")
17291757
{

0 commit comments

Comments
 (0)