@@ -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:
@@ -755,10 +777,11 @@ void smv_typecheckt::typecheck_expr_rec(
755
777
}
756
778
else if (expr.id ()==ID_constant)
757
779
{
780
+ const auto value = to_constant_expr (expr).get_value ();
781
+
758
782
if (expr.type ().id ()==ID_integer)
759
783
{
760
- const std::string &value=expr.get_string (ID_value);
761
- mp_integer int_value=string2integer (value);
784
+ mp_integer int_value = string2integer (id2string (value));
762
785
763
786
if (dest_type.is_nil ())
764
787
{
@@ -804,6 +827,12 @@ void smv_typecheckt::typecheck_expr_rec(
804
827
{
805
828
if (dest_type.id () == ID_enumeration)
806
829
{
830
+ if (!is_contained_in (value, to_enumeration_type (dest_type)))
831
+ {
832
+ throw errort ().with_location (expr.find_source_location ())
833
+ << " enum " << value << " not a member of " << to_string (dest_type);
834
+ }
835
+
807
836
if (to_enumeration_type (expr.type ()).elements ().empty ())
808
837
expr.type () = dest_type;
809
838
}
0 commit comments