diff options
author | Christian <c@ethdev.com> | 2014-11-07 09:06:37 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-08 03:02:57 +0800 |
commit | 64a4d77c8b8c559c6e9aad712f7288e4f107e946 (patch) | |
tree | 59a8bef45a09ac9b1682bf213886f713a12468c4 /CompilerContext.cpp | |
parent | 4c8e670530675c7b7774b0d5355ee9aadd92f3a2 (diff) | |
download | dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.gz dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.bz2 dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.lz dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.xz dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.tar.zst dexon-solidity-64a4d77c8b8c559c6e9aad712f7288e4f107e946.zip |
State variables.
Diffstat (limited to 'CompilerContext.cpp')
-rw-r--r-- | CompilerContext.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/CompilerContext.cpp b/CompilerContext.cpp index 99cf090e..3c1acdfa 100644 --- a/CompilerContext.cpp +++ b/CompilerContext.cpp @@ -30,6 +30,12 @@ using namespace std; namespace dev { namespace solidity { +void CompilerContext::addStateVariable(VariableDeclaration const& _declaration) +{ + m_stateVariables[&_declaration] = m_stateVariablesSize; + m_stateVariablesSize += _declaration.getType()->getStorageSize(); +} + void CompilerContext::initializeLocalVariables(unsigned _numVariables) { if (_numVariables > 0) @@ -41,12 +47,9 @@ void CompilerContext::initializeLocalVariables(unsigned _numVariables) } } -int CompilerContext::getStackPositionOfVariable(Declaration const& _declaration) +bool CompilerContext::isLocalVariable(Declaration const* _declaration) const { - auto res = find(begin(m_localVariables), end(m_localVariables), &_declaration); - if (asserts(res != m_localVariables.end())) - BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Variable not found on stack.")); - return end(m_localVariables) - res - 1 + m_asm.deposit(); + return std::find(m_localVariables.begin(), m_localVariables.end(), _declaration) != m_localVariables.end(); } eth::AssemblyItem CompilerContext::getFunctionEntryLabel(FunctionDefinition const& _function) const @@ -57,5 +60,28 @@ eth::AssemblyItem CompilerContext::getFunctionEntryLabel(FunctionDefinition cons return res->second.tag(); } +unsigned CompilerContext::getBaseStackOffsetOfVariable(Declaration const& _declaration) const +{ + auto res = find(begin(m_localVariables), end(m_localVariables), &_declaration); + if (asserts(res != m_localVariables.end())) + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Variable not found on stack.")); + return unsigned(end(m_localVariables) - res - 1); +} + +unsigned CompilerContext::baseToCurrentStackOffset(unsigned _baseOffset) const +{ + return _baseOffset + m_asm.deposit(); +} + +u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declaration) const +{ + auto it = m_stateVariables.find(&_declaration); + if (it == m_stateVariables.end()) + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Variable not found in storage.")); + return it->second; +} + + + } } |