aboutsummaryrefslogtreecommitdiffstats
path: root/CompilerStack.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-18 01:33:55 +0800
committerChristian <c@ethdev.com>2014-12-18 01:37:06 +0800
commita98afc8eaa20146359dd212fc2eb0bd0fe18d893 (patch)
tree4940858db88efe5b3f9db42c16bb59d4036abcbb /CompilerStack.cpp
parent5a1a83ff42b97f85e06c54c7d5fe7db2f8239e5a (diff)
downloaddexon-solidity-a98afc8eaa20146359dd212fc2eb0bd0fe18d893.tar.gz
dexon-solidity-a98afc8eaa20146359dd212fc2eb0bd0fe18d893.tar.zst
dexon-solidity-a98afc8eaa20146359dd212fc2eb0bd0fe18d893.zip
Return the last contract by default.
Diffstat (limited to 'CompilerStack.cpp')
-rw-r--r--CompilerStack.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp
index 1242c0ab..9fdc88ba 100644
--- a/CompilerStack.cpp
+++ b/CompilerStack.cpp
@@ -234,9 +234,13 @@ CompilerStack::Contract const& CompilerStack::getContract(string const& _contrac
{
if (m_contracts.empty())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
+ string contractName = _contractName;
if (_contractName.empty())
- return m_contracts.begin()->second;
- auto it = m_contracts.find(_contractName);
+ // try to find the "last contract"
+ for (ASTPointer<ASTNode> const& node: m_sourceOrder.back()->ast->getNodes())
+ if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
+ contractName = contract->getName();
+ auto it = m_contracts.find(contractName);
if (it == m_contracts.end())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
return it->second;