aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-14 02:48:24 +0800
committerchriseth <c@ethdev.com>2015-03-17 01:07:14 +0800
commit02595abf6ac1c30c7c0125c5a705cd2c85974838 (patch)
treeb824309b77c9be95bd81b50e6e4cc6b457b3b9a9 /ExpressionCompiler.cpp
parent7f64584b7fb151459500ade84612d3cd48f13f18 (diff)
downloaddexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.gz
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.bz2
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.lz
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.xz
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.zst
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.zip
Fetch and store packed values.
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index 6f533129..a0a688bb 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -67,9 +67,10 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
length += CompilerUtils(m_context).storeInMemory(length, *paramType, true);
// retrieve the position of the variable
- m_context << m_context.getStorageLocationOfVariable(_varDecl);
- TypePointer returnType = _varDecl.getType();
+ auto const& location = m_context.getStorageLocationOfVariable(_varDecl);
+ m_context << location.first;
+ TypePointer returnType = _varDecl.getType();
for (TypePointer const& paramType: paramTypes)
{
// move offset to memory
@@ -81,7 +82,6 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
returnType = dynamic_cast<MappingType const&>(*returnType).getValueType();
}
- m_context << u256(0); // @todo
unsigned retSizeOnStack = 0;
solAssert(accessorType.getReturnParameterTypes().size() >= 1, "");
if (StructType const* structType = dynamic_cast<StructType const*>(returnType.get()))
@@ -93,21 +93,20 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
{
if (types[i]->getCategory() == Type::Category::Mapping)
continue;
- m_context
- << eth::Instruction::DUP2 << structType->getStorageOffsetOfMember(names[i])
- << eth::Instruction::ADD;
- m_context << u256(0); //@todo
+ pair<u256, unsigned> const& offsets = structType->getStorageOffsetsOfMember(names[i]);
+ m_context << eth::Instruction::DUP1 << u256(offsets.first) << eth::Instruction::ADD << u256(offsets.second);
StorageItem(m_context, *types[i]).retrieveValue(SourceLocation(), true);
solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented.");
- m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
+ m_context << eth::Instruction::SWAP1;
retSizeOnStack += types[i]->getSizeOnStack();
}
- m_context << eth::Instruction::POP << eth::Instruction::POP;
+ m_context << eth::Instruction::POP;
}
else
{
// simple value
solAssert(accessorType.getReturnParameterTypes().size() == 1, "");
+ m_context << u256(location.second);
StorageItem(m_context, *returnType).retrieveValue(SourceLocation(), true);
retSizeOnStack = returnType->getSizeOnStack();
}
@@ -666,10 +665,9 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
case Type::Category::Struct:
{
StructType const& type = dynamic_cast<StructType const&>(*_memberAccess.getExpression().getType());
- m_context << eth::Instruction::POP; //@todo
- m_context << type.getStorageOffsetOfMember(member) << eth::Instruction::ADD;
- //@todo
- m_context << u256(0);
+ m_context << eth::Instruction::POP; // structs always align to new slot
+ pair<u256, unsigned> const& offsets = type.getStorageOffsetsOfMember(member);
+ m_context << offsets.first << eth::Instruction::ADD << u256(offsets.second);
setLValueToStorageItem(_memberAccess);
break;
}