| 243 | } |
| 244 | |
| 245 | std::optional<std::string> expressionToString(smtutil::Expression const& _expr, frontend::Type const* _type) |
| 246 | { |
| 247 | if (smt::isNumber(*_type)) |
| 248 | { |
| 249 | solAssert(_expr.sort->kind == Kind::Int); |
| 250 | solAssert(_expr.arguments.empty() || _expr.name == "-"); |
| 251 | if (_expr.name == "-") |
| 252 | { |
| 253 | solAssert(_expr.arguments.size() == 1); |
| 254 | smtutil::Expression const& val = _expr.arguments[0]; |
| 255 | solAssert(val.sort->kind == Kind::Int && val.arguments.empty()); |
| 256 | return "(- " + val.name + ")"; |
| 257 | } |
| 258 | |
| 259 | if ( |
| 260 | _type->category() == frontend::Type::Category::Address || |
| 261 | _type->category() == frontend::Type::Category::FixedBytes |
| 262 | ) |
| 263 | { |
| 264 | try |
| 265 | { |
| 266 | if (_expr.name == "0") |
| 267 | return "0x0"; |
| 268 | // For some reason the code below returns "0x" for "0". |
| 269 | return util::toHex(toCompactBigEndian(bigint(_expr.name)), util::HexPrefix::Add, util::HexCase::Lower); |
| 270 | } |
| 271 | catch (std::out_of_range const&) |
| 272 | { |
| 273 | } |
| 274 | catch (std::invalid_argument const&) |
| 275 | { |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return _expr.name; |
| 280 | } |
| 281 | if (smt::isBool(*_type)) |
| 282 | { |
| 283 | solAssert(_expr.sort->kind == Kind::Bool); |
| 284 | solAssert(_expr.arguments.empty()); |
| 285 | solAssert(_expr.name == "true" || _expr.name == "false"); |
| 286 | return _expr.name; |
| 287 | } |
| 288 | if (smt::isFunction(*_type)) |
| 289 | { |
| 290 | solAssert(_expr.arguments.empty()); |
| 291 | return _expr.name; |
| 292 | } |
| 293 | if (smt::isArray(*_type)) |
| 294 | { |
| 295 | auto const& arrayType = dynamic_cast<ArrayType const&>(*_type); |
| 296 | if (_expr.name != "tuple_constructor") |
| 297 | return {}; |
| 298 | |
| 299 | auto const& tupleSort = dynamic_cast<TupleSort const&>(*_expr.sort); |
| 300 | solAssert(tupleSort.components.size() == 2); |
| 301 | |
| 302 | unsigned long length; |
no test coverage detected