diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-10-12 16:11:58 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-10-15 16:52:30 +0800 |
commit | 3287cd464fc6b73ba5da2a94030ab202370f647a (patch) | |
tree | 202ad3536a68427e38425f9884baef67276c0162 /libsolidity | |
parent | 763b544822778110eb23106060ffae5f3d0b6e95 (diff) | |
download | dexon-solidity-3287cd464fc6b73ba5da2a94030ab202370f647a.tar.gz dexon-solidity-3287cd464fc6b73ba5da2a94030ab202370f647a.tar.zst dexon-solidity-3287cd464fc6b73ba5da2a94030ab202370f647a.zip |
WIP - Expression compiler for array push
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ExpressionCompiler.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index f6eed0de..c25202b6 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<ArrayType const&>(*_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<StorageArrayLength>(_memberAccess, type); + break; + case DataLocation::Memory: + m_context << eth::Instruction::MLOAD; + break; + } } - else - switch (type.location()) + else if (member == "push" && type.isDynamicallySized() && type.location() == DataLocation::Storage) + { + if (type.isByteArray()) { - case DataLocation::CallData: - m_context << eth::Instruction::SWAP1 << eth::Instruction::POP; - break; - case DataLocation::Storage: - setLValue<StorageArrayLength>(_memberAccess, type); - break; - case DataLocation::Memory: - m_context << eth::Instruction::MLOAD; - break; + solAssert(!type.isString(), "Index access to string is not allowed."); + setLValue<StorageByteArrayElement>(_indexAccess); } + else + setLValueToStorageItem(_indexAccess); + setLValue<StorageArrayLength>(_memberAccess, type); + } + else + solAssert(false, "Illegal array member."); + break; } default: |