From 24d04087d2ee4e5b2769c4bb69e5629bc1aaeb97 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 7 Oct 2015 15:57:17 +0200 Subject: Resolve binary dependencies properly. --- libsolidity/CompilerStack.cpp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'libsolidity/CompilerStack.cpp') diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index 7d9ca32c..8c1cd8cf 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -170,22 +170,8 @@ bool CompilerStack::compile(bool _optimize, unsigned _runs) map compiledContracts; for (Source const* source: m_sourceOrder) for (ASTPointer const& node: source->ast->nodes()) - if (ContractDefinition* contract = dynamic_cast(node.get())) - { - if (!contract->annotation().isFullyImplemented) - continue; - shared_ptr compiler = make_shared(_optimize, _runs); - compiler->compileContract(*contract, compiledContracts); - Contract& compiledContract = m_contracts.at(contract->name()); - compiledContract.compiler = compiler; - compiledContract.object = compiler->assembledObject(); - compiledContract.runtimeObject = compiler->runtimeObject(); - compiledContracts[compiledContract.contract] = &compiler->assembly(); - - Compiler cloneCompiler(_optimize, _runs); - cloneCompiler.compileClone(*contract, compiledContracts); - compiledContract.cloneObject = cloneCompiler.assembledObject(); - } + if (auto contract = dynamic_cast(node.get())) + compileContract(_optimize, _runs, *contract, compiledContracts); return true; } @@ -375,6 +361,31 @@ void CompilerStack::resolveImports() swap(m_sourceOrder, sourceOrder); } +void CompilerStack::compileContract( + bool _optimize, + unsigned _runs, + ContractDefinition const& _contract, + map& _compiledContracts +) +{ + if (_compiledContracts.count(&_contract) || !_contract.annotation().isFullyImplemented) + return; + for (auto const* dependency: _contract.annotation().contractDependencies) + compileContract(_optimize, _runs, *dependency, _compiledContracts); + + shared_ptr compiler = make_shared(_optimize, _runs); + compiler->compileContract(_contract, _compiledContracts); + Contract& compiledContract = m_contracts.at(_contract.name()); + compiledContract.compiler = compiler; + compiledContract.object = compiler->assembledObject(); + compiledContract.runtimeObject = compiler->runtimeObject(); + _compiledContracts[compiledContract.contract] = &compiler->assembly(); + + Compiler cloneCompiler(_optimize, _runs); + cloneCompiler.compileClone(_contract, _compiledContracts); + compiledContract.cloneObject = cloneCompiler.assembledObject(); +} + std::string CompilerStack::defaultContractName() const { return contract("").contract->name(); -- cgit