Skip to content

Commit 072e374

Browse files
Display dynamic object names as 'data' in JSON traces
Fixes diffblue/test-gen#147
1 parent fd96acc commit 072e374

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

src/util/json_expr.cpp

+68-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,67 @@ Author: Peter Schrammel
1414
#include "fixedbv.h"
1515
#include "std_expr.h"
1616
#include "config.h"
17+
#include "identifier.h"
1718

1819
#include "json_expr.h"
1920

2021
/*******************************************************************\
2122
23+
Function: simplify_json_expr
24+
25+
Inputs:
26+
27+
Outputs:
28+
29+
Purpose:
30+
31+
\*******************************************************************/
32+
33+
static exprt simplify_json_expr(
34+
const exprt &src,
35+
const namespacet &ns)
36+
{
37+
if(src.id()==ID_constant)
38+
{
39+
const typet &type=ns.follow(src.type());
40+
41+
if(type.id()==ID_pointer)
42+
{
43+
const irep_idt &value=to_constant_expr(src).get_value();
44+
45+
if(value!=ID_NULL &&
46+
(value!=std::string(value.size(), '0') ||
47+
!config.ansi_c.NULL_is_zero) &&
48+
src.operands().size()==1 &&
49+
src.op0().id()!=ID_constant)
50+
// try to simplify the constant pointer
51+
return simplify_json_expr(src.op0(), ns);
52+
}
53+
}
54+
else if(src.id()==ID_address_of &&
55+
src.operands().size()==1 &&
56+
src.op0().id()==ID_member &&
57+
id2string(to_member_expr(
58+
src.op0()).get_component_name()).find("@")!=std::string::npos)
59+
{
60+
// simplify things of the form &member_expr(object, @class_identifier)
61+
return simplify_json_expr(src.op0(), ns);
62+
}
63+
else if(src.id()==ID_member &&
64+
src.operands().size()==1 &&
65+
id2string(
66+
to_member_expr(src).get_component_name())
67+
.find("@")!=std::string::npos)
68+
{
69+
// simplify things of the form member_expr(object, @class_identifier)
70+
return simplify_json_expr(src.op0(), ns);
71+
}
72+
73+
return src;
74+
}
75+
76+
/*******************************************************************\
77+
2278
Function: json
2379
2480
Inputs:
@@ -262,9 +318,19 @@ json_objectt json(
262318
else if(type.id()==ID_pointer)
263319
{
264320
result["name"]=json_stringt("pointer");
265-
result["binary"]=json_stringt(expr.get_string(ID_value));
266-
if(expr.get(ID_value)==ID_NULL)
321+
exprt simpl_expr=simplify_json_expr(expr, ns);
322+
if(simpl_expr.get(ID_value)==ID_NULL ||
323+
// remove typecast on NULL
324+
(simpl_expr.id()==ID_constant && simpl_expr.type().id()==ID_pointer &&
325+
simpl_expr.op0().get(ID_value)==ID_NULL))
267326
result["data"]=json_stringt("NULL");
327+
else if(simpl_expr.id()==ID_symbol)
328+
{
329+
const irep_idt &ptr_id=to_symbol_expr(simpl_expr).get_identifier();
330+
identifiert identifier(id2string(ptr_id));
331+
assert(!identifier.components.empty());
332+
result["data"]=json_stringt(identifier.components.back());
333+
}
268334
}
269335
else if(type.id()==ID_bool)
270336
{

0 commit comments

Comments
 (0)