aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-10-15 19:54:59 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-10-15 19:54:59 +0800
commit9224c1f7128f92f47ddf3feaf83b57d6d98e0a04 (patch)
treec6d94f12a23b771a388994b01f034a04f338eb01
parenta521843f6b0bf019a19d9a377f4bbbc473083151 (diff)
downloaddexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar.gz
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar.bz2
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar.lz
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar.xz
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.tar.zst
dexon-solidity-9224c1f7128f92f47ddf3feaf83b57d6d98e0a04.zip
Working implementation of arraypush
ByteArrayPush() gets a test but is ignored for now, since there are still some issues with its implementation
-rw-r--r--libsolidity/ExpressionCompiler.cpp22
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp23
2 files changed, 31 insertions, 14 deletions
diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp
index 5ff1363f..2d3126c8 100644
--- a/libsolidity/ExpressionCompiler.cpp
+++ b/libsolidity/ExpressionCompiler.cpp
@@ -623,27 +623,29 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
appendExternalFunctionCall(function, arguments);
break;
}
+ case Location::ByteArrayPush:
+ solAssert(false, "Not properly implemented yet");
case Location::ArrayPush:
{
- cout << "Beginning " << m_context.stackHeight() << endl;
+ _functionCall.expression().accept(*this);
solAssert(function.parameterTypes().size() == 1, "");
solAssert(!!function.parameterTypes()[0], "");
TypePointer const& paramType = function.parameterTypes()[0];
- ArrayType arrayType(DataLocation::Storage, paramType);
+ shared_ptr<ArrayType> arrayType =
+ function.location() == Location::ArrayPush ?
+ make_shared<ArrayType>(DataLocation::Storage, paramType) :
+ make_shared<ArrayType>(DataLocation::Storage);
// get the current length
- ArrayUtils(m_context).retrieveLength(arrayType);
+ ArrayUtils(m_context).retrieveLength(*arrayType);
m_context << eth::Instruction::DUP1;
- cout << "After DUP1 " << m_context.stackHeight() << endl;
// stack: ArrayReference currentLength currentLength
m_context << u256(1) << eth::Instruction::ADD;
// stack: ArrayReference currentLength newLength
m_context << eth::Instruction::DUP3 << eth::Instruction::DUP2;
- ArrayUtils(m_context).resizeDynamicArray(arrayType);
- cout << "After Resize Dynamic Array " << m_context.stackHeight() << endl;
+ ArrayUtils(m_context).resizeDynamicArray(*arrayType);
m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
// stack: newLength ArrayReference oldLength
- ArrayUtils(m_context).accessIndex(arrayType, false);
- cout << "After Access Index " << m_context.stackHeight() << endl;
+ ArrayUtils(m_context).accessIndex(*arrayType, false);
// stack: newLength storageSlot slotOffset
arguments[0]->accept(*this);
@@ -657,9 +659,6 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
StorageItem(m_context, *paramType).storeValue(*type, _functionCall.location(), true);
break;
}
- case Location::ByteArrayPush:
- // TODO
- break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
}
@@ -852,7 +851,6 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
}
else
solAssert(false, "Illegal array member.");
-
break;
}
default:
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 7ae97db2..96a426dd 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3493,9 +3493,28 @@ BOOST_AUTO_TEST_CASE(array_push)
}
)";
compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 2));
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3));
}
-
+#if 0 // reactivate once ByteArrayPush is properly implemented
+BOOST_AUTO_TEST_CASE(byte_array_push)
+{
+ char const* sourceCode = R"(
+ contract c {
+ bytes data;
+ function test() returns (byte x, byte y, byte z, uint l) {
+ data.push(5);
+ x = data[0];
+ data.push(4);
+ y = data[1];
+ l = data.push(3);
+ z = data[2];
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3));
+}
+#endif
BOOST_AUTO_TEST_CASE(external_array_args)
{
char const* sourceCode = R"(