@@ -31,24 +31,7 @@ Author: Peter Schrammel
3131
3232static exprt simplify_json_expr (const exprt &src)
3333{
34- if (src.id () == ID_constant)
35- {
36- if (src.type ().id () == ID_pointer)
37- {
38- const constant_exprt &c = to_constant_expr (src);
39-
40- if (
41- c.get_value () != ID_NULL &&
42- (!c.value_is_zero_string () || !config.ansi_c .NULL_is_zero ) &&
43- src.operands ().size () == 1 &&
44- to_unary_expr (src).op ().id () != ID_constant)
45- // try to simplify the constant pointer
46- {
47- return simplify_json_expr (to_unary_expr (src).op ());
48- }
49- }
50- }
51- else if (src.id () == ID_typecast)
34+ if (src.id () == ID_typecast)
5235 {
5336 return simplify_json_expr (to_typecast_expr (src).op ());
5437 }
@@ -303,25 +286,8 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode)
303286 {
304287 result[" name" ] = json_stringt (" pointer" );
305288 result[" type" ] = json_stringt (type_string);
306- exprt simpl_expr = simplify_json_expr (expr);
307- if (
308- simpl_expr.get (ID_value) == ID_NULL ||
309- // remove typecast on NULL
310- (simpl_expr.id () == ID_constant &&
311- simpl_expr.type ().id () == ID_pointer &&
312- to_unary_expr (simpl_expr).op ().get (ID_value) == ID_NULL))
313- {
289+ if (constant_expr.get_value () == ID_NULL)
314290 result[" data" ] = json_stringt (value_string);
315- }
316- else if (simpl_expr.id () == ID_symbol)
317- {
318- const irep_idt &ptr_id = to_symbol_expr (simpl_expr).get_identifier ();
319- identifiert identifier (id2string (ptr_id));
320- DATA_INVARIANT (
321- !identifier.components .empty (),
322- " pointer identifier should have non-empty components" );
323- result[" data" ] = json_stringt (identifier.components .back ());
324- }
325291 }
326292 else if (type.id () == ID_bool)
327293 {
@@ -339,6 +305,46 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode)
339305 result[" name" ] = json_stringt (" unknown" );
340306 }
341307 }
308+ else if (expr.id () == ID_annotated_pointer_constant)
309+ {
310+ const annotated_pointer_constant_exprt &c =
311+ to_annotated_pointer_constant_expr (expr);
312+ exprt simpl_expr = simplify_json_expr (c.symbolic_pointer ());
313+
314+ if (simpl_expr.id () == ID_symbol)
315+ {
316+ result[" name" ] = json_stringt (" pointer" );
317+
318+ const typet &type = expr.type ();
319+
320+ std::unique_ptr<languaget> lang;
321+ if (mode != ID_unknown)
322+ lang = std::unique_ptr<languaget>(get_language_from_mode (mode));
323+ if (!lang)
324+ lang = std::unique_ptr<languaget>(get_default_language ());
325+
326+ const typet &underlying_type =
327+ type.id () == ID_c_bit_field
328+ ? to_c_bit_field_type (type).underlying_type ()
329+ : type;
330+
331+ std::string type_string;
332+ bool error = lang->from_type (underlying_type, type_string, ns);
333+ CHECK_RETURN (!error);
334+ result[" type" ] = json_stringt (type_string);
335+
336+ const irep_idt &ptr_id = to_symbol_expr (simpl_expr).get_identifier ();
337+ identifiert identifier (id2string (ptr_id));
338+ DATA_INVARIANT (
339+ !identifier.components .empty (),
340+ " pointer identifier should have non-empty components" );
341+ result[" data" ] = json_stringt (identifier.components .back ());
342+ }
343+ else if (simpl_expr.id () == ID_constant)
344+ return json (simpl_expr, ns, mode);
345+ else
346+ result[" name" ] = json_stringt (" unknown" );
347+ }
342348 else if (expr.id () == ID_array)
343349 {
344350 result[" name" ] = json_stringt (" array" );
0 commit comments