@@ -14,11 +14,67 @@ Author: Peter Schrammel
14
14
#include " fixedbv.h"
15
15
#include " std_expr.h"
16
16
#include " config.h"
17
+ #include " identifier.h"
17
18
18
19
#include " json_expr.h"
19
20
20
21
/* ******************************************************************\
21
22
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
+
22
78
Function: json
23
79
24
80
Inputs:
@@ -262,9 +318,19 @@ json_objectt json(
262
318
else if (type.id ()==ID_pointer)
263
319
{
264
320
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))
267
326
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
+ }
268
334
}
269
335
else if (type.id ()==ID_bool)
270
336
{
0 commit comments