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

Method arrayAllocationSizeFunction

libsolidity/codegen/YulUtilFunctions.cpp:2362–2389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2360}
2361
2362std::string YulUtilFunctions::arrayAllocationSizeFunction(ArrayType const& _type)
2363{
2364 solAssert(_type.dataStoredIn(DataLocation::Memory), "");
2365 std::string functionName = "array_allocation_size_" + _type.identifier();
2366 return m_functionCollector.createFunction(functionName, [&]() {
2367 Whiskers w(R"(
2368 function <functionName>(length) -> size {
2369 // Make sure we can allocate memory without overflow
2370 if gt(length, 0xffffffffffffffff) { <panic>() }
2371 <?byteArray>
2372 size := <roundUp>(length)
2373 <!byteArray>
2374 size := mul(length, 0x20)
2375 </byteArray>
2376 <?dynamic>
2377 // add length slot
2378 size := add(size, 0x20)
2379 </dynamic>
2380 }
2381 )");
2382 w("functionName", functionName);
2383 w("panic", panicFunction(PanicCode::ResourceError));
2384 w("byteArray", _type.isByteArrayOrString());
2385 w("roundUp", roundUpFunction());
2386 w("dynamic", _type.isDynamicallySized());
2387 return w.render();
2388 });
2389}
2390
2391std::string YulUtilFunctions::arrayDataAreaFunction(ArrayType const& _type)
2392{

Calls 6

identifierMethod · 0.80
isByteArrayOrStringMethod · 0.80
renderMethod · 0.80
dataStoredInMethod · 0.45
createFunctionMethod · 0.45
isDynamicallySizedMethod · 0.45

Tested by

no test coverage detected