|
17 | 17 | #include "ieee_float.h"
|
18 | 18 | #include "mathematical_expr.h"
|
19 | 19 | #include "mp_arith.h"
|
| 20 | +#include "pointer_expr.h" |
| 21 | +#include "prefix.h" |
20 | 22 | #include "std_code.h"
|
21 | 23 | #include "string_utils.h"
|
22 | 24 |
|
@@ -177,8 +179,30 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
|
177 | 179 | return os << '"' << escape(id2string(src.get_value())) << '"';
|
178 | 180 | else if(type == ID_floatbv)
|
179 | 181 | 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 | + } |
182 | 206 | else
|
183 | 207 | return os << src.pretty();
|
184 | 208 | }
|
|
0 commit comments