Browse Source

Reset CompilerContext's visited nodes at compile start

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
45ef19046b
  1. 1
      libsolidity/Compiler.cpp
  2. 7
      libsolidity/CompilerContext.cpp
  3. 2
      libsolidity/CompilerContext.h
  4. 1
      test/SolidityExpressionCompiler.cpp

1
libsolidity/Compiler.cpp

@ -74,6 +74,7 @@ void Compiler::initializeContext(ContractDefinition const& _contract,
m_context.setCompiledContracts(_contracts); m_context.setCompiledContracts(_contracts);
m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts()); m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts());
registerStateVariables(_contract); registerStateVariables(_contract);
m_context.resetVisitedNodes(&_contract);
} }
void Compiler::packIntoContractCreator(ContractDefinition const& _contract, CompilerContext const& _runtimeContext) void Compiler::packIntoContractCreator(ContractDefinition const& _contract, CompilerContext const& _runtimeContext)

7
libsolidity/CompilerContext.cpp

@ -166,6 +166,13 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati
return it->second; return it->second;
} }
void CompilerContext::resetVisitedNodes(ASTNode const* _node)
{
stack<ASTNode const*> newStack;
newStack.push(_node);
std::swap(m_visitedNodes, newStack);
}
CompilerContext& CompilerContext::operator<<(eth::AssemblyItem _item) CompilerContext& CompilerContext::operator<<(eth::AssemblyItem _item)
{ {
solAssert(m_visitedNodes.size() > 0, "No node on the visited stack"); solAssert(m_visitedNodes.size() > 0, "No node on the visited stack");

2
libsolidity/CompilerContext.h

@ -100,6 +100,8 @@ public:
void appendProgramSize() { return m_asm.appendProgramSize(); } void appendProgramSize() { return m_asm.appendProgramSize(); }
/// Adds data to the data section, pushes a reference to the stack /// Adds data to the data section, pushes a reference to the stack
eth::AssemblyItem appendData(bytes const& _data) { return m_asm.append(_data); } 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 /// Pops the stack of visited nodes
void popVisitedNodes() { m_visitedNodes.pop();} void popVisitedNodes() { m_visitedNodes.pop();}
/// Pushes an ASTNode to the stack of visited nodes /// Pushes an ASTNode to the stack of visited nodes

1
test/SolidityExpressionCompiler.cpp

@ -127,6 +127,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
BOOST_REQUIRE(extractor.getExpression() != nullptr); BOOST_REQUIRE(extractor.getExpression() != nullptr);
CompilerContext context; CompilerContext context;
context.resetVisitedNodes(contract);
context.setInheritanceHierarchy(inheritanceHierarchy); context.setInheritanceHierarchy(inheritanceHierarchy);
unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack
context.adjustStackOffset(parametersSize); context.adjustStackOffset(parametersSize);

Loading…
Cancel
Save