| 291 | } |
| 292 | |
| 293 | std::string YulUtilFunctions::requireOrAssertFunction(bool _assert, Type const* _messageType, ASTPointer<Expression const> _stringArgumentExpression) |
| 294 | { |
| 295 | std::string functionName = |
| 296 | std::string(_assert ? "assert_helper" : "require_helper") + |
| 297 | (_messageType ? ("_" + _messageType->identifier()) : ""); |
| 298 | |
| 299 | solAssert(!_assert || !_messageType, "Asserts can't have messages!"); |
| 300 | |
| 301 | return m_functionCollector.createFunction(functionName, [&]() { |
| 302 | if (!_messageType) |
| 303 | return Whiskers(R"( |
| 304 | function <functionName>(condition) { |
| 305 | if iszero(condition) { <error> } |
| 306 | } |
| 307 | )") |
| 308 | ("error", _assert ? panicFunction(PanicCode::Assert) + "()" : "revert(0, 0)") |
| 309 | ("functionName", functionName) |
| 310 | .render(); |
| 311 | |
| 312 | solAssert(_stringArgumentExpression, "Require with string must have a string argument"); |
| 313 | solAssert(_stringArgumentExpression->annotation().type); |
| 314 | std::vector<std::string> functionParameterNames = IRVariable(*_stringArgumentExpression).stackSlots(); |
| 315 | |
| 316 | return Whiskers(R"( |
| 317 | function <functionName>(condition <functionParameterNames>) { |
| 318 | if iszero(condition) |
| 319 | <revertWithError> |
| 320 | } |
| 321 | )") |
| 322 | ("functionName", functionName) |
| 323 | ("revertWithError", revertWithError("Error(string)", {TypeProvider::stringMemory()}, {_stringArgumentExpression})) |
| 324 | ("functionParameterNames", joinHumanReadablePrefixed(functionParameterNames)) |
| 325 | .render(); |
| 326 | }); |
| 327 | } |
| 328 | |
| 329 | std::string YulUtilFunctions::requireWithErrorFunction(FunctionCall const& errorConstructorCall) |
| 330 | { |
no test coverage detected