Skip to content

Commit aba22a5

Browse files
committed
SMV: set type
This fixes typechecking for set literals, assignments from set literals to variables of the element type, and typechecking for the "in" set membership operator.
1 parent b0016ca commit aba22a5

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ IREP_ID_ONE(smv_next)
2323
IREP_ID_ONE(smv_iff)
2424
IREP_ID_TWO(C_smv_iff, "#smv_iff")
2525
IREP_ID_ONE(smv_resize)
26+
IREP_ID_ONE(smv_set)
2627
IREP_ID_ONE(smv_setin)
2728
IREP_ID_ONE(smv_setnotin)
2829
IREP_ID_ONE(smv_signed_cast)

src/smvlang/expr2smv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ std::string type2smv(const typet &type, const namespacet &ns)
902902
{
903903
return type.get_string(ID_from) + ".." + type.get_string(ID_to);
904904
}
905+
else if(type.id() == ID_smv_set)
906+
{
907+
return "set";
908+
}
905909
else if(type.id()=="submodule")
906910
{
907911
auto code = type.get_string(ID_identifier);

src/smvlang/parser.y

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static void new_module(YYSTYPE &module)
176176
%token LTLWFF_Token "LTLWFF"
177177
%token PSLWFF_Token "PSLWFF"
178178
%token COMPWFF_Token "COMPWFF"
179-
%token IN_Token "IN"
180179
%token MIN_Token "MIN"
181180
%token MAX_Token "MAX"
182181
%token MIRROR_Token "MIRROR"
@@ -289,7 +288,7 @@ static void new_module(YYSTYPE &module)
289288
%left EX_Token AX_Token EF_Token AF_Token EG_Token AG_Token E_Token A_Token U_Token R_Token V_Token F_Token G_Token H_Token O_Token S_Token T_Token X_Token Y_Token Z_Token EBF_Token ABF_Token EBG_Token ABG_Token
290289
%left EQUAL_Token NOTEQUAL_Token LT_Token GT_Token LE_Token GE_Token
291290
%left union_Token
292-
%left IN_Token NOTIN_Token
291+
%left in_Token
293292
%left mod_Token /* Precedence from CMU SMV, different from NuSMV */
294293
%left LTLT_Token GTGT_Token
295294
%left PLUS_Token MINUS_Token
@@ -673,7 +672,7 @@ formula : term
673672
term : variable_identifier
674673
| next_Token '(' term ')' { init($$, ID_smv_next); mto($$, $3); }
675674
| '(' formula ')' { $$=$2; }
676-
| '{' formula_list '}' { $$=$2; stack_expr($$).id("smv_nondet_choice"); }
675+
| '{' formula_list '}' { $$=$2; stack_expr($$).id(ID_smv_set); }
677676
| INC_Token '(' term ')' { init($$, "inc"); mto($$, $3); }
678677
| DEC_Token '(' term ')' { init($$, "dec"); mto($$, $3); }
679678
| ADD_Token '(' term ',' term ')' { j_binary($$, $3, ID_plus, $5); }
@@ -709,8 +708,7 @@ term : variable_identifier
709708
| term GT_Token term { binary($$, $1, ID_gt, $3); }
710709
| term GE_Token term { binary($$, $1, ID_ge, $3); }
711710
| term union_Token term { binary($$, $1, ID_smv_union, $3); }
712-
| term IN_Token term { binary($$, $1, ID_smv_setin, $3); }
713-
| term NOTIN_Token term { binary($$, $1, ID_smv_setnotin, $3); }
711+
| term in_Token term { binary($$, $1, ID_smv_setin, $3); }
714712
| extend_Token '(' term ',' term ')' { binary($$, $3, ID_smv_extend, $5); }
715713
| resize_Token '(' term ',' term ')' { binary($$, $3, ID_smv_resize, $5); }
716714
| signed_Token '(' term ')' { init($$, ID_smv_signed_cast); mto($$, $3); }

src/smvlang/scanner.l

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void newlocation(YYSTYPE &x)
101101
"LTLWFF" token(LTLWFF_Token);
102102
"PSLWFF" token(PSLWFF_Token);
103103
"COMPWFF" token(COMPWFF_Token);
104-
"IN" token(IN_Token);
105104
"MIN" token(MIN_Token);
106105
"MAX" token(MAX_Token);
107106
"MIRROR" token(MIRROR_Token);

src/smvlang/smv_typecheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,11 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
12321232
<< "signed operand must have unsigned word type";
12331233
}
12341234
}
1235+
else if(expr.id() == ID_smv_set)
1236+
{
1237+
// a set literal
1238+
expr.type() = typet{ID_smv_set};
1239+
}
12351240
else
12361241
{
12371242
throw errort().with_location(expr.find_source_location())

0 commit comments

Comments
 (0)