diff options
author | chriseth <c@ethdev.com> | 2015-06-05 17:07:50 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-06-05 20:44:05 +0800 |
commit | f4d1acc563a972ee4f5a44c690cd3fdd1783ae97 (patch) | |
tree | b2814613dff69ffe8f1e14ef6160dcc0902eb3c4 /ArrayUtils.cpp | |
parent | 4987eec3d1e87868e091850d31af58e054ab5ee5 (diff) | |
download | dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.tar.gz dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.tar.zst dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.zip |
Ability to specify the storage location of a reference type.
Diffstat (limited to 'ArrayUtils.cpp')
-rw-r--r-- | ArrayUtils.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/ArrayUtils.cpp b/ArrayUtils.cpp index 79ea4953..531ab8af 100644 --- a/ArrayUtils.cpp +++ b/ArrayUtils.cpp @@ -38,10 +38,10 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons // need to leave "target_ref target_byte_off" on the stack at the end // stack layout: [source_ref] [source_byte_off] [source length] target_ref target_byte_off (top) - solAssert(_targetType.getLocation() == ArrayType::Location::Storage, ""); + solAssert(_targetType.location() == ReferenceType::Location::Storage, ""); solAssert( - _sourceType.getLocation() == ArrayType::Location::CallData || - _sourceType.getLocation() == ArrayType::Location::Storage, + _sourceType.location() == ReferenceType::Location::CallData || + _sourceType.location() == ReferenceType::Location::Storage, "Given array location not implemented." ); @@ -51,7 +51,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons // TODO unroll loop for small sizes - bool sourceIsStorage = _sourceType.getLocation() == ArrayType::Location::Storage; + bool sourceIsStorage = _sourceType.location() == ReferenceType::Location::Storage; bool directCopy = sourceIsStorage && sourceBaseType->isValueType() && *sourceBaseType == *targetBaseType; bool haveByteOffsetSource = !directCopy && sourceIsStorage && sourceBaseType->getStorageBytes() <= 16; bool haveByteOffsetTarget = !directCopy && targetBaseType->getStorageBytes() <= 16; @@ -69,7 +69,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons m_context << eth::Instruction::POP; // stack: target_ref source_ref [source_length] // retrieve source length - if (_sourceType.getLocation() != ArrayType::Location::CallData || !_sourceType.isDynamicallySized()) + if (_sourceType.location() != ReferenceType::Location::CallData || !_sourceType.isDynamicallySized()) retrieveLength(_sourceType); // otherwise, length is already there // stack: target_ref source_ref source_length m_context << eth::Instruction::DUP3; @@ -82,7 +82,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons if (sourceBaseType->getCategory() == Type::Category::Mapping) { solAssert(targetBaseType->getCategory() == Type::Category::Mapping, ""); - solAssert(_sourceType.getLocation() == ArrayType::Location::Storage, ""); + solAssert(_sourceType.location() == ReferenceType::Location::Storage, ""); // nothing to copy m_context << eth::Instruction::POP << eth::Instruction::POP @@ -106,7 +106,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons eth::AssemblyItem copyLoopEndWithoutByteOffset = m_context.newTag(); m_context.appendConditionalJumpTo(copyLoopEndWithoutByteOffset); - if (_sourceType.getLocation() == ArrayType::Location::Storage && _sourceType.isDynamicallySized()) + if (_sourceType.location() == ReferenceType::Location::Storage && _sourceType.isDynamicallySized()) CompilerUtils(m_context).computeHashStatic(); // stack: target_ref target_data_end source_length target_data_pos source_data_pos m_context << eth::Instruction::SWAP2; @@ -155,7 +155,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons // checking is easier. // stack: target_ref target_data_end source_data_pos target_data_pos source_data_end [target_byte_offset] [source_byte_offset] m_context << eth::dupInstruction(3 + byteOffsetSize); - if (_sourceType.getLocation() == ArrayType::Location::Storage) + if (_sourceType.location() == ReferenceType::Location::Storage) { if (haveByteOffsetSource) m_context << eth::Instruction::DUP2; @@ -228,7 +228,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons void ArrayUtils::clearArray(ArrayType const& _type) const { unsigned stackHeightStart = m_context.getStackHeight(); - solAssert(_type.getLocation() == ArrayType::Location::Storage, ""); + solAssert(_type.location() == ReferenceType::Location::Storage, ""); if (_type.getBaseType()->getStorageBytes() < 32) { solAssert(_type.getBaseType()->isValueType(), "Invalid storage size for non-value type."); @@ -283,7 +283,7 @@ void ArrayUtils::clearArray(ArrayType const& _type) const void ArrayUtils::clearDynamicArray(ArrayType const& _type) const { - solAssert(_type.getLocation() == ArrayType::Location::Storage, ""); + solAssert(_type.location() == ReferenceType::Location::Storage, ""); solAssert(_type.isDynamicallySized(), ""); unsigned stackHeightStart = m_context.getStackHeight(); @@ -311,7 +311,7 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const void ArrayUtils::resizeDynamicArray(const ArrayType& _type) const { - solAssert(_type.getLocation() == ArrayType::Location::Storage, ""); + solAssert(_type.location() == ReferenceType::Location::Storage, ""); solAssert(_type.isDynamicallySized(), ""); if (!_type.isByteArray() && _type.getBaseType()->getStorageBytes() < 32) solAssert(_type.getBaseType()->isValueType(), "Invalid storage size for non-value type."); @@ -396,7 +396,7 @@ void ArrayUtils::clearStorageLoop(Type const& _type) const void ArrayUtils::convertLengthToSize(ArrayType const& _arrayType, bool _pad) const { - if (_arrayType.getLocation() == ArrayType::Location::Storage) + if (_arrayType.location() == ReferenceType::Location::Storage) { if (_arrayType.getBaseType()->getStorageSize() <= 1) { @@ -432,15 +432,15 @@ void ArrayUtils::retrieveLength(ArrayType const& _arrayType) const else { m_context << eth::Instruction::DUP1; - switch (_arrayType.getLocation()) + switch (_arrayType.location()) { - case ArrayType::Location::CallData: + case ReferenceType::Location::CallData: // length is stored on the stack break; - case ArrayType::Location::Memory: + case ReferenceType::Location::Memory: m_context << eth::Instruction::MLOAD; break; - case ArrayType::Location::Storage: + case ReferenceType::Location::Storage: m_context << eth::Instruction::SLOAD; break; } @@ -449,16 +449,16 @@ void ArrayUtils::retrieveLength(ArrayType const& _arrayType) const void ArrayUtils::accessIndex(ArrayType const& _arrayType) const { - ArrayType::Location location = _arrayType.getLocation(); + ReferenceType::Location location = _arrayType.location(); eth::Instruction load = - location == ArrayType::Location::Storage ? eth::Instruction::SLOAD : - location == ArrayType::Location::Memory ? eth::Instruction::MLOAD : + location == ReferenceType::Location::Storage ? eth::Instruction::SLOAD : + location == ReferenceType::Location::Memory ? eth::Instruction::MLOAD : eth::Instruction::CALLDATALOAD; // retrieve length if (!_arrayType.isDynamicallySized()) m_context << _arrayType.getLength(); - else if (location == ArrayType::Location::CallData) + else if (location == ReferenceType::Location::CallData) // length is stored on the stack m_context << eth::Instruction::SWAP1; else @@ -473,15 +473,15 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType) const m_context << eth::Instruction::SWAP1; if (_arrayType.isDynamicallySized()) { - if (location == ArrayType::Location::Storage) + if (location == ReferenceType::Location::Storage) CompilerUtils(m_context).computeHashStatic(); - else if (location == ArrayType::Location::Memory) + else if (location == ReferenceType::Location::Memory) m_context << u256(32) << eth::Instruction::ADD; } // stack: <index> <data_ref> switch (location) { - case ArrayType::Location::CallData: + case ReferenceType::Location::CallData: if (!_arrayType.isByteArray()) m_context << eth::Instruction::SWAP1 @@ -496,7 +496,7 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType) const false ); break; - case ArrayType::Location::Storage: + case ReferenceType::Location::Storage: m_context << eth::Instruction::SWAP1; if (_arrayType.getBaseType()->getStorageBytes() <= 16) { @@ -524,7 +524,7 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType) const m_context << eth::Instruction::ADD << u256(0); } break; - case ArrayType::Location::Memory: + case ReferenceType::Location::Memory: solAssert(false, "Memory lvalues not yet implemented."); } } |