aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-19 19:43:17 +0800
committerGitHub <noreply@github.com>2017-10-19 19:43:17 +0800
commit4e7d1440ab84ba0566c7c75ff61b2f9e70738ef4 (patch)
treef4983ffe53f5c63478c682219f6cfae221493cd6 /libsolidity
parentb96602122c2380b1759a8f657a9b97e30c5978b0 (diff)
parent8d3cfa8cff85b1aed7c1b77a0886a58b09144a36 (diff)
downloaddexon-solidity-4e7d1440ab84ba0566c7c75ff61b2f9e70738ef4.tar.gz
dexon-solidity-4e7d1440ab84ba0566c7c75ff61b2f9e70738ef4.tar.zst
dexon-solidity-4e7d1440ab84ba0566c7c75ff61b2f9e70738ef4.zip
Merge pull request #3101 from ethereum/compilerstack-header
Remove the reliance on empty contract name equals "last contract" in CompilerStack
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/CompilerStack.cpp37
-rw-r--r--libsolidity/interface/CompilerStack.h31
2 files changed, 41 insertions, 27 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index b99fe4ee..5713256a 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -747,22 +747,32 @@ 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);
+ 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)
{
@@ -773,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
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index c567ac2c..b377b3aa 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -155,10 +155,10 @@ public:
std::map<std::string, unsigned> sourceIndices() const;
/// @returns the previously used scanner, useful for counting lines during error reporting.
- Scanner const& scanner(std::string const& _sourceName = "") const;
+ Scanner const& scanner(std::string const& _sourceName) const;
/// @returns the parsed source unit with the supplied name.
- SourceUnit const& ast(std::string const& _sourceName = "") const;
+ SourceUnit const& ast(std::string const& _sourceName) const;
/// Helper function for logs printing. Do only use in error cases, it's quite expensive.
/// line and columns are numbered starting from 1 with following order:
@@ -168,48 +168,51 @@ 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;
/// @returns the assembled object for a contract.
- eth::LinkerObject const& object(std::string const& _contractName = "") const;
+ eth::LinkerObject const& object(std::string const& _contractName) const;
/// @returns the runtime object for the contract.
- eth::LinkerObject const& runtimeObject(std::string const& _contractName = "") const;
+ eth::LinkerObject const& runtimeObject(std::string const& _contractName) const;
/// @returns the bytecode of a contract that uses an already deployed contract via DELEGATECALL.
/// The returned bytes will contain a sequence of 20 bytes of the format "XXX...XXX" which have to
/// substituted by the actual address. Note that this sequence starts end ends in three X
/// characters but can contain anything in between.
- eth::LinkerObject const& cloneObject(std::string const& _contractName = "") const;
+ eth::LinkerObject const& cloneObject(std::string const& _contractName) const;
/// @returns normal contract assembly items
- eth::AssemblyItems const* assemblyItems(std::string const& _contractName = "") const;
+ eth::AssemblyItems const* assemblyItems(std::string const& _contractName) const;
/// @returns runtime contract assembly items
- eth::AssemblyItems const* runtimeAssemblyItems(std::string const& _contractName = "") const;
+ eth::AssemblyItems const* runtimeAssemblyItems(std::string const& _contractName) const;
/// @returns the string that provides a mapping between bytecode and sourcecode or a nullptr
/// if the contract does not (yet) have bytecode.
- std::string const* sourceMapping(std::string const& _contractName = "") const;
+ std::string const* sourceMapping(std::string const& _contractName) const;
/// @returns the string that provides a mapping between runtime bytecode and sourcecode.
/// if the contract does not (yet) have bytecode.
- std::string const* runtimeSourceMapping(std::string const& _contractName = "") const;
+ std::string const* runtimeSourceMapping(std::string const& _contractName) const;
/// @return a verbose text representation of the assembly.
/// @arg _sourceCodes is the map of input files to source code strings
/// Prerequisite: Successful compilation.
- std::string assemblyString(std::string const& _contractName = "", StringMap _sourceCodes = StringMap()) const;
+ std::string assemblyString(std::string const& _contractName, StringMap _sourceCodes = StringMap()) const;
/// @returns a JSON representation of the assembly.
/// @arg _sourceCodes is the map of input files to source code strings
/// Prerequisite: Successful compilation.
- Json::Value assemblyJSON(std::string const& _contractName = "", StringMap _sourceCodes = StringMap()) const;
+ Json::Value assemblyJSON(std::string const& _contractName, StringMap _sourceCodes = StringMap()) const;
/// @returns a JSON representing the contract ABI.
/// Prerequisite: Successful call to parse or compile.
- Json::Value const& contractABI(std::string const& _contractName = "") const;
+ Json::Value const& contractABI(std::string const& _contractName) const;
/// @returns a JSON representing the contract's user documentation.
/// Prerequisite: Successful call to parse or compile.
@@ -276,8 +279,8 @@ private:
);
void link();
- Contract const& contract(std::string const& _contractName = "") const;
- Source const& source(std::string const& _sourceName = "") const;
+ Contract const& contract(std::string const& _contractName) const;
+ Source const& source(std::string const& _sourceName) const;
/// @returns the parsed contract with the supplied name. Throws an exception if the contract
/// does not exist.