From 3287cd464fc6b73ba5da2a94030ab202370f647a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 12 Oct 2015 10:11:58 +0200 Subject: [PATCH] WIP - Expression compiler for array push --- libsolidity/ExpressionCompiler.cpp | 48 ++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index f6eed0de2..c25202b60 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -784,26 +784,42 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) } case Type::Category::Array: { - solAssert(member == "length", "Illegal array member."); auto const& type = dynamic_cast(*_memberAccess.expression().annotation().type); - if (!type.isDynamicallySized()) + if (member == "length") { - utils().popStackElement(type); - m_context << type.length(); + if (!type.isDynamicallySized()) + { + utils().popStackElement(type); + m_context << type.length(); + } + else + switch (type.location()) + { + case DataLocation::CallData: + m_context << eth::Instruction::SWAP1 << eth::Instruction::POP; + break; + case DataLocation::Storage: + setLValue(_memberAccess, type); + break; + case DataLocation::Memory: + m_context << eth::Instruction::MLOAD; + break; + } + } + else if (member == "push" && type.isDynamicallySized() && type.location() == DataLocation::Storage) + { + if (type.isByteArray()) + { + solAssert(!type.isString(), "Index access to string is not allowed."); + setLValue(_indexAccess); + } + else + setLValueToStorageItem(_indexAccess); + setLValue(_memberAccess, type); } else - switch (type.location()) - { - case DataLocation::CallData: - m_context << eth::Instruction::SWAP1 << eth::Instruction::POP; - break; - case DataLocation::Storage: - setLValue(_memberAccess, type); - break; - case DataLocation::Memory: - m_context << eth::Instruction::MLOAD; - break; - } + solAssert(false, "Illegal array member."); + break; } default: