aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-09-14 02:43:16 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-10-05 03:30:14 +0800
commitf96e932243273050fcf2bd4ba89d80412252a9d9 (patch)
treeb97d38396eea5a13248ca4a84284b02913c36362 /libsolidity
parent19274c78904632d568bf56e95603d22ef091ce77 (diff)
downloaddexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar.gz
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar.bz2
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar.lz
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar.xz
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.tar.zst
dexon-solidity-f96e932243273050fcf2bd4ba89d80412252a9d9.zip
Provide optional list of contract names to CompilerStack.compile
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/CompilerStack.cpp11
-rw-r--r--libsolidity/interface/CompilerStack.h11
2 files changed, 21 insertions, 1 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 51544f8a..b99fe4ee 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -252,6 +252,14 @@ bool CompilerStack::parseAndAnalyze()
return parse() && analyze();
}
+bool CompilerStack::isRequestedContract(ContractDefinition const& _contract) const
+{
+ return
+ m_requestedContractNames.empty() ||
+ m_requestedContractNames.count(_contract.fullyQualifiedName()) ||
+ m_requestedContractNames.count(_contract.name());
+}
+
bool CompilerStack::compile()
{
if (m_stackState < AnalysisSuccessful)
@@ -262,7 +270,8 @@ bool CompilerStack::compile()
for (Source const* source: m_sourceOrder)
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
- compileContract(*contract, compiledContracts);
+ if (isRequestedContract(*contract))
+ compileContract(*contract, compiledContracts);
this->link();
m_stackState = CompilationSuccessful;
return true;
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index f1bbae47..c567ac2c 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -116,6 +116,13 @@ public:
m_optimizeRuns = _runs;
}
+ /// Sets the list of requested contract names. If empty, no filtering is performed and every contract
+ /// found in the supplied sources is compiled. Names are cleared iff @a _contractNames is missing.
+ void setRequestedContractNames(std::set<std::string> const& _contractNames = std::set<std::string>{})
+ {
+ m_requestedContractNames = _contractNames;
+ }
+
/// @arg _metadataLiteralSources When true, store sources as literals in the contract metadata.
void useMetadataLiteralSources(bool _metadataLiteralSources) { m_metadataLiteralSources = _metadataLiteralSources; }
@@ -259,6 +266,9 @@ private:
/// Helper function to return path converted strings.
std::string sanitizePath(std::string const& _path) const { return boost::filesystem::path(_path).generic_string(); }
+ /// @returns true if the contract is requested to be compiled.
+ bool isRequestedContract(ContractDefinition const& _contract) const;
+
/// Compile a single contract and put the result in @a _compiledContracts.
void compileContract(
ContractDefinition const& _contract,
@@ -297,6 +307,7 @@ private:
ReadCallback::Callback m_smtQuery;
bool m_optimize = false;
unsigned m_optimizeRuns = 200;
+ std::set<std::string> m_requestedContractNames;
std::map<std::string, h160> m_libraries;
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
/// "context:prefix=target"