diff options
author | Liana Husikyan <liana@ethdev.com> | 2015-02-17 23:21:38 +0800 |
---|---|---|
committer | Liana Husikyan <liana@ethdev.com> | 2015-02-21 05:50:34 +0800 |
commit | 52050201e39b823ea9e6133e47c7e9e779dc1f07 (patch) | |
tree | bf415cf6c45a0f6ee9468849c5c708217f366260 /ExpressionCompiler.cpp | |
parent | 26132363d5a11d762224cc7c8acc6b8c854cf646 (diff) | |
download | dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.gz dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.zst dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.zip |
Inline member initialisation
renamed VariableDefinition class to VariableDeclarationStatement
added tests
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r-- | ExpressionCompiler.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index a8bc53e0..74dfb2b5 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -56,6 +56,19 @@ void ExpressionCompiler::appendStateVariableAccessor(CompilerContext& _context, compiler.appendStateVariableAccessor(_varDecl); } +void ExpressionCompiler::appendStateVariableInitialization(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize) +{ + ExpressionCompiler compiler(_context, _optimize); + compiler.appendStateVariableInitialization(_varDecl); +} + +void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration const& _varDecl) +{ + m_currentLValue.fromStateVariable(_varDecl); + m_currentLValue.storeValue(*_varDecl.getType(), _varDecl.getLocation()); + m_currentLValue.reset(); +} + bool ExpressionCompiler::visit(Assignment const& _assignment) { _assignment.getRightHandSide().accept(*this); @@ -77,7 +90,6 @@ bool ExpressionCompiler::visit(Assignment const& _assignment) } m_currentLValue.storeValue(*_assignment.getRightHandSide().getType(), _assignment.getLocation()); m_currentLValue.reset(); - return false; } @@ -1018,12 +1030,24 @@ void ExpressionCompiler::LValue::fromIdentifier(Identifier const& _identifier, D m_dataType = _identifier.getType(); solAssert(m_dataType->getStorageSize() <= numeric_limits<unsigned>::max(), "The storage size of " + m_dataType->toString() + " should fit in an unsigned"); - m_size = unsigned(m_dataType->getStorageSize()); } + m_size = unsigned(m_dataType->getStorageSize()); + } else BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_identifier.getLocation()) << errinfo_comment("Identifier type not supported or identifier not found.")); } +void ExpressionCompiler::LValue::fromStateVariable(VariableDeclaration const& _declaration) +{ + solAssert(m_context->isStateVariable(&_declaration), "Not a state variable."); + *m_context << m_context->getStorageLocationOfVariable(_declaration); + m_type = LValueType::Storage; + m_dataType = _declaration.getType(); + solAssert(m_dataType->getStorageSize() <= numeric_limits<unsigned>::max(), + "The storage size of " + m_dataType->toString() + " should fit in an unsigned"); + m_size = unsigned(m_dataType->getStorageSize()); +} + void ExpressionCompiler::LValue::retrieveValue(Location const& _location, bool _remove) const { switch (m_type) @@ -1117,7 +1141,7 @@ void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, Location co } else { - solAssert(_sourceType.getCategory() == m_dataType->getCategory(), ""); + solAssert(_sourceType.getCategory() == m_dataType->getCategory(), "Wrong type conversation for assignment."); if (m_dataType->getCategory() == Type::Category::ByteArray) { CompilerUtils(*m_context).copyByteArrayToStorage( |