From fb1cf35f3b624b01c56cca4cb1f919134a34082e Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 1 Apr 2015 14:22:42 +0200 Subject: added implementation to append code for State variable accessor fixed tests --- ExpressionCompiler.cpp | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'ExpressionCompiler.cpp') diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 30cc3c6f..92fca636 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -60,43 +60,37 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& CompilerContext::LocationSetter locationSetter(m_context, _varDecl); FunctionType accessorType(_varDecl); - unsigned length = 0; TypePointers const& paramTypes = accessorType.getParameterTypes(); - // to exclude the last key if it is an array - TypePointer finalMappingValueType = _varDecl.getType(); - while (finalMappingValueType->getCategory() == Type::Category::Mapping) - finalMappingValueType = dynamic_cast(*finalMappingValueType).getValueType(); - - bool finalIsArrayType = finalMappingValueType->getCategory() == Type::Category::Array; - TypePointers mappingKeys(paramTypes); - if (finalIsArrayType) - mappingKeys.pop_back(); - - // move mapping arguments to memory - for (TypePointer const& paramType: boost::adaptors::reverse(mappingKeys)) - length += CompilerUtils(m_context).storeInMemory(length, *paramType, true); - // retrieve the position of the variable auto const& location = m_context.getStorageLocationOfVariable(_varDecl); m_context << location.first; TypePointer returnType = _varDecl.getType(); - for (TypePointer const& paramType: mappingKeys) - { - // move offset to memory - CompilerUtils(m_context).storeInMemory(length); - unsigned argLen = paramType->getCalldataEncodedSize(); - length -= argLen; - m_context << u256(argLen + 32) << u256(length) << eth::Instruction::SHA3; - - returnType = dynamic_cast(*returnType).getValueType(); - } - if (finalMappingValueType->isDynamicallySized()) + for (size_t i = 0; i < paramTypes.size(); ++i) { - + if (auto mappingType = dynamic_cast(returnType.get())) + { + // move storage offset to memory. + CompilerUtils(m_context).storeInMemory(32); + //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; + returnType = mappingType->getValueType(); + } + else if (auto arrayType = dynamic_cast(returnType.get())) + { + CompilerUtils(m_context).copyToStackTop(paramTypes.size() - i + 1, 1); + ArrayUtils(m_context).accessIndex(*arrayType); + returnType = arrayType->getBaseType(); + } + else + solAssert(false, "Index access is allowed only for \"mapping\" and \"array\" types."); } + //remove index arguments. + CompilerUtils(m_context).popStackSlots(paramTypes.size()); unsigned retSizeOnStack = 0; solAssert(accessorType.getReturnParameterTypes().size() >= 1, ""); -- cgit