aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorRhett Aultman <rhett.aultman@meraki.net>2017-01-17 12:47:04 +0800
committerRhett Aultman <rhett.aultman@meraki.net>2017-01-17 12:47:04 +0800
commit94b092d87c051e8846f5d61eaa1a4581b6588c71 (patch)
tree8978ce9b3614a1231d3211829c2da5d4444d2173 /libsolidity
parent88a2ac25e5e10aa7cea8627b60aa663f7ed6066d (diff)
downloaddexon-solidity-94b092d87c051e8846f5d61eaa1a4581b6588c71.tar.gz
dexon-solidity-94b092d87c051e8846f5d61eaa1a4581b6588c71.tar.zst
dexon-solidity-94b092d87c051e8846f5d61eaa1a4581b6588c71.zip
Provide fall-back method for contract lookup
Properly, contracts are now looked up via <source>:<contract> identifiers called "fully qualified names." As a modicum of backward-compatibility, failure on a lookup is now backed up by seeing if the ":" exists at all, and if it doesn't, then the known contracts are scanned for any matching contract name.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/CompilerStack.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index d8bb20d7..262b91ff 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -677,8 +677,25 @@ CompilerStack::Contract const& CompilerStack::contract(string const& _contractNa
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
contractName = contract->fullyQualifiedName();
auto it = m_contracts.find(contractName);
- if (it == m_contracts.end())
+ // 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)
+ {
+ for (auto const& contractEntry: m_contracts)
+ {
+ stringstream ss;
+ ss.str(contractEntry.first);
+ // All entries are <source>:<contract>
+ string source;
+ string foundName;
+ getline(ss, source, ':');
+ getline(ss, foundName, ':');
+ 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;
}