From 3e5c9a74b277aadf619aed9a41cc6936d64297b1 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 24 Feb 2015 12:08:51 +0100 Subject: [PATCH] Reset CompilerContext's visited nodes at compile start --- Compiler.cpp | 1 + CompilerContext.cpp | 7 +++++++ CompilerContext.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/Compiler.cpp b/Compiler.cpp index 7b79959c9..e4a5c4f0d 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -74,6 +74,7 @@ void Compiler::initializeContext(ContractDefinition const& _contract, m_context.setCompiledContracts(_contracts); m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts()); registerStateVariables(_contract); + m_context.resetVisitedNodes(&_contract); } void Compiler::packIntoContractCreator(ContractDefinition const& _contract, CompilerContext const& _runtimeContext) diff --git a/CompilerContext.cpp b/CompilerContext.cpp index c599be5ef..67a367240 100644 --- a/CompilerContext.cpp +++ b/CompilerContext.cpp @@ -166,6 +166,13 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati return it->second; } +void CompilerContext::resetVisitedNodes(ASTNode const* _node) +{ + stack newStack; + newStack.push(_node); + std::swap(m_visitedNodes, newStack); +} + CompilerContext& CompilerContext::operator<<(eth::AssemblyItem _item) { solAssert(m_visitedNodes.size() > 0, "No node on the visited stack"); diff --git a/CompilerContext.h b/CompilerContext.h index c07d9fb2f..6ee52a5b0 100644 --- a/CompilerContext.h +++ b/CompilerContext.h @@ -100,6 +100,8 @@ public: void appendProgramSize() { return m_asm.appendProgramSize(); } /// Adds data to the data section, pushes a reference to the stack eth::AssemblyItem appendData(bytes const& _data) { return m_asm.append(_data); } + /// Resets the stack of visited nodes with a new stack having only @c _node + void resetVisitedNodes(ASTNode const* _node); /// Pops the stack of visited nodes void popVisitedNodes() { m_visitedNodes.pop();} /// Pushes an ASTNode to the stack of visited nodes