aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-01-24 19:06:11 +0800
committerchriseth <c@ethdev.com>2017-01-24 19:07:09 +0800
commit23eca813f578463383afd37b76ce49d87f79c811 (patch)
treecb3939091bcc7a9dba953a8e7f1588924ebeb7ca
parent1b87e08e046b786b9c85c08696c72ed162f5f9a1 (diff)
downloaddexon-solidity-23eca813f578463383afd37b76ce49d87f79c811.tar.gz
dexon-solidity-23eca813f578463383afd37b76ce49d87f79c811.tar.zst
dexon-solidity-23eca813f578463383afd37b76ce49d87f79c811.zip
Change clearStorageLoop to TypePointer.
-rw-r--r--libsolidity/codegen/ArrayUtils.cpp29
-rw-r--r--libsolidity/codegen/ArrayUtils.h5
2 files changed, 18 insertions, 16 deletions
diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp
index 0b09cc1a..4d100d1d 100644
--- a/libsolidity/codegen/ArrayUtils.cpp
+++ b/libsolidity/codegen/ArrayUtils.cpp
@@ -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
_context << Instruction::POP << Instruction::SWAP1 << Instruction::POP;
// stack: target_ref target_data_end target_data_pos_updated
- utils.clearStorageLoop(*targetBaseType);
+ utils.clearStorageLoop(targetBaseType);
_context << Instruction::POP;
}
);
@@ -572,9 +572,9 @@ void ArrayUtils::clearArray(ArrayType const& _typeIn) const
ArrayUtils(_context).convertLengthToSize(_type);
_context << Instruction::ADD << Instruction::SWAP1;
if (_type.baseType()->storageBytes() < 32)
- ArrayUtils(_context).clearStorageLoop(*make_shared<IntegerType>(256));
+ ArrayUtils(_context).clearStorageLoop(make_shared<IntegerType>(256));
else
- ArrayUtils(_context).clearStorageLoop(*_type.baseType());
+ ArrayUtils(_context).clearStorageLoop(_type.baseType());
_context << Instruction::POP;
}
solAssert(_context.stackHeight() == stackHeightStart - 2, "");
@@ -613,9 +613,9 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
<< Instruction::SWAP1;
// stack: data_pos_end data_pos
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
- clearStorageLoop(*make_shared<IntegerType>(256));
+ clearStorageLoop(make_shared<IntegerType>(256));
else
- clearStorageLoop(*_type.baseType());
+ clearStorageLoop(_type.baseType());
// cleanup
m_context << endTag;
m_context << Instruction::POP;
@@ -720,7 +720,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
ArrayUtils(_context).convertLengthToSize(_type);
_context << Instruction::DUP2 << Instruction::ADD << Instruction::SWAP1;
// 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;
// stack: ref new_length current_length first_word
solAssert(_context.stackHeight() - stackHeightStart == 4 - 2, "3");
@@ -759,9 +759,9 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
_context << Instruction::SWAP2 << Instruction::ADD;
// stack: ref new_length delete_end delete_start
if (_type.isByteArray() || _type.baseType()->storageBytes() < 32)
- ArrayUtils(_context).clearStorageLoop(*make_shared<IntegerType>(256));
+ ArrayUtils(_context).clearStorageLoop(make_shared<IntegerType>(256));
else
- ArrayUtils(_context).clearStorageLoop(*_type.baseType());
+ ArrayUtils(_context).clearStorageLoop(_type.baseType());
_context << resizeEnd;
// 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(
- "$clearStorageLoop_" + _type.identifier(),
+ "$clearStorageLoop_" + _type->identifier(),
2,
1,
- [type](CompilerContext& _context)
+ [_type](CompilerContext& _context)
{
unsigned stackHeightStart = _context.stackHeight();
- if (type->category() == Type::Category::Mapping)
+ if (_type->category() == Type::Category::Mapping)
{
_context << Instruction::POP;
return;
@@ -802,10 +801,10 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const
_context.appendConditionalJumpTo(zeroLoopEnd);
// delete
_context << u256(0);
- StorageItem(_context, *type).setToZero(SourceLocation(), false);
+ StorageItem(_context, *_type).setToZero(SourceLocation(), false);
_context << Instruction::POP;
// increment
- _context << type->storageSize() << Instruction::ADD;
+ _context << _type->storageSize() << Instruction::ADD;
_context.appendJumpTo(loopStart);
// cleanup
_context << zeroLoopEnd;
diff --git a/libsolidity/codegen/ArrayUtils.h b/libsolidity/codegen/ArrayUtils.h
index d0ba2892..806fbea7 100644
--- a/libsolidity/codegen/ArrayUtils.h
+++ b/libsolidity/codegen/ArrayUtils.h
@@ -22,6 +22,8 @@
#pragma once
+#include <memory>
+
namespace dev
{
namespace solidity
@@ -30,6 +32,7 @@ namespace solidity
class CompilerContext;
class Type;
class ArrayType;
+using TypePointer = std::shared_ptr<Type const>;
/**
* 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).
/// Stack pre: end_ref start_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).
/// if @a _pad then add padding to multiples of 32 bytes for calldata/memory.
/// Stack pre: length