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

Method convertLengthToSize

libsolidity/codegen/ArrayUtils.cpp:626–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624}
625
626void ArrayUtils::convertLengthToSize(ArrayType const& _arrayType, bool _pad) const
627{
628 if (_arrayType.location() == DataLocation::Storage)
629 {
630 if (_arrayType.baseType()->storageSize() <= 1)
631 {
632 unsigned baseBytes = _arrayType.baseType()->storageBytes();
633 if (baseBytes == 0)
634 m_context << Instruction::POP << u256(1);
635 else if (baseBytes <= 16)
636 {
637 unsigned itemsPerSlot = 32 / baseBytes;
638 m_context
639 << u256(itemsPerSlot - 1) << Instruction::ADD
640 << u256(itemsPerSlot) << Instruction::SWAP1 << Instruction::DIV;
641 }
642 }
643 else
644 m_context << _arrayType.baseType()->storageSize() << Instruction::MUL;
645 }
646 else
647 {
648 if (!_arrayType.isByteArrayOrString())
649 {
650 if (_arrayType.location() == DataLocation::Memory)
651 m_context << _arrayType.memoryStride();
652 else
653 m_context << _arrayType.calldataStride();
654 m_context << Instruction::MUL;
655 }
656 else if (_pad)
657 m_context << u256(31) << Instruction::ADD
658 << u256(32) << Instruction::DUP1
659 << Instruction::SWAP2 << Instruction::DIV << Instruction::MUL;
660 }
661}
662
663void ArrayUtils::retrieveLength(ArrayType const& _arrayType, unsigned _stackDepth) const
664{

Callers 2

clearArrayMethod · 0.80
convertTypeMethod · 0.80

Calls 7

isByteArrayOrStringMethod · 0.80
memoryStrideMethod · 0.80
calldataStrideMethod · 0.80
locationMethod · 0.45
storageSizeMethod · 0.45
baseTypeMethod · 0.45
storageBytesMethod · 0.45

Tested by

no test coverage detected