Skip to content

Commit 06837c8

Browse files
author
thk123
committed
Use the member functions to make code more robust
1 parent eff658a commit 06837c8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/util/json_expr.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,15 @@ json_objectt json(
243243

244244
if(expr.id()==ID_constant)
245245
{
246+
const constant_exprt &constant_expr=to_constant_expr(expr);
246247
if(type.id()==ID_unsignedbv ||
247248
type.id()==ID_signedbv ||
248249
type.id()==ID_c_bit_field)
249250
{
250251
std::size_t width=to_bitvector_type(type).get_width();
251252

252253
result["name"]=json_stringt("integer");
253-
result["binary"]=json_stringt(expr.get_string(ID_value));
254+
result["binary"]=json_stringt(id2string(constant_expr.get_value()));
254255
result["width"]=json_numbert(std::to_string(width));
255256

256257
const typet &underlying_type=
@@ -279,7 +280,7 @@ json_objectt json(
279280
else if(type.id()==ID_c_enum)
280281
{
281282
result["name"]=json_stringt("integer");
282-
result["binary"]=json_stringt(expr.get_string(ID_value));
283+
result["binary"]=json_stringt(id2string(constant_expr.get_value()));
283284
result["width"]=json_numbert(type.subtype().get_string(ID_width));
284285
result["c_type"]=json_stringt("enum");
285286

@@ -291,27 +292,27 @@ json_objectt json(
291292
{
292293
constant_exprt tmp;
293294
tmp.type()=ns.follow_tag(to_c_enum_tag_type(type));
294-
tmp.set_value(to_constant_expr(expr).get_value());
295+
tmp.set_value(constant_expr.get_value());
295296
return json(tmp, ns);
296297
}
297298
else if(type.id()==ID_bv)
298299
{
299300
result["name"]=json_stringt("bitvector");
300-
result["binary"]=json_stringt(expr.get_string(ID_value));
301+
result["binary"]=json_stringt(id2string(constant_expr.get_value()));
301302
}
302303
else if(type.id()==ID_fixedbv)
303304
{
304305
result["name"]=json_stringt("fixed");
305306
result["width"]=json_numbert(type.get_string(ID_width));
306-
result["binary"]=json_stringt(expr.get_string(ID_value));
307+
result["binary"]=json_stringt(id2string(constant_expr.get_value()));
307308
result["data"]=
308309
json_stringt(fixedbvt(to_constant_expr(expr)).to_ansi_c_string());
309310
}
310311
else if(type.id()==ID_floatbv)
311312
{
312313
result["name"]=json_stringt("float");
313314
result["width"]=json_numbert(type.get_string(ID_width));
314-
result["binary"]=json_stringt(expr.get_string(ID_value));
315+
result["binary"]=json_stringt(id2string(constant_expr.get_value()));
315316
result["data"]=
316317
json_stringt(ieee_floatt(to_constant_expr(expr)).to_ansi_c_string());
317318
}
@@ -350,7 +351,7 @@ json_objectt json(
350351
else if(type.id()==ID_string)
351352
{
352353
result["name"]=json_stringt("string");
353-
result["data"]=json_stringt(expr.get_string(ID_value));
354+
result["data"]=json_stringt(id2string(constant_expr.get_value()));
354355
}
355356
else
356357
{

0 commit comments

Comments
 (0)