@@ -378,21 +378,27 @@ std::string expr2ct::convert_rec(
378378
379379 if (!to_c_enum_type (src).is_incomplete ())
380380 {
381+ const c_enum_typet &c_enum_type = to_c_enum_type (src);
382+ const bool is_signed = c_enum_type.subtype ().id () == ID_signedbv;
383+ const auto width = to_bitvector_type (c_enum_type.subtype ()).get_width ();
384+
381385 result += ' {' ;
382386
383387 // add members
384- const c_enum_typet::memberst &members = to_c_enum_type (src) .members ();
388+ const c_enum_typet::memberst &members = c_enum_type .members ();
385389
386390 for (c_enum_typet::memberst::const_iterator it = members.begin ();
387391 it != members.end ();
388392 it++)
389393 {
394+ mp_integer int_value = bvrep2integer (it->get_value (), width, is_signed);
395+
390396 if (it != members.begin ())
391397 result += ' ,' ;
392398 result += ' ' ;
393399 result += id2string (it->get_base_name ());
394400 result += ' =' ;
395- result += id2string (it-> get_value () );
401+ result += integer2string (int_value );
396402 }
397403
398404 result += " }" ;
@@ -1703,24 +1709,21 @@ std::string expr2ct::convert_constant(
17031709 if (c_enum_type.id ()!=ID_c_enum)
17041710 return convert_norep (src, precedence);
17051711
1706- const bool is_signed = c_enum_type.subtype ().id () == ID_signedbv;
1707- const auto width = to_bitvector_type (c_enum_type.subtype ()).get_width ();
1708-
1709- mp_integer int_value = bvrep2integer (value, width, is_signed);
1710- mp_integer i=0 ;
1711-
1712- irep_idt int_value_string=integer2string (int_value);
1713-
17141712 const c_enum_typet::memberst &members=
17151713 to_c_enum_type (c_enum_type).members ();
17161714
17171715 for (const auto &member : members)
17181716 {
1719- if (member.get_value () == int_value_string )
1717+ if (member.get_value () == value )
17201718 return " /*enum*/" + id2string (member.get_base_name ());
17211719 }
17221720
17231721 // failed...
1722+ const bool is_signed = c_enum_type.subtype ().id () == ID_signedbv;
1723+ const auto width = to_bitvector_type (c_enum_type.subtype ()).get_width ();
1724+
1725+ mp_integer int_value = bvrep2integer (value, width, is_signed);
1726+
17241727 return " /*enum*/" +integer2string (int_value);
17251728 }
17261729 else if (type.id ()==ID_rational)
0 commit comments