|
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 | }
|
@@ -445,6 +469,39 @@ void format_expr_configt::setup()
|
445 | 469 | return fallback_format_rec(os, expr);
|
446 | 470 | };
|
447 | 471 |
|
| 472 | + expr_map[ID_string_constant] = |
| 473 | + [](std::ostream &os, const exprt &expr) -> std::ostream & { |
| 474 | + return os << '"' << expr.get_string(ID_value) << '"'; |
| 475 | + }; |
| 476 | + |
| 477 | + expr_map[ID_function_application] = |
| 478 | + [](std::ostream &os, const exprt &expr) -> std::ostream & { |
| 479 | + const auto &function_application_expr = to_function_application_expr(expr); |
| 480 | + os << format(function_application_expr.function()) << '('; |
| 481 | + bool first = true; |
| 482 | + for(auto &argument : function_application_expr.arguments()) |
| 483 | + { |
| 484 | + if(first) |
| 485 | + first = false; |
| 486 | + else |
| 487 | + os << ", "; |
| 488 | + os << format(argument); |
| 489 | + } |
| 490 | + os << ')'; |
| 491 | + return os; |
| 492 | + }; |
| 493 | + |
| 494 | + expr_map[ID_dereference] = |
| 495 | + [](std::ostream &os, const exprt &expr) -> std::ostream & { |
| 496 | + const auto &dereference_expr = to_dereference_expr(expr); |
| 497 | + os << '*'; |
| 498 | + if(dereference_expr.pointer().id() != ID_symbol) |
| 499 | + os << '(' << format(dereference_expr.pointer()) << ')'; |
| 500 | + else |
| 501 | + os << format(dereference_expr.pointer()); |
| 502 | + return os; |
| 503 | + }; |
| 504 | + |
448 | 505 | fallback = [](std::ostream &os, const exprt &expr) -> std::ostream & {
|
449 | 506 | return fallback_format_rec(os, expr);
|
450 | 507 | };
|
|
0 commit comments