Skip to content

Commit caeaab7

Browse files
committed
introduce SMV enumeration type
SMV enumerations behave differently from enumeration_typet; hence, this introduces smv_enumeration_typet, which is subsequently lowered to enumeration_typet.
1 parent a93aa31 commit caeaab7

File tree

9 files changed

+268
-112
lines changed

9 files changed

+268
-112
lines changed

regression/smv/enums/enum3.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
enum3.smv
33

4-
^file .* line 7: enum c not a member of \{ a, b \}$
4+
^file .* line 7: Expected expression of type `\{ a, b \}', but got expression `c', which is of type `\{ c \}'$
55
^EXIT=2$
66
^SIGNAL=0$
77
--

regression/smv/enums/enum5.desc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE broken-smt-backend
22
enum5.smv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
This fails in the decision procedure.

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ IREP_ID_ONE(smv_abs)
2121
IREP_ID_ONE(smv_bitimplies)
2222
IREP_ID_ONE(smv_bool)
2323
IREP_ID_ONE(smv_count)
24+
IREP_ID_ONE(smv_enumeration)
2425
IREP_ID_ONE(smv_extend)
2526
IREP_ID_ONE(smv_max)
2627
IREP_ID_ONE(smv_min)

src/smvlang/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SRC = smv_expr.cpp \
22
smv_language.cpp \
33
smv_parser.cpp \
44
smv_typecheck.cpp \
5+
smv_types.cpp \
56
expr2smv.cpp \
67
smv_y.tab.cpp \
78
lex.yy.cpp \

src/smvlang/expr2smv.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include <util/mathematical_types.h>
1313

1414
#include "smv_expr.h"
15+
#include "smv_types.h"
1516

1617
/*******************************************************************\
1718
@@ -337,6 +338,12 @@ expr2smvt::resultt expr2smvt::convert_typecast(const typecast_exprt &expr)
337338
return convert_rec(smv_resize_exprt{expr.op(), dest_width, dest_type});
338339
}
339340
}
341+
else if(
342+
src_type.id() == ID_smv_enumeration && dest_type.id() == ID_smv_enumeration)
343+
{
344+
// added by SMV typechecker, implicit
345+
return convert_rec(expr.op());
346+
}
340347
else
341348
return convert_norep(expr);
342349
}
@@ -593,10 +600,9 @@ expr2smvt::resultt expr2smvt::convert_constant(const constant_exprt &src)
593600
else
594601
dest+="FALSE";
595602
}
596-
else if(type.id()==ID_integer ||
597-
type.id()==ID_natural ||
598-
type.id()==ID_range ||
599-
type.id()==ID_enumeration)
603+
else if(
604+
type.id() == ID_integer || type.id() == ID_natural ||
605+
type.id() == ID_range || type.id() == ID_smv_enumeration)
600606
{
601607
dest = id2string(src.get_value());
602608
}
@@ -903,15 +909,15 @@ std::string type2smv(const typet &type, const namespacet &ns)
903909
code += type2smv(to_array_type(type).element_type(), ns);
904910
return code;
905911
}
906-
else if(type.id()==ID_enumeration)
912+
else if(type.id() == ID_smv_enumeration)
907913
{
908-
const irept::subt &elements=to_enumeration_type(type).elements();
914+
auto elements = to_smv_enumeration_type(type).elements();
909915
std::string code = "{ ";
910916
bool first=true;
911917
for(auto &element : elements)
912918
{
913919
if(first) first=false; else code+=", ";
914-
code += element.id_string();
920+
code += id2string(element);
915921
}
916922
code+=" }";
917923
return code;

src/smvlang/parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ parameter_list:
642642

643643
enum_list : enum_element
644644
{
645-
init($$, ID_enumeration);
645+
init($$, ID_smv_enumeration);
646646
stack_expr($$).add(ID_elements).get_sub().push_back(irept(stack_expr($1).id()));
647647
}
648648
| enum_list ',' enum_element
@@ -946,7 +946,7 @@ variable_identifier: complex_identifier
946946
else if(is_enum)
947947
{
948948
init($$, ID_constant);
949-
stack_expr($$).type()=typet(ID_enumeration);
949+
stack_expr($$).type()=typet(ID_smv_enumeration);
950950
stack_expr($$).set(ID_value, id);
951951
}
952952
else // not an enum, probably a variable

0 commit comments

Comments
 (0)