diff options
author | Liana Husikyan <liana@ethdev.com> | 2015-04-02 23:03:02 +0800 |
---|---|---|
committer | Liana Husikyan <liana@ethdev.com> | 2015-04-08 21:56:36 +0800 |
commit | 6f38bfeb6c66122ed31d744caad3577e4b4653d5 (patch) | |
tree | bb2eeefa8ac9d004b1b979bf0856da2409c7d558 /ExpressionCompiler.cpp | |
parent | fb1cf35f3b624b01c56cca4cb1f919134a34082e (diff) | |
download | dexon-solidity-6f38bfeb6c66122ed31d744caad3577e4b4653d5.tar.gz dexon-solidity-6f38bfeb6c66122ed31d744caad3577e4b4653d5.tar.zst dexon-solidity-6f38bfeb6c66122ed31d744caad3577e4b4653d5.zip |
fixes
added more tests
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r-- | ExpressionCompiler.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 92fca636..dcfb6e17 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -64,7 +64,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& // retrieve the position of the variable auto const& location = m_context.getStorageLocationOfVariable(_varDecl); - m_context << location.first; + m_context << location.first << u256(location.second); TypePointer returnType = _varDecl.getType(); @@ -72,16 +72,22 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& { if (auto mappingType = dynamic_cast<MappingType const*>(returnType.get())) { + // pop offset + m_context << eth::Instruction::POP; // move storage offset to memory. CompilerUtils(m_context).storeInMemory(32); - //move key to memory. + // move key to memory. CompilerUtils(m_context).copyToStackTop(paramTypes.size() - i, 1); CompilerUtils(m_context).storeInMemory(0); m_context << u256(64) << u256(0) << eth::Instruction::SHA3; + // push offset + m_context << u256(0); returnType = mappingType->getValueType(); } else if (auto arrayType = dynamic_cast<ArrayType const*>(returnType.get())) { + // pop offset + m_context << eth::Instruction::POP; CompilerUtils(m_context).copyToStackTop(paramTypes.size() - i + 1, 1); ArrayUtils(m_context).accessIndex(*arrayType); returnType = arrayType->getBaseType(); @@ -89,19 +95,28 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& else solAssert(false, "Index access is allowed only for \"mapping\" and \"array\" types."); } - //remove index arguments. - CompilerUtils(m_context).popStackSlots(paramTypes.size()); - + // remove index arguments. + if (paramTypes.size() == 1) + m_context << eth::Instruction::SWAP2 << eth::Instruction::POP << eth::Instruction::SWAP1; + else if (paramTypes.size() >= 2) + { + m_context << eth::swapInstruction(paramTypes.size()); + m_context << eth::Instruction::POP; + m_context << eth::swapInstruction(paramTypes.size()); + CompilerUtils(m_context).popStackSlots(paramTypes.size() - 1); + } unsigned retSizeOnStack = 0; solAssert(accessorType.getReturnParameterTypes().size() >= 1, ""); if (StructType const* structType = dynamic_cast<StructType const*>(returnType.get())) { + // remove offset + m_context << eth::Instruction::POP; auto const& names = accessorType.getReturnParameterNames(); auto const& types = accessorType.getReturnParameterTypes(); // struct for (size_t i = 0; i < names.size(); ++i) { - if (types[i]->getCategory() == Type::Category::Mapping) + if (types[i]->getCategory() == Type::Category::Mapping || types[i]->getCategory() == Type::Category::Array) continue; pair<u256, unsigned> const& offsets = structType->getStorageOffsetsOfMember(names[i]); m_context << eth::Instruction::DUP1 << u256(offsets.first) << eth::Instruction::ADD << u256(offsets.second); @@ -110,13 +125,13 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& m_context << eth::Instruction::SWAP1; retSizeOnStack += types[i]->getSizeOnStack(); } + // remove slot m_context << eth::Instruction::POP; } else { // simple value solAssert(accessorType.getReturnParameterTypes().size() == 1, ""); - m_context << u256(location.second); StorageItem(m_context, *returnType).retrieveValue(SourceLocation(), true); retSizeOnStack = returnType->getSizeOnStack(); } |