| 579 | } |
| 580 | |
| 581 | void ArrayUtils::clearStorageLoop(Type const* _type) const |
| 582 | { |
| 583 | solAssert(_type->storageBytes() >= 32, ""); |
| 584 | m_context.callLowLevelFunction( |
| 585 | "$clearStorageLoop_" + _type->identifier(), |
| 586 | 2, |
| 587 | 0, |
| 588 | [_type](CompilerContext& _context) |
| 589 | { |
| 590 | unsigned stackHeightStart = _context.stackHeight(); |
| 591 | if (_type->category() == Type::Category::Mapping) |
| 592 | { |
| 593 | _context << Instruction::POP << Instruction::POP; |
| 594 | return; |
| 595 | } |
| 596 | // stack: start_pos slot_count |
| 597 | // Initialize loop counter i = 0 |
| 598 | _context << u256(0); |
| 599 | // stack: start_pos slot_count i |
| 600 | evmasm::AssemblyItem loopStart = _context.appendJumpToNew(); |
| 601 | _context << loopStart; |
| 602 | // check for loop condition: !(slot_count > i) = (i >= slot_count) |
| 603 | _context << Instruction::DUP1 << Instruction::DUP3 << Instruction::GT << Instruction::ISZERO; |
| 604 | evmasm::AssemblyItem zeroLoopEnd = _context.newTag(); |
| 605 | _context.appendConditionalJumpTo(zeroLoopEnd); |
| 606 | // stack: start_pos slot_count i |
| 607 | // compute storage position: start_pos + i |
| 608 | _context << Instruction::DUP3 << Instruction::DUP2 << Instruction::ADD; |
| 609 | // stack: start_pos slot_count i (start_pos+i) |
| 610 | // delete storage slot |
| 611 | _context << u256(0); |
| 612 | StorageItem(_context, *_type).setToZero(SourceLocation(), /* _removeReference = */ true); |
| 613 | // stack: start_pos slot_count i |
| 614 | // increment counter: i += storageSize |
| 615 | _context << _type->storageSize() << Instruction::ADD; |
| 616 | _context.appendJumpTo(loopStart); |
| 617 | // cleanup |
| 618 | _context << zeroLoopEnd; |
| 619 | // stack: start_pos slot_count i |
| 620 | _context << Instruction::POP << Instruction::POP << Instruction::POP; |
| 621 | solAssert(_context.stackHeight() == stackHeightStart - 2, ""); |
| 622 | } |
| 623 | ); |
| 624 | } |
| 625 | |
| 626 | void ArrayUtils::convertLengthToSize(ArrayType const& _arrayType, bool _pad) const |
| 627 | { |
no test coverage detected