@@ -79,6 +79,8 @@ class smv_typecheckt:public typecheckt
79
79
bool do_spec;
80
80
81
81
smv_ranget convert_type (const typet &);
82
+ static bool is_contained_in (irep_idt, const enumeration_typet &);
83
+
82
84
void convert (smv_parse_treet::modulet::itemt &);
83
85
void typecheck (smv_parse_treet::modulet::itemt &);
84
86
void typecheck_expr_rec (exprt &, const typet &, modet);
@@ -137,6 +139,26 @@ class smv_typecheckt:public typecheckt
137
139
138
140
/* ******************************************************************\
139
141
142
+ Function: smv_typecheckt::is_contained_in
143
+
144
+ Inputs:
145
+
146
+ Outputs:
147
+
148
+ Purpose:
149
+
150
+ \*******************************************************************/
151
+
152
+ bool smv_typecheckt::is_contained_in (irep_idt id, const enumeration_typet &type)
153
+ {
154
+ for (auto &element : type.elements ())
155
+ if (element.id () == id)
156
+ return true ;
157
+ return false ;
158
+ }
159
+
160
+ /* ******************************************************************\
161
+
140
162
Function: smv_typecheckt::convert_ports
141
163
142
164
Inputs:
@@ -749,10 +771,11 @@ void smv_typecheckt::typecheck_expr_rec(
749
771
}
750
772
else if (expr.id ()==ID_constant)
751
773
{
774
+ const auto value = to_constant_expr (expr).get_value ();
775
+
752
776
if (expr.type ().id ()==ID_integer)
753
777
{
754
- const std::string &value=expr.get_string (ID_value);
755
- mp_integer int_value=string2integer (value);
778
+ mp_integer int_value = string2integer (id2string (value));
756
779
757
780
if (dest_type.is_nil ())
758
781
{
@@ -796,6 +819,12 @@ void smv_typecheckt::typecheck_expr_rec(
796
819
{
797
820
if (dest_type.id () == ID_enumeration)
798
821
{
822
+ if (!is_contained_in (value, to_enumeration_type (dest_type)))
823
+ {
824
+ throw errort ().with_location (expr.find_source_location ())
825
+ << " enum " << value << " not a member of " << to_string (dest_type);
826
+ }
827
+
799
828
if (to_enumeration_type (expr.type ()).elements ().empty ())
800
829
expr.type () = dest_type;
801
830
}
0 commit comments