diff options
author | Leonardo Alt <leo@ethereum.org> | 2018-05-03 22:40:33 +0800 |
---|---|---|
committer | Leonardo Alt <leo@ethereum.org> | 2018-07-11 00:39:38 +0800 |
commit | 1f77deada1abc9ca1e635ab13d45707e852a5628 (patch) | |
tree | 54a8b70a13e8e029a88bdc07cde19dc877ca4fc4 /libsolidity/codegen/ContractCompiler.h | |
parent | 0e9415bc31fa379b2c6cc8c8dba6b6ba1305391b (diff) | |
download | dexon-solidity-1f77deada1abc9ca1e635ab13d45707e852a5628.tar.gz dexon-solidity-1f77deada1abc9ca1e635ab13d45707e852a5628.tar.zst dexon-solidity-1f77deada1abc9ca1e635ab13d45707e852a5628.zip |
[050] Reserving and popping local vars in their scope
Diffstat (limited to 'libsolidity/codegen/ContractCompiler.h')
-rw-r--r-- | libsolidity/codegen/ContractCompiler.h | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/libsolidity/codegen/ContractCompiler.h b/libsolidity/codegen/ContractCompiler.h index 02a3452f..72f46495 100644 --- a/libsolidity/codegen/ContractCompiler.h +++ b/libsolidity/codegen/ContractCompiler.h @@ -109,6 +109,8 @@ private: virtual bool visit(VariableDeclarationStatement const& _variableDeclarationStatement) override; virtual bool visit(ExpressionStatement const& _expressionStatement) override; virtual bool visit(PlaceholderStatement const&) override; + virtual bool visit(Block const& _block) override; + virtual void endVisit(Block const& _block) override; /// Repeatedly visits all function which are referenced but which are not compiled yet. void appendMissingFunctions(); @@ -123,19 +125,35 @@ private: /// @returns the runtime assembly for clone contracts. eth::AssemblyPointer cloneRuntime() const; + /// Frees the variables of a certain scope (to be used when leaving). + void popScopedVariables(ASTNode const* _node); + + /// Pops _amount slots from the stack and jumps to _jumpTo. + /// Also readjusts the stack offset to the original value. + void popAndJump(unsigned _amount, eth::AssemblyItem const& _jumpTo); + + /// Sets the stack height for the visited loop. + void visitLoop(BreakableStatement const* _loop); + bool const m_optimise; /// Pointer to the runtime compiler in case this is a creation compiler. ContractCompiler* m_runtimeCompiler = nullptr; CompilerContext& m_context; - std::vector<eth::AssemblyItem> m_breakTags; ///< tag to jump to for a "break" statement - std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement - /// Tag to jump to for a "return" statement, needs to be stacked because of modifiers. - std::vector<eth::AssemblyItem> m_returnTags; + /// Tag to jump to for a "break" statement and the stack height after freeing the local loop variables. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_breakTags; + /// Tag to jump to for a "continue" statement and the stack height after freeing the local loop variables. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_continueTags; + /// Tag to jump to for a "return" statement and the stack height after freeing the local function or modifier variables. + /// Needs to be stacked because of modifiers. + std::vector<std::pair<eth::AssemblyItem, unsigned>> m_returnTags; unsigned m_modifierDepth = 0; FunctionDefinition const* m_currentFunction = nullptr; - unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag + // arguments for base constructors, filled in derived-to-base order std::map<FunctionDefinition const*, ASTNode const*> const* m_baseArguments; + + /// Stores the variables that were declared inside a specific scope, for each modifier depth. + std::map<unsigned, std::map<ASTNode const*, unsigned>> m_scopeStackHeight; }; } |