Skip to content

Commit

Permalink
Simplify contract lookup in CompileStack
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 18, 2017
1 parent 2ce35b7 commit 8d3cfa8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,15 @@ CompilerStack::Contract const& CompilerStack::contract(string const& _contractNa
{
if (m_contracts.empty())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));

auto it = m_contracts.find(_contractName);
if (it != m_contracts.end())
return it->second;

// To provide a measure of backward-compatibility, if a contract is not located by its
// fully-qualified name, a lookup will be attempted purely on the contract's name to see
// if anything will satisfy.
if (it == m_contracts.end() && _contractName.find(":") == string::npos)
if (_contractName.find(":") == string::npos)
{
for (auto const& contractEntry: m_contracts)
{
Expand All @@ -779,12 +783,13 @@ CompilerStack::Contract const& CompilerStack::contract(string const& _contractNa
string foundName;
getline(ss, source, ':');
getline(ss, foundName, ':');
if (foundName == _contractName) return contractEntry.second;
if (foundName == _contractName)
return contractEntry.second;
}
// If we get here, both lookup methods failed.
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
}
return it->second;

// If we get here, both lookup methods failed.
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract \"" + _contractName + "\" not found."));
}

CompilerStack::Source const& CompilerStack::source(string const& _sourceName) const
Expand Down

0 comments on commit 8d3cfa8

Please sign in to comment.