MCPcopy Create free account
hub / github.com/argotorg/solidity / requireOrAssertFunction

Method requireOrAssertFunction

libsolidity/codegen/YulUtilFunctions.cpp:293–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291}
292
293std::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
329std::string YulUtilFunctions::requireWithErrorFunction(FunctionCall const& errorConstructorCall)
330{

Callers 1

endVisitMethod · 0.80

Calls 7

WhiskersClass · 0.85
IRVariableClass · 0.85
identifierMethod · 0.80
renderMethod · 0.80
stackSlotsMethod · 0.80
createFunctionMethod · 0.45

Tested by

no test coverage detected