| 139 | } |
| 140 | |
| 141 | std::string toSolidityStr(smtutil::Expression const& _expr) |
| 142 | { |
| 143 | auto const& op = _expr.name; |
| 144 | |
| 145 | auto const& args = _expr.arguments; |
| 146 | auto strArgs = util::applyMap(args, [](auto const& _arg) { return toSolidityStr(_arg); }); |
| 147 | |
| 148 | // Constant or variable. |
| 149 | if (args.empty()) |
| 150 | return op; |
| 151 | |
| 152 | if (starts_with(op, "dt_accessor")) |
| 153 | return formatDatatypeAccessor(_expr, strArgs); |
| 154 | |
| 155 | // Infix operators with format replacements. |
| 156 | static std::map<std::string, std::string> const infixOps{ |
| 157 | {"and", "&&"}, |
| 158 | {"or", "||"}, |
| 159 | {"implies", "=>"}, |
| 160 | {"=", "="}, |
| 161 | {">", ">"}, |
| 162 | {">=", ">="}, |
| 163 | {"<", "<"}, |
| 164 | {"<=", "<="}, |
| 165 | {"+", "+"}, |
| 166 | {"-", "-"}, |
| 167 | {"*", "*"}, |
| 168 | {"/", "/"}, |
| 169 | {"div", "/"}, |
| 170 | {"mod", "%"} |
| 171 | }; |
| 172 | // Some of these (and, or, +, *) may have >= 2 arguments from z3. |
| 173 | if (infixOps.count(op) && args.size() >= 2) |
| 174 | return formatInfixOp(infixOps.at(op), strArgs); |
| 175 | |
| 176 | static std::set<std::string> const arrayOps{"select", "store", "const_array"}; |
| 177 | if (arrayOps.count(op)) |
| 178 | return formatArrayOp(_expr, strArgs); |
| 179 | |
| 180 | if (args.size() == 1) |
| 181 | return formatUnaryOp(_expr, strArgs); |
| 182 | |
| 183 | // Other operators such as bv2int, int2bv may end up here. |
| 184 | return op + "(" + boost::algorithm::join(strArgs, ", ") + ")"; |
| 185 | } |
| 186 | |
| 187 | namespace |
| 188 | { |
no test coverage detected