Use array length function.

This commit is contained in:
chriseth 2020-10-14 12:22:22 +02:00
parent 56d6855222
commit a737e51533

View File

@ -1767,32 +1767,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
auto const& type = dynamic_cast<ArrayType const&>(*_memberAccess.expression().annotation().type);
if (member == "length")
{
if (!type.isDynamicallySized())
define(_memberAccess) << type.length() << "\n";
else
switch (type.location())
{
case DataLocation::CallData:
define(_memberAccess, IRVariable(_memberAccess.expression()).part("length"));
break;
case DataLocation::Storage:
{
define(_memberAccess) <<
m_utils.arrayLengthFunction(type) <<
"(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
break;
}
case DataLocation::Memory:
define(_memberAccess) <<
"mload(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
break;
}
}
define(_memberAccess) <<
m_utils.arrayLengthFunction(type) <<
"(" <<
IRVariable(_memberAccess.expression()).commaSeparatedList() <<
")\n";
else if (member == "pop" || member == "push")
{
solAssert(type.location() == DataLocation::Storage, "");