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

Method arrayLengthFunction

libsolidity/codegen/YulUtilFunctions.cpp:1317–1357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1315}
1316
1317std::string YulUtilFunctions::arrayLengthFunction(ArrayType const& _type)
1318{
1319 std::string functionName = "array_length_" + _type.identifier();
1320 return m_functionCollector.createFunction(functionName, [&]() {
1321 Whiskers w(R"(
1322 function <functionName>(value<?dynamic><?calldata>, len</calldata></dynamic>) -> length {
1323 <?dynamic>
1324 <?memory>
1325 length := mload(value)
1326 </memory>
1327 <?storage>
1328 length := sload(value)
1329 <?byteArray>
1330 length := <extractByteArrayLength>(length)
1331 </byteArray>
1332 </storage>
1333 <?calldata>
1334 length := len
1335 </calldata>
1336 <!dynamic>
1337 length := <length>
1338 </dynamic>
1339 }
1340 )");
1341 w("functionName", functionName);
1342 w("dynamic", _type.isDynamicallySized());
1343 if (!_type.isDynamicallySized())
1344 w("length", toCompactHexWithPrefix(_type.length()));
1345 w("memory", _type.location() == DataLocation::Memory);
1346 w("storage", _type.location() == DataLocation::Storage);
1347 w("calldata", _type.location() == DataLocation::CallData);
1348 if (_type.location() == DataLocation::Storage)
1349 {
1350 w("byteArray", _type.isByteArrayOrString());
1351 if (_type.isByteArrayOrString())
1352 w("extractByteArrayLength", extractByteArrayLengthFunction());
1353 }
1354
1355 return w.render();
1356 });
1357}
1358
1359std::string YulUtilFunctions::extractByteArrayLengthFunction()
1360{

Calls 8

toCompactHexWithPrefixFunction · 0.85
identifierMethod · 0.80
isByteArrayOrStringMethod · 0.80
renderMethod · 0.80
createFunctionMethod · 0.45
isDynamicallySizedMethod · 0.45
lengthMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected