Move lastContractName closer to contractNames

This commit is contained in:
Alex Beregszaszi 2018-08-06 13:00:21 +01:00
parent 5778af07a3
commit be70703f82

View File

@ -353,6 +353,19 @@ vector<string> CompilerStack::contractNames() const
return contractNames; return contractNames;
} }
string const CompilerStack::lastContractName() const
{
if (m_contracts.empty())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
// try to find some user-supplied contract
string contractName;
for (auto const& it: m_sources)
for (ASTPointer<ASTNode> const& node: it.second.ast->nodes())
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
contractName = contract->fullyQualifiedName();
return contractName;
}
eth::AssemblyItems const* CompilerStack::assemblyItems(string const& _contractName) const eth::AssemblyItems const* CompilerStack::assemblyItems(string const& _contractName) const
{ {
Contract const& currentContract = contract(_contractName); Contract const& currentContract = contract(_contractName);
@ -760,19 +773,6 @@ void CompilerStack::compileContract(
_compiledContracts[compiledContract.contract] = &compiler->assembly(); _compiledContracts[compiledContract.contract] = &compiler->assembly();
} }
string const CompilerStack::lastContractName() const
{
if (m_contracts.empty())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
// try to find some user-supplied contract
string contractName;
for (auto const& it: m_sources)
for (ASTPointer<ASTNode> const& node: it.second.ast->nodes())
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
contractName = contract->fullyQualifiedName();
return contractName;
}
CompilerStack::Contract const& CompilerStack::contract(string const& _contractName) const CompilerStack::Contract const& CompilerStack::contract(string const& _contractName) const
{ {
if (m_contracts.empty()) if (m_contracts.empty())