Skip to content

Commit 17c9de8

Browse files
committed
formatter for pointer constants
This adds an expression formatter for pointer-typed constants.
1 parent f8e5b77 commit 17c9de8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

scripts/expected_doxygen_warnings.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ warning: Included by graph for 'invariant.h' not generated, too many nodes (172)
77
warning: Included by graph for 'irep.h' not generated, too many nodes (80), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
88
warning: Included by graph for 'message.h' not generated, too many nodes (97), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
99
warning: Included by graph for 'namespace.h' not generated, too many nodes (88), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
10-
warning: Included by graph for 'pointer_expr.h' not generated, too many nodes (120), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
11-
warning: Included by graph for 'prefix.h' not generated, too many nodes (61), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
10+
warning: Included by graph for 'pointer_expr.h' not generated, too many nodes (121), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
11+
warning: Included by graph for 'prefix.h' not generated, too many nodes (62), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
1212
warning: Included by graph for 'simplify_expr.h' not generated, too many nodes (67), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
1313
warning: Included by graph for 'std_code.h' not generated, too many nodes (71), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
1414
warning: Included by graph for 'std_expr.h' not generated, too many nodes (178), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.

src/util/format_expr.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Author: Daniel Kroening, [email protected]
1717
#include "ieee_float.h"
1818
#include "mathematical_expr.h"
1919
#include "mp_arith.h"
20+
#include "pointer_expr.h"
21+
#include "prefix.h"
2022
#include "std_code.h"
2123
#include "string_utils.h"
2224

@@ -177,8 +179,30 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
177179
return os << '"' << escape(id2string(src.get_value())) << '"';
178180
else if(type == ID_floatbv)
179181
return os << ieee_floatt(src);
180-
else if(type == ID_pointer && src.is_zero())
181-
return os << src.get_value();
182+
else if(type == ID_pointer)
183+
{
184+
if(src.is_zero())
185+
return os << ID_NULL;
186+
else if(has_prefix(id2string(src.get_value()), "INVALID-"))
187+
{
188+
return os << "INVALID-POINTER";
189+
}
190+
else if(src.operands().size() == 1)
191+
{
192+
const auto &unary_expr = to_unary_expr(src);
193+
const auto &pointer_type = to_pointer_type(src.type());
194+
return os << "pointer(" << format(unary_expr.op()) << ", "
195+
<< format(pointer_type.subtype()) << ')';
196+
}
197+
else
198+
{
199+
const auto &pointer_type = to_pointer_type(src.type());
200+
const auto width = pointer_type.get_width();
201+
auto int_value = bvrep2integer(src.get_value(), width, false);
202+
return os << "pointer(0x" << integer2string(int_value, 16) << ", "
203+
<< format(pointer_type.subtype()) << ')';
204+
}
205+
}
182206
else
183207
return os << src.pretty();
184208
}

0 commit comments

Comments
 (0)