Provide different options for reason strings.

This commit is contained in:
chriseth
2019-11-07 14:13:53 +01:00
parent 108992c335
commit 138ee647f1
22 changed files with 300 additions and 22 deletions
+13 -1
View File
@@ -152,6 +152,14 @@ void CompilerStack::setOptimiserSettings(OptimiserSettings _settings)
m_optimiserSettings = std::move(_settings);
}
void CompilerStack::setRevertStringBehaviour(RevertStrings _revertStrings)
{
if (m_stackState >= ParsingPerformed)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Must set revert string settings before parsing."));
solUnimplementedAssert(_revertStrings == RevertStrings::Default || _revertStrings == RevertStrings::Strip, "");
m_revertStrings = _revertStrings;
}
void CompilerStack::useMetadataLiteralSources(bool _metadataLiteralSources)
{
if (m_stackState >= ParsingPerformed)
@@ -187,6 +195,7 @@ void CompilerStack::reset(bool _keepSettings)
m_evmVersion = langutil::EVMVersion();
m_generateIR = false;
m_generateEWasm = false;
m_revertStrings = RevertStrings::Default;
m_optimiserSettings = OptimiserSettings::minimal();
m_metadataLiteralSources = false;
m_metadataHash = MetadataHash::IPFS;
@@ -972,7 +981,7 @@ void CompilerStack::compileContract(
Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName());
shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimiserSettings);
shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_revertStrings, m_optimiserSettings);
compiledContract.compiler = compiler;
bytes cborEncodedMetadata = createCBORMetadata(
@@ -1171,6 +1180,9 @@ string CompilerStack::createMetadata(Contract const& _contract) const
meta["settings"]["optimizer"]["details"] = std::move(details);
}
if (m_revertStrings != RevertStrings::Default)
meta["settings"]["debug"]["revertStrings"] = revertStringsToString(m_revertStrings);
if (m_metadataLiteralSources)
meta["settings"]["metadata"]["useLiteralContent"] = true;
+5
View File
@@ -26,6 +26,7 @@
#include <libsolidity/interface/ReadFile.h>
#include <libsolidity/interface/OptimiserSettings.h>
#include <libsolidity/interface/Version.h>
#include <libsolidity/interface/DebugSettings.h>
#include <liblangutil/ErrorReporter.h>
#include <liblangutil/EVMVersion.h>
@@ -145,6 +146,9 @@ public:
/// Must be set before parsing.
void setOptimiserSettings(OptimiserSettings _settings);
/// Sets whether to strip revert strings, add additional strings or do nothing at all.
void setRevertStringBehaviour(RevertStrings _revertStrings);
/// Set whether or not parser error is desired.
/// When called without an argument it will revert to the default.
/// Must be set before parsing.
@@ -414,6 +418,7 @@ private:
ReadCallback::Callback m_readFile;
OptimiserSettings m_optimiserSettings;
RevertStrings m_revertStrings = RevertStrings::Default;
langutil::EVMVersion m_evmVersion;
std::map<std::string, std::set<std::string>> m_requestedContractNames;
bool m_generateIR;
+63
View File
@@ -0,0 +1,63 @@
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Settings to aid debugging.
*/
#pragma once
#include <cstddef>
#include <string>
#include <optional>
namespace dev
{
namespace solidity
{
enum class RevertStrings
{
Default, // no compiler-generated strings, keep user-supplied strings
Strip, // no compiler-generated strings, remove user-supplied strings (if possible)
Debug, // add strings for internal reverts, keep user-supplied strings
VerboseDebug // add strings for internal reverts, add user-supplied strings if not provided
};
inline std::string revertStringsToString(RevertStrings _str)
{
switch (_str)
{
case RevertStrings::Default: return "default";
case RevertStrings::Strip: return "strip";
case RevertStrings::Debug: return "debug";
case RevertStrings::VerboseDebug: return "verboseDebug";
}
// Cannot reach this.
return "INVALID";
}
inline std::optional<RevertStrings> revertStringsFromString(std::string const& _str)
{
for (auto i: {RevertStrings::Default, RevertStrings::Strip, RevertStrings::Debug, RevertStrings::VerboseDebug})
if (revertStringsToString(i) == _str)
return i;
return {};
}
}
}
+25 -1
View File
@@ -350,7 +350,7 @@ std::optional<Json::Value> checkAuxiliaryInputKeys(Json::Value const& _input)
std::optional<Json::Value> checkSettingsKeys(Json::Value const& _input)
{
static set<string> keys{"parserErrorRecovery", "evmVersion", "libraries", "metadata", "optimizer", "outputSelection", "remappings"};
static set<string> keys{"parserErrorRecovery", "debug", "evmVersion", "libraries", "metadata", "optimizer", "outputSelection", "remappings"};
return checkKeys(_input, keys, "settings");
}
@@ -649,6 +649,27 @@ boost::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompile
ret.evmVersion = *version;
}
if (settings.isMember("debug"))
{
if (auto result = checkKeys(settings["debug"], {"revertStrings"}, "settings.debug"))
return *result;
if (settings["debug"].isMember("revertStrings"))
{
if (!settings["debug"]["revertStrings"].isString())
return formatFatalError("JSONError", "settings.debug.revertStrings must be a string.");
std::optional<RevertStrings> revertStrings = revertStringsFromString(settings["debug"]["revertStrings"].asString());
if (!revertStrings)
return formatFatalError("JSONError", "Invalid value for settings.debug.revertStrings.");
if (*revertStrings != RevertStrings::Default && *revertStrings != RevertStrings::Strip)
return formatFatalError(
"UnimplementedFeatureError",
"Only \"default\" and \"strip\" are implemented for settings.debug.revertStrings for now."
);
ret.revertStrings = *revertStrings;
}
}
if (settings.isMember("remappings") && !settings["remappings"].isArray())
return formatFatalError("JSONError", "\"settings.remappings\" must be an array of strings.");
@@ -751,6 +772,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
compilerStack.setParserErrorRecovery(_inputsAndSettings.parserErrorRecovery);
compilerStack.setRemappings(_inputsAndSettings.remappings);
compilerStack.setOptimiserSettings(std::move(_inputsAndSettings.optimiserSettings));
compilerStack.setRevertStringBehaviour(_inputsAndSettings.revertStrings);
compilerStack.setLibraries(_inputsAndSettings.libraries);
compilerStack.useMetadataLiteralSources(_inputsAndSettings.metadataLiteralSources);
compilerStack.setMetadataHash(_inputsAndSettings.metadataHash);
@@ -990,6 +1012,8 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
return formatFatalError("JSONError", "Field \"settings.remappings\" cannot be used for Yul.");
if (!_inputsAndSettings.libraries.empty())
return formatFatalError("JSONError", "Field \"settings.libraries\" cannot be used for Yul.");
if (_inputsAndSettings.revertStrings != RevertStrings::Default)
return formatFatalError("JSONError", "Field \"settings.debug.revertStrings\" cannot be used for Yul.");
Json::Value output = Json::objectValue;
+1
View File
@@ -65,6 +65,7 @@ private:
std::map<h256, std::string> smtLib2Responses;
langutil::EVMVersion evmVersion;
std::vector<CompilerStack::Remapping> remappings;
RevertStrings revertStrings = RevertStrings::Default;
OptimiserSettings optimiserSettings = OptimiserSettings::minimal();
std::map<std::string, h160> libraries;
bool metadataLiteralSources = false;