|
30 | 30 | #include <ostream>
|
31 | 31 | #include <stack>
|
32 | 32 |
|
| 33 | +// expressions that are rendered with infix operators |
| 34 | +struct infix_opt |
| 35 | +{ |
| 36 | + const char *rep; |
| 37 | +}; |
| 38 | + |
| 39 | +const std::map<irep_idt, infix_opt> infix_map = { |
| 40 | + {ID_plus, {"+"}}, |
| 41 | + {ID_minus, {"-"}}, |
| 42 | + {ID_mult, {"*"}}, |
| 43 | + {ID_div, {"/"}}, |
| 44 | + {ID_equal, {"="}}, |
| 45 | + {ID_notequal, {u8"\u2260"}}, // /=, U+2260 |
| 46 | + {ID_and, {u8"\u2227"}}, // wedge, U+2227 |
| 47 | + {ID_or, {u8"\u2228"}}, // vee, U+2228 |
| 48 | + {ID_xor, {u8"\u2295"}}, // + in circle, U+2295 |
| 49 | + {ID_implies, {u8"\u21d2"}}, // =>, U+21D2 |
| 50 | + {ID_le, {u8"\u2264"}}, // <=, U+2264 |
| 51 | + {ID_ge, {u8"\u2265"}}, // >=, U+2265 |
| 52 | + {ID_lt, {"<"}}, |
| 53 | + {ID_gt, {">"}}, |
| 54 | +}; |
| 55 | + |
33 | 56 | /// We use the precendences that most readers expect
|
34 | 57 | /// (i.e., the ones you learn in primary school),
|
35 | 58 | /// and stay clear of the surprising ones that C has.
|
@@ -63,31 +86,20 @@ static std::ostream &format_rec(std::ostream &os, const multi_ary_exprt &src)
|
63 | 86 | {
|
64 | 87 | bool first = true;
|
65 | 88 |
|
66 |
| - std::string operator_str; |
67 |
| - |
68 |
| - if(src.id() == ID_and) |
69 |
| - operator_str = u8"\u2227"; // wedge, U+2227 |
70 |
| - else if(src.id() == ID_or) |
71 |
| - operator_str = u8"\u2228"; // vee, U+2228 |
72 |
| - else if(src.id() == ID_xor) |
73 |
| - operator_str = u8"\u2295"; // + in circle, U+2295 |
74 |
| - else if(src.id() == ID_le) |
75 |
| - operator_str = u8"\u2264"; // <=, U+2264 |
76 |
| - else if(src.id() == ID_ge) |
77 |
| - operator_str = u8"\u2265"; // >=, U+2265 |
78 |
| - else if(src.id() == ID_notequal) |
79 |
| - operator_str = u8"\u2260"; // /=, U+2260 |
80 |
| - else if(src.id() == ID_implies) |
81 |
| - operator_str = u8"\u21d2"; // =>, U+21D2 |
82 |
| - else if(src.id() == ID_equal) |
| 89 | + std::string operator_str = id2string(src.id()); // default |
| 90 | + |
| 91 | + if( |
| 92 | + src.id() == ID_equal && !src.operands().empty() && |
| 93 | + src.op0().type().id() == ID_bool) |
83 | 94 | {
|
84 |
| - if(!src.operands().empty() && src.op0().type().id() == ID_bool) |
85 |
| - operator_str = u8"\u21d4"; // <=>, U+21D4 |
86 |
| - else |
87 |
| - operator_str = "="; |
| 95 | + operator_str = u8"\u21d4"; // <=>, U+21D4 |
88 | 96 | }
|
89 | 97 | else
|
90 |
| - operator_str = id2string(src.id()); |
| 98 | + { |
| 99 | + auto infix_map_it = infix_map.find(src.id()); |
| 100 | + if(infix_map_it != infix_map.end()) |
| 101 | + operator_str = infix_map_it->second.rep; |
| 102 | + } |
91 | 103 |
|
92 | 104 | for(const auto &op : src.operands())
|
93 | 105 | {
|
|
0 commit comments