aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-19 01:28:14 +0800
committerchriseth <chris@ethereum.org>2018-12-19 19:58:17 +0800
commitbeae2a608ba09cfdf1720fa8655cb22cf2d6c051 (patch)
tree98e63baf365bda252ef196aa6a106f60277a6610 /libsolidity
parent4e89945d823abe8c5869522e64533d4047acae9d (diff)
downloaddexon-solidity-beae2a608ba09cfdf1720fa8655cb22cf2d6c051.tar.gz
dexon-solidity-beae2a608ba09cfdf1720fa8655cb22cf2d6c051.tar.zst
dexon-solidity-beae2a608ba09cfdf1720fa8655cb22cf2d6c051.zip
Only fully compile if binaries requested.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/interface/StandardCompiler.cpp49
1 files changed, 40 insertions, 9 deletions
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index e99b1324..6415e732 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -28,6 +28,7 @@
#include <libdevcore/JSON.h>
#include <libdevcore/Keccak256.h>
+#include <boost/algorithm/cxx11/any_of.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <algorithm>
@@ -191,6 +192,31 @@ bool isArtifactRequested(Json::Value const& _outputSelection, string const& _fil
return false;
}
+/// @returns true if any binary was requested, i.e. we actually have to perform compilation.
+bool isBinaryRequested(Json::Value const& _outputSelection)
+{
+ if (!_outputSelection.isObject())
+ return false;
+
+ // This does not inculde "evm.methodIdentifiers" on purpose!
+ static vector<string> const outputsThatRequireBinaries{
+ "*",
+ "metadata", // This is only generated at the end of compilation, but could be generated earlier.
+ "evm.deployedBytecode", "evm.deployedBytecode.object", "evm.deployedBytecode.opcodes",
+ "evm.deployedBytecode.sourceMap", "evm.deployedBytecode.linkReferences",
+ "evm.bytecode", "evm.bytecode.object", "evm.bytecode.opcodes", "evm.bytecode.sourceMap",
+ "evm.bytecode.linkReferences",
+ "evm.gasEstimates", "evm.legacyAssembly", "evm.assembly"
+ };
+
+ for (auto const& fileRequests: _outputSelection)
+ for (auto const& requests: fileRequests)
+ for (auto const& output: outputsThatRequireBinaries)
+ if (isArtifactRequested(requests, output))
+ return true;
+ return false;
+}
+
Json::Value formatLinkReferences(std::map<size_t, std::string> const& linkReferences)
{
Json::Value ret(Json::objectValue);
@@ -564,9 +590,14 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
m_compilerStack.setRequestedContractNames(requestedContractNames(outputSelection));
+ bool const binariesRequested = isBinaryRequested(outputSelection);
+
try
{
- m_compilerStack.compile();
+ if (binariesRequested)
+ m_compilerStack.compile();
+ else
+ m_compilerStack.parseAndAnalyze();
for (auto const& error: m_compilerStack.errors())
{
@@ -655,7 +686,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
bool const compilationSuccess = m_compilerStack.state() == CompilerStack::State::CompilationSuccessful;
/// Inconsistent state - stop here to receive error reports from users
- if (!compilationSuccess && errors.empty())
+ if (((binariesRequested && !compilationSuccess) || !analysisSuccess) && errors.empty())
return formatFatalError("InternalCompilerError", "No error reported, but compilation failed.");
Json::Value output = Json::objectValue;
@@ -681,7 +712,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
}
Json::Value contractsOutput = Json::objectValue;
- for (string const& contractName: compilationSuccess ? m_compilerStack.contractNames() : vector<string>())
+ for (string const& contractName: analysisSuccess ? m_compilerStack.contractNames() : vector<string>())
{
size_t colon = contractName.rfind(':');
solAssert(colon != string::npos, "");
@@ -692,7 +723,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
Json::Value contractData(Json::objectValue);
if (isArtifactRequested(outputSelection, file, name, "abi"))
contractData["abi"] = m_compilerStack.contractABI(contractName);
- if (isArtifactRequested(outputSelection, file, name, "metadata"))
+ if (compilationSuccess && isArtifactRequested(outputSelection, file, name, "metadata"))
contractData["metadata"] = m_compilerStack.metadata(contractName);
if (isArtifactRequested(outputSelection, file, name, "userdoc"))
contractData["userdoc"] = m_compilerStack.natspecUser(contractName);
@@ -702,16 +733,16 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
// EVM
Json::Value evmData(Json::objectValue);
// @TODO: add ir
- if (isArtifactRequested(outputSelection, file, name, "evm.assembly"))
+ if (compilationSuccess && isArtifactRequested(outputSelection, file, name, "evm.assembly"))
evmData["assembly"] = m_compilerStack.assemblyString(contractName, createSourceList(_input));
- if (isArtifactRequested(outputSelection, file, name, "evm.legacyAssembly"))
+ if (compilationSuccess && isArtifactRequested(outputSelection, file, name, "evm.legacyAssembly"))
evmData["legacyAssembly"] = m_compilerStack.assemblyJSON(contractName, createSourceList(_input));
if (isArtifactRequested(outputSelection, file, name, "evm.methodIdentifiers"))
evmData["methodIdentifiers"] = m_compilerStack.methodIdentifiers(contractName);
- if (isArtifactRequested(outputSelection, file, name, "evm.gasEstimates"))
+ if (compilationSuccess && isArtifactRequested(outputSelection, file, name, "evm.gasEstimates"))
evmData["gasEstimates"] = m_compilerStack.gasEstimates(contractName);
- if (isArtifactRequested(
+ if (compilationSuccess && isArtifactRequested(
outputSelection,
file,
name,
@@ -722,7 +753,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
m_compilerStack.sourceMapping(contractName)
);
- if (isArtifactRequested(
+ if (compilationSuccess && isArtifactRequested(
outputSelection,
file,
name,