mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change clearStorageLoop to TypePointer.
This commit is contained in:
parent
1b87e08e04
commit
23eca813f5
@ -276,7 +276,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
|
|||||||
// stack: target_ref target_data_end source_data_pos target_data_pos_updated source_data_end
|
// stack: target_ref target_data_end source_data_pos target_data_pos_updated source_data_end
|
||||||
_context << Instruction::POP << Instruction::SWAP1 << Instruction::POP;
|
_context << Instruction::POP << Instruction::SWAP1 << Instruction::POP;
|
||||||
// stack: target_ref target_data_end target_data_pos_updated
|
// stack: target_ref target_data_end target_data_pos_updated
|
||||||
utils.clearStorageLoop(*targetBaseType);
|
utils.clearStorageLoop(targetBaseType);
|
||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -572,9 +572,9 @@ void ArrayUtils::clearArray(ArrayType const& _typeIn) const
|
|||||||
ArrayUtils(_context).convertLengthToSize(_type);
|
ArrayUtils(_context).convertLengthToSize(_type);
|
||||||
_context << Instruction::ADD << Instruction::SWAP1;
|
_context << Instruction::ADD << Instruction::SWAP1;
|
||||||
if (_type.baseType()->storageBytes() < 32)
|
if (_type.baseType()->storageBytes() < 32)
|
||||||
ArrayUtils(_context).clearStorageLoop(*make_shared<IntegerType>(256));
|
ArrayUtils(_context).clearStorageLoop(make_shared<IntegerType>(256));
|
||||||
else
|
else
|
||||||
ArrayUtils(_context).clearStorageLoop(*_type.baseType());
|
ArrayUtils(_context).clearStorageLoop(_type.baseType());
|
||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
}
|
}
|
||||||
solAssert(_context.stackHeight() == stackHeightStart - 2, "");
|
solAssert(_context.stackHeight() == stackHeightStart - 2, "");
|
||||||
@ -613,9 +613,9 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
|
|||||||
<< Instruction::SWAP1;
|
<< Instruction::SWAP1;
|
||||||
// stack: data_pos_end data_pos
|
// stack: data_pos_end data_pos
|
||||||
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
|
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
|
||||||
clearStorageLoop(*make_shared<IntegerType>(256));
|
clearStorageLoop(make_shared<IntegerType>(256));
|
||||||
else
|
else
|
||||||
clearStorageLoop(*_type.baseType());
|
clearStorageLoop(_type.baseType());
|
||||||
// cleanup
|
// cleanup
|
||||||
m_context << endTag;
|
m_context << endTag;
|
||||||
m_context << Instruction::POP;
|
m_context << Instruction::POP;
|
||||||
@ -720,7 +720,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
|
|||||||
ArrayUtils(_context).convertLengthToSize(_type);
|
ArrayUtils(_context).convertLengthToSize(_type);
|
||||||
_context << Instruction::DUP2 << Instruction::ADD << Instruction::SWAP1;
|
_context << Instruction::DUP2 << Instruction::ADD << Instruction::SWAP1;
|
||||||
// stack: ref new_length current_length first_word data_location_end data_location
|
// stack: ref new_length current_length first_word data_location_end data_location
|
||||||
ArrayUtils(_context).clearStorageLoop(*make_shared<IntegerType>(256));
|
ArrayUtils(_context).clearStorageLoop(make_shared<IntegerType>(256));
|
||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
// stack: ref new_length current_length first_word
|
// stack: ref new_length current_length first_word
|
||||||
solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3");
|
solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3");
|
||||||
@ -759,9 +759,9 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
|
|||||||
_context << Instruction::SWAP2 << Instruction::ADD;
|
_context << Instruction::SWAP2 << Instruction::ADD;
|
||||||
// stack: ref new_length delete_end delete_start
|
// stack: ref new_length delete_end delete_start
|
||||||
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
|
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
|
||||||
ArrayUtils(_context).clearStorageLoop(*make_shared<IntegerType>(256));
|
ArrayUtils(_context).clearStorageLoop(make_shared<IntegerType>(256));
|
||||||
else
|
else
|
||||||
ArrayUtils(_context).clearStorageLoop(*_type.baseType());
|
ArrayUtils(_context).clearStorageLoop(_type.baseType());
|
||||||
|
|
||||||
_context << resizeEnd;
|
_context << resizeEnd;
|
||||||
// cleanup
|
// cleanup
|
||||||
@ -771,17 +771,16 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayUtils::clearStorageLoop(Type const& _type) const
|
void ArrayUtils::clearStorageLoop(TypePointer const& _type) const
|
||||||
{
|
{
|
||||||
TypePointer type = _type.shared_from_this();
|
|
||||||
m_context.callLowLevelFunction(
|
m_context.callLowLevelFunction(
|
||||||
"$clearStorageLoop_" + _type.identifier(),
|
"$clearStorageLoop_" + _type->identifier(),
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
[type](CompilerContext& _context)
|
[_type](CompilerContext& _context)
|
||||||
{
|
{
|
||||||
unsigned stackHeightStart = _context.stackHeight();
|
unsigned stackHeightStart = _context.stackHeight();
|
||||||
if (type->category() == Type::Category::Mapping)
|
if (_type->category() == Type::Category::Mapping)
|
||||||
{
|
{
|
||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
return;
|
return;
|
||||||
@ -802,10 +801,10 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
|
|||||||
_context.appendConditionalJumpTo(zeroLoopEnd);
|
_context.appendConditionalJumpTo(zeroLoopEnd);
|
||||||
// delete
|
// delete
|
||||||
_context << u256(0);
|
_context << u256(0);
|
||||||
StorageItem(_context, *type).setToZero(SourceLocation(), false);
|
StorageItem(_context, *_type).setToZero(SourceLocation(), false);
|
||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
// increment
|
// increment
|
||||||
_context << type->storageSize() << Instruction::ADD;
|
_context << _type->storageSize() << Instruction::ADD;
|
||||||
_context.appendJumpTo(loopStart);
|
_context.appendJumpTo(loopStart);
|
||||||
// cleanup
|
// cleanup
|
||||||
_context << zeroLoopEnd;
|
_context << zeroLoopEnd;
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
namespace solidity
|
namespace solidity
|
||||||
@ -30,6 +32,7 @@ namespace solidity
|
|||||||
class CompilerContext;
|
class CompilerContext;
|
||||||
class Type;
|
class Type;
|
||||||
class ArrayType;
|
class ArrayType;
|
||||||
|
using TypePointer = std::shared_ptr<Type const>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that provides code generation for handling arrays.
|
* Class that provides code generation for handling arrays.
|
||||||
@ -67,7 +70,7 @@ public:
|
|||||||
/// Appends a loop that clears a sequence of storage slots of the given type (excluding end).
|
/// Appends a loop that clears a sequence of storage slots of the given type (excluding end).
|
||||||
/// Stack pre: end_ref start_ref
|
/// Stack pre: end_ref start_ref
|
||||||
/// Stack post: end_ref
|
/// Stack post: end_ref
|
||||||
void clearStorageLoop(Type const& _type) const;
|
void clearStorageLoop(TypePointer const& _type) const;
|
||||||
/// Converts length to size (number of storage slots or calldata/memory bytes).
|
/// Converts length to size (number of storage slots or calldata/memory bytes).
|
||||||
/// if @a _pad then add padding to multiples of 32 bytes for calldata/memory.
|
/// if @a _pad then add padding to multiples of 32 bytes for calldata/memory.
|
||||||
/// Stack pre: length
|
/// Stack pre: length
|
||||||
|
Loading…
Reference in New Issue
Block a user