@@ -131,24 +131,34 @@ void goto_trace_stept::output(
131131// / \return a string with the numeric representation
132132static std::string numeric_representation (
133133 const constant_exprt &expr,
134+ const namespacet &ns,
134135 const trace_optionst &options)
135136{
136137 std::string result;
137138 std::string prefix;
138139
140+ const typet &expr_type = expr.type ();
141+
142+ const typet &underlying_type =
143+ expr_type.id () == ID_c_enum_tag
144+ ? ns.follow_tag (to_c_enum_tag_type (expr_type)).subtype ()
145+ : expr_type;
146+
139147 const irep_idt &value = expr.get_value ();
140148
149+ const auto width = to_bitvector_type (underlying_type).get_width ();
150+
151+ const mp_integer value_int = bvrep2integer (id2string (value), width, false );
152+
141153 if (options.hex_representation )
142154 {
143- const mp_integer value_int =
144- bvrep2integer (to_constant_expr (expr).get_value (), value.size (), false );
145155 result = integer2string (value_int, 16 );
146156 prefix = " 0x" ;
147157 }
148158 else
149159 {
160+ result = integer2binary (value_int, width);
150161 prefix = " 0b" ;
151- result = id2string (value);
152162 }
153163
154164 std::ostringstream oss;
@@ -185,9 +195,7 @@ std::string trace_numeric_value(
185195 type.id ()==ID_c_enum ||
186196 type.id ()==ID_c_enum_tag)
187197 {
188- const std::string &str =
189- numeric_representation (to_constant_expr (expr), options);
190- return str;
198+ return numeric_representation (to_constant_expr (expr), ns, options);
191199 }
192200 else if (type.id ()==ID_bool)
193201 {
0 commit comments