aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-22 04:49:58 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-10-19 06:54:32 +0800
commit2ce35b77becab2395dce218b106a7ce904a1b141 (patch)
treea495989b6c5eabeb1620bc71fef36fad252e6d6c /libsolidity
parent039cc25b1fd875e9f4cfd0f0649f2b4ed67640e1 (diff)
downloaddexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar.gz
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar.bz2
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar.lz
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar.xz
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.tar.zst
dexon-solidity-2ce35b77becab2395dce218b106a7ce904a1b141.zip
Implement CompilerStack.lastContractName()
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/CompilerStack.cpp26
-rw-r--r--libsolidity/interface/CompilerStack.h3
2 files changed, 19 insertions, 10 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index b99fe4ee..8edce879 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -747,22 +747,28 @@ void CompilerStack::compileContract(
}
}
+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
{
if (m_contracts.empty())
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
- string contractName = _contractName;
- if (_contractName.empty())
- // try to find some user-supplied contract
- 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();
- auto it = m_contracts.find(contractName);
+ auto it = m_contracts.find(_contractName);
// 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 (it == m_contracts.end() && _contractName.find(":") == string::npos)
{
for (auto const& contractEntry: m_contracts)
{
@@ -773,7 +779,7 @@ 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."));
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index f992ebc8..b377b3aa 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -168,6 +168,9 @@ public:
/// @returns a list of the contract names in the sources.
std::vector<std::string> contractNames() const;
+ /// @returns the name of the last contract.
+ std::string const lastContractName() const;
+
/// @returns either the contract's name or a mixture of its name and source file, sanitized for filesystem use
std::string const filesystemFriendlyName(std::string const& _contractName) const;