From 561e461ded32f4e3c3ccd0514e9022d06dc816e1 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 26 Mar 2015 12:22:49 +0100 Subject: [PATCH] added createing FunctionType from ArrayType VariableDeclaration added test --- libsolidity/ExpressionCompiler.cpp | 20 ++++++++++++-------- libsolidity/Types.cpp | 17 +++++++++++------ test/SolidityEndToEndTest.cpp | 13 +++++++++++++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index daea21623..59781f821 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -71,16 +71,20 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& m_context << location.first; TypePointer returnType = _varDecl.getType(); - for (TypePointer const& paramType: paramTypes) + if (ArrayType const* arrayType = dynamic_cast(returnType.get())) { - // 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; + (void)arrayType; + } else + for (TypePointer const& paramType: paramTypes) + { + // 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(); - } + returnType = dynamic_cast(*returnType).getValueType(); + } unsigned retSizeOnStack = 0; solAssert(accessorType.getReturnParameterTypes().size() >= 1, ""); diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 78649cc95..0c80a0f7d 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -1002,12 +1002,17 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): retParamNames.push_back(member.first); retParams.push_back(member.second); } - } - else - { - retParams.push_back(returnType); - retParamNames.push_back(""); - } + } else + if (auto arrayType = dynamic_cast(returnType.get())) + { + params.push_back(make_shared(256)); + paramNames.push_back(""); + returnType = arrayType->getBaseType(); + } else + { + retParams.push_back(returnType); + retParamNames.push_back(""); + } swap(params, m_parameterTypes); swap(paramNames, m_parameterNames); diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index b169263da..3c4c2bc0e 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -966,6 +966,19 @@ BOOST_AUTO_TEST_CASE(simple_accessor) BOOST_CHECK(callContractFunction("data()") == encodeArgs(8)); } +BOOST_AUTO_TEST_CASE(array_accessor) +{ + char const* sourceCode = R"( + contract test { + uint[8] datas; + function test() { + datas[2] = 8; + } + })"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("data(2)") == encodeArgs(8)); +} + BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) { char const* sourceCode = "contract test {\n"