Make use of C++17 std::optional<> instead of boost::optional<>.

This commit is contained in:
Christian Parpart 2019-10-28 11:39:30 +01:00
parent 302a51a58c
commit df729b3084
67 changed files with 173 additions and 168 deletions

View File

@ -119,7 +119,7 @@ Use `solAssert` and `solUnimplementedAssert` generously to check assumptions tha
4. Favour declarations close to use; don't habitually declare at top of scope ala C. 4. Favour declarations close to use; don't habitually declare at top of scope ala C.
5. Pass non-trivial parameters as const reference, unless the data is to be copied into the function, then either pass by const reference or by value and use std::move. 5. Pass non-trivial parameters as const reference, unless the data is to be copied into the function, then either pass by const reference or by value and use std::move.
6. If a function returns multiple values, use std::tuple (std::pair acceptable) or better introduce a struct type. Do not use */& arguments. 6. If a function returns multiple values, use std::tuple (std::pair acceptable) or better introduce a struct type. Do not use */& arguments.
7. Use parameters of pointer type only if ``nullptr`` is a valid argument, use references otherwise. Often, ``boost::optional`` is better suited than a raw pointer. 7. Use parameters of pointer type only if ``nullptr`` is a valid argument, use references otherwise. Often, ``std::optional`` is better suited than a raw pointer.
8. Never use a macro where adequate non-preprocessor C++ can be written. 8. Never use a macro where adequate non-preprocessor C++ can be written.
9. Only use ``auto`` if the type is very long and rather irrelevant. 9. Only use ``auto`` if the type is very long and rather irrelevant.
10. Do not pass bools: prefer enumerations instead. 10. Do not pass bools: prefer enumerations instead.

View File

@ -25,11 +25,10 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <boost/optional.hpp>
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
#include <cstring> #include <cstring>
#include <optional>
#include <string> #include <string>
#include <set> #include <set>
#include <functional> #include <functional>
@ -277,7 +276,7 @@ void iterateReplacing(std::vector<T>& _vector, F const& _f)
std::vector<T> modifiedVector; std::vector<T> modifiedVector;
for (size_t i = 0; i < _vector.size(); ++i) for (size_t i = 0; i < _vector.size(); ++i)
{ {
if (boost::optional<std::vector<T>> r = _f(_vector[i])) if (std::optional<std::vector<T>> r = _f(_vector[i]))
{ {
if (!useModified) if (!useModified)
{ {
@ -305,7 +304,7 @@ void iterateReplacingWindow(std::vector<T>& _vector, F const& _f, std::index_seq
size_t i = 0; size_t i = 0;
for (; i + sizeof...(I) <= _vector.size(); ++i) for (; i + sizeof...(I) <= _vector.size(); ++i)
{ {
if (boost::optional<std::vector<T>> r = _f(_vector[i + I]...)) if (std::optional<std::vector<T>> r = _f(_vector[i + I]...))
{ {
if (!useModified) if (!useModified)
{ {

View File

@ -22,9 +22,9 @@
#include <libevmasm/Instruction.h> #include <libevmasm/Instruction.h>
#include <optional>
#include <string> #include <string>
#include <boost/optional.hpp>
#include <boost/operators.hpp> #include <boost/operators.hpp>
@ -51,12 +51,12 @@ public:
static EVMVersion istanbul() { return {Version::Istanbul}; } static EVMVersion istanbul() { return {Version::Istanbul}; }
static EVMVersion berlin() { return {Version::Berlin}; } static EVMVersion berlin() { return {Version::Berlin}; }
static boost::optional<EVMVersion> fromString(std::string const& _version) static std::optional<EVMVersion> fromString(std::string const& _version)
{ {
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin()}) for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin()})
if (_version == v.name()) if (_version == v.name())
return v; return v;
return {}; return std::nullopt;
} }
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; } bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }

View File

@ -53,8 +53,9 @@
#include <liblangutil/Common.h> #include <liblangutil/Common.h>
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>
#include <boost/optional.hpp>
#include <algorithm> #include <algorithm>
#include <optional>
#include <ostream> #include <ostream>
#include <tuple> #include <tuple>
@ -187,7 +188,7 @@ bool Scanner::scanHexByte(char& o_scannedByte)
return true; return true;
} }
boost::optional<unsigned> Scanner::scanUnicode() std::optional<unsigned> Scanner::scanUnicode()
{ {
unsigned x = 0; unsigned x = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -718,7 +719,7 @@ bool Scanner::scanEscape()
break; break;
case 'u': case 'u':
{ {
if (boost::optional<unsigned> codepoint = scanUnicode()) if (auto const codepoint = scanUnicode(); codepoint.has_value())
addUnicodeAsUTF8(*codepoint); addUnicodeAsUTF8(*codepoint);
else else
return false; return false;

View File

@ -57,6 +57,8 @@
#include <liblangutil/SourceLocation.h> #include <liblangutil/SourceLocation.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/CommonData.h> #include <libdevcore/CommonData.h>
#include <optional>
#include <iosfwd> #include <iosfwd>
namespace langutil namespace langutil
@ -207,7 +209,7 @@ private:
inline Token selectToken(char _next, Token _then, Token _else); inline Token selectToken(char _next, Token _then, Token _else);
bool scanHexByte(char& o_scannedByte); bool scanHexByte(char& o_scannedByte);
boost::optional<unsigned> scanUnicode(); std::optional<unsigned> scanUnicode();
/// Scans a single Solidity token. /// Scans a single Solidity token.
void scanToken(); void scanToken();

View File

@ -122,7 +122,7 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName)
if (!_typeName.annotation().type) if (!_typeName.annotation().type)
{ {
_typeName.annotation().type = TypeProvider::fromElementaryTypeName(_typeName.typeName()); _typeName.annotation().type = TypeProvider::fromElementaryTypeName(_typeName.typeName());
if (_typeName.stateMutability().is_initialized()) if (_typeName.stateMutability().has_value())
{ {
// for non-address types this was already caught by the parser // for non-address types this was already caught by the parser
solAssert(_typeName.annotation().type->category() == Type::Category::Address, ""); solAssert(_typeName.annotation().type->category() == Type::Category::Address, "");
@ -323,7 +323,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
// Will be re-generated later with correct information // Will be re-generated later with correct information
// We use the latest EVM version because we will re-run it anyway. // We use the latest EVM version because we will re-run it anyway.
yul::AsmAnalysisInfo analysisInfo; yul::AsmAnalysisInfo analysisInfo;
boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError; std::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
yul::AsmAnalyzer( yul::AsmAnalyzer(
analysisInfo, analysisInfo,
errorsIgnored, errorsIgnored,

View File

@ -241,7 +241,7 @@ void ViewPureChecker::endVisit(InlineAssembly const& _inlineAssembly)
void ViewPureChecker::reportMutability( void ViewPureChecker::reportMutability(
StateMutability _mutability, StateMutability _mutability,
SourceLocation const& _location, SourceLocation const& _location,
boost::optional<SourceLocation> const& _nestedLocation std::optional<SourceLocation> const& _nestedLocation
) )
{ {
if (_mutability > m_bestMutabilityAndLocation.mutability) if (_mutability > m_bestMutabilityAndLocation.mutability)

View File

@ -23,6 +23,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
namespace langutil namespace langutil
{ {
@ -67,7 +68,7 @@ private:
void reportMutability( void reportMutability(
StateMutability _mutability, StateMutability _mutability,
langutil::SourceLocation const& _location, langutil::SourceLocation const& _location,
boost::optional<langutil::SourceLocation> const& _nestedLocation = {} std::optional<langutil::SourceLocation> const& _nestedLocation = {}
); );
std::vector<std::shared_ptr<ASTNode>> const& m_ast; std::vector<std::shared_ptr<ASTNode>> const& m_ast;

View File

@ -36,6 +36,7 @@
#include <json/json.h> #include <json/json.h>
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -912,10 +913,10 @@ public:
ElementaryTypeName( ElementaryTypeName(
SourceLocation const& _location, SourceLocation const& _location,
ElementaryTypeNameToken const& _elem, ElementaryTypeNameToken const& _elem,
boost::optional<StateMutability> _stateMutability = {} std::optional<StateMutability> _stateMutability = {}
): TypeName(_location), m_type(_elem), m_stateMutability(_stateMutability) ): TypeName(_location), m_type(_elem), m_stateMutability(_stateMutability)
{ {
solAssert(!_stateMutability.is_initialized() || _elem.token() == Token::Address, ""); solAssert(!_stateMutability.has_value() || _elem.token() == Token::Address, "");
} }
void accept(ASTVisitor& _visitor) override; void accept(ASTVisitor& _visitor) override;
@ -923,11 +924,11 @@ public:
ElementaryTypeNameToken const& typeName() const { return m_type; } ElementaryTypeNameToken const& typeName() const { return m_type; }
boost::optional<StateMutability> const& stateMutability() const { return m_stateMutability; } std::optional<StateMutability> const& stateMutability() const { return m_stateMutability; }
private: private:
ElementaryTypeNameToken m_type; ElementaryTypeNameToken m_type;
boost::optional<StateMutability> m_stateMutability; ///< state mutability for address type std::optional<StateMutability> m_stateMutability; ///< state mutability for address type
}; };
/** /**

View File

@ -26,10 +26,9 @@
#include <libsolidity/ast/ASTEnums.h> #include <libsolidity/ast/ASTEnums.h>
#include <libsolidity/ast/ExperimentalFeatures.h> #include <libsolidity/ast/ExperimentalFeatures.h>
#include <boost/optional.hpp>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <set> #include <set>
#include <vector> #include <vector>
@ -183,7 +182,7 @@ struct ExpressionAnnotation: ASTAnnotation
/// Types and - if given - names of arguments if the expr. is a function /// Types and - if given - names of arguments if the expr. is a function
/// that is called, used for overload resoultion /// that is called, used for overload resoultion
boost::optional<FuncCallArguments> arguments; std::optional<FuncCallArguments> arguments;
}; };
struct IdentifierAnnotation: ExpressionAnnotation struct IdentifierAnnotation: ExpressionAnnotation

View File

@ -148,7 +148,7 @@ Json::Value ASTJsonConverter::typePointerToJson(TypePointer _tp, bool _short)
return typeDescriptions; return typeDescriptions;
} }
Json::Value ASTJsonConverter::typePointerToJson(boost::optional<FuncCallArguments> const& _tps) Json::Value ASTJsonConverter::typePointerToJson(std::optional<FuncCallArguments> const& _tps)
{ {
if (_tps) if (_tps)
{ {

View File

@ -27,10 +27,12 @@
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>
#include <json/json.h> #include <json/json.h>
#include <algorithm>
#include <optional>
#include <ostream> #include <ostream>
#include <stack> #include <stack>
#include <vector> #include <vector>
#include <algorithm>
namespace langutil namespace langutil
{ {
@ -169,7 +171,7 @@ private:
return json; return json;
} }
static Json::Value typePointerToJson(TypePointer _tp, bool _short = false); static Json::Value typePointerToJson(TypePointer _tp, bool _short = false);
static Json::Value typePointerToJson(boost::optional<FuncCallArguments> const& _tps); static Json::Value typePointerToJson(std::optional<FuncCallArguments> const& _tps);
void appendExpressionAttributes( void appendExpressionAttributes(
std::vector<std::pair<std::string, Json::Value>> &_attributes, std::vector<std::pair<std::string, Json::Value>> &_attributes,
ExpressionAnnotation const& _annotation ExpressionAnnotation const& _annotation

View File

@ -22,6 +22,7 @@
#include <array> #include <array>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <utility> #include <utility>
namespace dev namespace dev

View File

@ -1812,10 +1812,10 @@ TypePointer ArrayType::decodingType() const
TypeResult ArrayType::interfaceType(bool _inLibrary) const TypeResult ArrayType::interfaceType(bool _inLibrary) const
{ {
if (_inLibrary && m_interfaceType_library.is_initialized()) if (_inLibrary && m_interfaceType_library.has_value())
return *m_interfaceType_library; return *m_interfaceType_library;
if (!_inLibrary && m_interfaceType.is_initialized()) if (!_inLibrary && m_interfaceType.has_value())
return *m_interfaceType; return *m_interfaceType;
TypeResult result{TypePointer{}}; TypeResult result{TypePointer{}};
@ -2106,10 +2106,10 @@ MemberList::MemberMap StructType::nativeMembers(ContractDefinition const*) const
TypeResult StructType::interfaceType(bool _inLibrary) const TypeResult StructType::interfaceType(bool _inLibrary) const
{ {
if (_inLibrary && m_interfaceType_library.is_initialized()) if (_inLibrary && m_interfaceType_library.has_value())
return *m_interfaceType_library; return *m_interfaceType_library;
if (!_inLibrary && m_interfaceType.is_initialized()) if (!_inLibrary && m_interfaceType.has_value())
return *m_interfaceType; return *m_interfaceType;
TypeResult result{TypePointer{}}; TypeResult result{TypePointer{}};
@ -2166,7 +2166,7 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
} }
}; };
m_recursive = m_recursive.get() || (CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr); m_recursive = m_recursive.value() || (CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr);
std::string const recursiveErrMsg = "Recursive type not allowed for public or external contract functions."; std::string const recursiveErrMsg = "Recursive type not allowed for public or external contract functions.";
@ -2179,13 +2179,13 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
else else
m_interfaceType_library = TypeProvider::withLocation(this, DataLocation::Memory, true); m_interfaceType_library = TypeProvider::withLocation(this, DataLocation::Memory, true);
if (m_recursive.get()) if (m_recursive.value())
m_interfaceType = TypeResult::err(recursiveErrMsg); m_interfaceType = TypeResult::err(recursiveErrMsg);
return *m_interfaceType_library; return *m_interfaceType_library;
} }
if (m_recursive.get()) if (m_recursive.value())
m_interfaceType = TypeResult::err(recursiveErrMsg); m_interfaceType = TypeResult::err(recursiveErrMsg);
else if (!result.message().empty()) else if (!result.message().empty())
m_interfaceType = result; m_interfaceType = result;

View File

@ -31,11 +31,11 @@
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/Result.h> #include <libdevcore/Result.h>
#include <boost/optional.hpp>
#include <boost/rational.hpp> #include <boost/rational.hpp>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <set> #include <set>
#include <string> #include <string>
@ -769,8 +769,8 @@ private:
Type const* m_baseType; Type const* m_baseType;
bool m_hasDynamicLength = true; bool m_hasDynamicLength = true;
u256 m_length; u256 m_length;
mutable boost::optional<TypeResult> m_interfaceType; mutable std::optional<TypeResult> m_interfaceType;
mutable boost::optional<TypeResult> m_interfaceType_library; mutable std::optional<TypeResult> m_interfaceType_library;
}; };
/** /**
@ -865,12 +865,12 @@ public:
bool recursive() const bool recursive() const
{ {
if (m_recursive.is_initialized()) if (m_recursive.has_value())
return m_recursive.get(); return m_recursive.value();
interfaceType(false); interfaceType(false);
return m_recursive.get(); return m_recursive.value();
} }
std::unique_ptr<ReferenceType> copyForLocation(DataLocation _location, bool _isPointer) const override; std::unique_ptr<ReferenceType> copyForLocation(DataLocation _location, bool _isPointer) const override;
@ -898,9 +898,9 @@ public:
private: private:
StructDefinition const& m_struct; StructDefinition const& m_struct;
// Caches for interfaceType(bool) // Caches for interfaceType(bool)
mutable boost::optional<TypeResult> m_interfaceType; mutable std::optional<TypeResult> m_interfaceType;
mutable boost::optional<TypeResult> m_interfaceType_library; mutable std::optional<TypeResult> m_interfaceType_library;
mutable boost::optional<bool> m_recursive; mutable std::optional<bool> m_recursive;
}; };
/** /**

View File

@ -411,7 +411,7 @@ void CompilerContext::appendInlineAssembly(
analyzerResult = yul::AsmAnalyzer( analyzerResult = yul::AsmAnalyzer(
analysisInfo, analysisInfo,
errorReporter, errorReporter,
boost::none, std::nullopt,
dialect, dialect,
identifierAccess.resolve identifierAccess.resolve
).analyze(*parserResult); ).analyze(*parserResult);

View File

@ -962,11 +962,11 @@ string YulUtilFunctions::readFromCalldata(Type const& _type)
return readFromMemoryOrCalldata(_type, true); return readFromMemoryOrCalldata(_type, true);
} }
string YulUtilFunctions::updateStorageValueFunction(Type const& _type, boost::optional<unsigned> const& _offset) string YulUtilFunctions::updateStorageValueFunction(Type const& _type, std::optional<unsigned> const& _offset)
{ {
string const functionName = string const functionName =
"update_storage_value_" + "update_storage_value_" +
(_offset.is_initialized() ? ("offset_" + to_string(*_offset)) : "") + (_offset.has_value() ? ("offset_" + to_string(*_offset)) : "") +
_type.identifier(); _type.identifier();
return m_functionCollector->createFunction(functionName, [&] { return m_functionCollector->createFunction(functionName, [&] {
@ -983,11 +983,11 @@ string YulUtilFunctions::updateStorageValueFunction(Type const& _type, boost::op
)") )")
("functionName", functionName) ("functionName", functionName)
("update", ("update",
_offset.is_initialized() ? _offset.has_value() ?
updateByteSliceFunction(_type.storageBytes(), *_offset) : updateByteSliceFunction(_type.storageBytes(), *_offset) :
updateByteSliceFunctionDynamic(_type.storageBytes()) updateByteSliceFunctionDynamic(_type.storageBytes())
) )
("offset", _offset.is_initialized() ? "" : "offset, ") ("offset", _offset.has_value() ? "" : "offset, ")
("prepare", prepareStoreFunction(_type)) ("prepare", prepareStoreFunction(_type))
.render(); .render();
} }

View File

@ -197,7 +197,7 @@ public:
/// the specified slot and offset. If offset is not given, it is expected as /// the specified slot and offset. If offset is not given, it is expected as
/// runtime parameter. /// runtime parameter.
/// signature: (slot, [offset,] value) /// signature: (slot, [offset,] value)
std::string updateStorageValueFunction(Type const& _type, boost::optional<unsigned> const& _offset = boost::optional<unsigned>()); std::string updateStorageValueFunction(Type const& _type, std::optional<unsigned> const& _offset = std::optional<unsigned>());
/// Returns the name of a function that will write the given value to /// Returns the name of a function that will write the given value to
/// the specified address. /// the specified address.

View File

@ -115,7 +115,7 @@ string IRStorageItem::storeValue(string const& _value, Type const& _sourceType)
if (m_type->isValueType()) if (m_type->isValueType())
solAssert(_sourceType == *m_type, "Different type, but might not be an error."); solAssert(_sourceType == *m_type, "Different type, but might not be an error.");
boost::optional<unsigned> offset; std::optional<unsigned> offset;
if (m_offset.type() == typeid(unsigned)) if (m_offset.type() == typeid(unsigned))
offset = get<unsigned>(m_offset); offset = get<unsigned>(m_offset);

View File

@ -95,7 +95,7 @@ CompilerStack::~CompilerStack()
TypeProvider::reset(); TypeProvider::reset();
} }
boost::optional<CompilerStack::Remapping> CompilerStack::parseRemapping(string const& _remapping) std::optional<CompilerStack::Remapping> CompilerStack::parseRemapping(string const& _remapping)
{ {
auto eq = find(_remapping.begin(), _remapping.end(), '='); auto eq = find(_remapping.begin(), _remapping.end(), '=');
if (eq == _remapping.end()) if (eq == _remapping.end())

View File

@ -121,7 +121,7 @@ public:
void reset(bool _keepSettings = false); void reset(bool _keepSettings = false);
// Parses a remapping of the format "context:prefix=target". // Parses a remapping of the format "context:prefix=target".
static boost::optional<Remapping> parseRemapping(std::string const& _remapping); static std::optional<Remapping> parseRemapping(std::string const& _remapping);
/// Sets path remappings. /// Sets path remappings.
/// Must be set before parsing. /// Must be set before parsing.

View File

@ -31,8 +31,9 @@
#include <boost/algorithm/cxx11/any_of.hpp> #include <boost/algorithm/cxx11/any_of.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <algorithm> #include <algorithm>
#include <optional>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -317,7 +318,7 @@ Json::Value collectEVMObject(eth::LinkerObject const& _object, string const* _so
return output; return output;
} }
boost::optional<Json::Value> checkKeys(Json::Value const& _input, set<string> const& _keys, string const& _name) std::optional<Json::Value> checkKeys(Json::Value const& _input, set<string> const& _keys, string const& _name)
{ {
if (!!_input && !_input.isObject()) if (!!_input && !_input.isObject())
return formatFatalError("JSONError", "\"" + _name + "\" must be an object"); return formatFatalError("JSONError", "\"" + _name + "\" must be an object");
@ -326,46 +327,46 @@ boost::optional<Json::Value> checkKeys(Json::Value const& _input, set<string> co
if (!_keys.count(member)) if (!_keys.count(member))
return formatFatalError("JSONError", "Unknown key \"" + member + "\""); return formatFatalError("JSONError", "Unknown key \"" + member + "\"");
return boost::none; return std::nullopt;
} }
boost::optional<Json::Value> checkRootKeys(Json::Value const& _input) std::optional<Json::Value> checkRootKeys(Json::Value const& _input)
{ {
static set<string> keys{"auxiliaryInput", "language", "settings", "sources"}; static set<string> keys{"auxiliaryInput", "language", "settings", "sources"};
return checkKeys(_input, keys, "root"); return checkKeys(_input, keys, "root");
} }
boost::optional<Json::Value> checkSourceKeys(Json::Value const& _input, string const& _name) std::optional<Json::Value> checkSourceKeys(Json::Value const& _input, string const& _name)
{ {
static set<string> keys{"content", "keccak256", "urls"}; static set<string> keys{"content", "keccak256", "urls"};
return checkKeys(_input, keys, "sources." + _name); return checkKeys(_input, keys, "sources." + _name);
} }
boost::optional<Json::Value> checkAuxiliaryInputKeys(Json::Value const& _input) std::optional<Json::Value> checkAuxiliaryInputKeys(Json::Value const& _input)
{ {
static set<string> keys{"smtlib2responses"}; static set<string> keys{"smtlib2responses"};
return checkKeys(_input, keys, "auxiliaryInput"); return checkKeys(_input, keys, "auxiliaryInput");
} }
boost::optional<Json::Value> checkSettingsKeys(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", "evmVersion", "libraries", "metadata", "optimizer", "outputSelection", "remappings"};
return checkKeys(_input, keys, "settings"); return checkKeys(_input, keys, "settings");
} }
boost::optional<Json::Value> checkOptimizerKeys(Json::Value const& _input) std::optional<Json::Value> checkOptimizerKeys(Json::Value const& _input)
{ {
static set<string> keys{"details", "enabled", "runs"}; static set<string> keys{"details", "enabled", "runs"};
return checkKeys(_input, keys, "settings.optimizer"); return checkKeys(_input, keys, "settings.optimizer");
} }
boost::optional<Json::Value> checkOptimizerDetailsKeys(Json::Value const& _input) std::optional<Json::Value> checkOptimizerDetailsKeys(Json::Value const& _input)
{ {
static set<string> keys{"peephole", "jumpdestRemover", "orderLiterals", "deduplicate", "cse", "constantOptimizer", "yul", "yulDetails"}; static set<string> keys{"peephole", "jumpdestRemover", "orderLiterals", "deduplicate", "cse", "constantOptimizer", "yul", "yulDetails"};
return checkKeys(_input, keys, "settings.optimizer.details"); return checkKeys(_input, keys, "settings.optimizer.details");
} }
boost::optional<Json::Value> checkOptimizerDetail(Json::Value const& _details, std::string const& _name, bool& _setting) std::optional<Json::Value> checkOptimizerDetail(Json::Value const& _details, std::string const& _name, bool& _setting)
{ {
if (_details.isMember(_name)) if (_details.isMember(_name))
{ {
@ -376,7 +377,7 @@ boost::optional<Json::Value> checkOptimizerDetail(Json::Value const& _details, s
return {}; return {};
} }
boost::optional<Json::Value> checkMetadataKeys(Json::Value const& _input) std::optional<Json::Value> checkMetadataKeys(Json::Value const& _input)
{ {
if (_input.isObject() && _input.isMember("useLiteralContent") && !_input["useLiteralContent"].isBool()) if (_input.isObject() && _input.isMember("useLiteralContent") && !_input["useLiteralContent"].isBool())
return formatFatalError("JSONError", "\"settings.metadata.useLiteralContent\" must be Boolean"); return formatFatalError("JSONError", "\"settings.metadata.useLiteralContent\" must be Boolean");
@ -384,7 +385,7 @@ boost::optional<Json::Value> checkMetadataKeys(Json::Value const& _input)
return checkKeys(_input, keys, "settings.metadata"); return checkKeys(_input, keys, "settings.metadata");
} }
boost::optional<Json::Value> checkOutputSelection(Json::Value const& _outputSelection) std::optional<Json::Value> checkOutputSelection(Json::Value const& _outputSelection)
{ {
if (!!_outputSelection && !_outputSelection.isObject()) if (!!_outputSelection && !_outputSelection.isObject())
return formatFatalError("JSONError", "\"settings.outputSelection\" must be an object"); return formatFatalError("JSONError", "\"settings.outputSelection\" must be an object");
@ -426,7 +427,7 @@ boost::optional<Json::Value> checkOutputSelection(Json::Value const& _outputSele
} }
} }
return boost::none; return std::nullopt;
} }
/// Validates the optimizer settings and returns them in a parsed object. /// Validates the optimizer settings and returns them in a parsed object.
/// On error returns the json-formatted error message. /// On error returns the json-formatted error message.
@ -635,7 +636,7 @@ boost::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompile
{ {
if (!settings["evmVersion"].isString()) if (!settings["evmVersion"].isString())
return formatFatalError("JSONError", "evmVersion must be a string."); return formatFatalError("JSONError", "evmVersion must be a string.");
boost::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(settings["evmVersion"].asString()); std::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(settings["evmVersion"].asString());
if (!version) if (!version)
return formatFatalError("JSONError", "Invalid EVM version requested."); return formatFatalError("JSONError", "Invalid EVM version requested.");
ret.evmVersion = *version; ret.evmVersion = *version;

View File

@ -24,7 +24,7 @@
#include <libsolidity/interface/CompilerStack.h> #include <libsolidity/interface/CompilerStack.h>
#include <boost/optional.hpp> #include <optional>
#include <boost/variant.hpp> #include <boost/variant.hpp>
namespace dev namespace dev

View File

@ -874,7 +874,9 @@ ASTPointer<TypeName> Parser::parseTypeName(bool _allowVar)
ASTNodeFactory nodeFactory(*this); ASTNodeFactory nodeFactory(*this);
nodeFactory.markEndPosition(); nodeFactory.markEndPosition();
m_scanner->next(); m_scanner->next();
auto stateMutability = boost::make_optional(elemTypeName.token() == Token::Address, StateMutability::NonPayable); auto stateMutability = elemTypeName.token() == Token::Address
? optional<StateMutability>{StateMutability::NonPayable}
: nullopt;
if (TokenTraits::isStateMutabilitySpecifier(m_scanner->currentToken(), false)) if (TokenTraits::isStateMutabilitySpecifier(m_scanner->currentToken(), false))
{ {
if (elemTypeName.token() == Token::Address) if (elemTypeName.token() == Token::Address)

View File

@ -31,11 +31,11 @@
#include <libyul/backends/evm/EVMDialect.h> #include <libyul/backends/evm/EVMDialect.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <functional> #include <functional>
#include <list> #include <list>
#include <memory> #include <memory>
#include <optional>
namespace langutil namespace langutil
{ {
@ -59,7 +59,7 @@ public:
explicit AsmAnalyzer( explicit AsmAnalyzer(
AsmAnalysisInfo& _analysisInfo, AsmAnalysisInfo& _analysisInfo,
langutil::ErrorReporter& _errorReporter, langutil::ErrorReporter& _errorReporter,
boost::optional<langutil::Error::Type> _errorTypeForLoose, std::optional<langutil::Error::Type> _errorTypeForLoose,
Dialect const& _dialect, Dialect const& _dialect,
ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver(), ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver(),
std::set<YulString> const& _dataNames = {} std::set<YulString> const& _dataNames = {}
@ -127,7 +127,7 @@ private:
langutil::ErrorReporter& m_errorReporter; langutil::ErrorReporter& m_errorReporter;
langutil::EVMVersion m_evmVersion; langutil::EVMVersion m_evmVersion;
Dialect const& m_dialect; Dialect const& m_dialect;
boost::optional<langutil::Error::Type> m_errorTypeForLoose; std::optional<langutil::Error::Type> m_errorTypeForLoose;
/// Names of data objects to be referenced by builtin functions with literal arguments. /// Names of data objects to be referenced by builtin functions with literal arguments.
std::set<YulString> m_dataNames; std::set<YulString> m_dataNames;
ForLoop const* m_currentForLoop = nullptr; ForLoop const* m_currentForLoop = nullptr;

View File

@ -27,10 +27,10 @@
#include <libdevcore/Visitor.h> #include <libdevcore/Visitor.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <optional>
namespace yul namespace yul
{ {

View File

@ -117,7 +117,7 @@ bool AssemblyStack::analyzeParsed(Object& _object)
AsmAnalyzer analyzer( AsmAnalyzer analyzer(
*_object.analysisInfo, *_object.analysisInfo,
m_errorReporter, m_errorReporter,
boost::none, std::nullopt,
languageToDialect(m_language, m_evmVersion), languageToDialect(m_language, m_evmVersion),
{}, {},
_object.dataNames() _object.dataNames()

View File

@ -723,9 +723,7 @@ void CodeTransform::visitExpression(Expression const& _expression)
void CodeTransform::visitStatements(vector<Statement> const& _statements) void CodeTransform::visitStatements(vector<Statement> const& _statements)
{ {
// Workaround boost bug: std::optional<AbstractAssembly::LabelID> jumpTarget = std::nullopt;
// https://www.boost.org/doc/libs/1_63_0/libs/optional/doc/html/boost_optional/tutorial/gotchas/false_positive_with__wmaybe_uninitialized.html
boost::optional<AbstractAssembly::LabelID> jumpTarget = boost::make_optional(false, AbstractAssembly::LabelID());
for (auto const& statement: _statements) for (auto const& statement: _statements)
{ {
@ -740,7 +738,7 @@ void CodeTransform::visitStatements(vector<Statement> const& _statements)
else if (!functionDefinition && jumpTarget) else if (!functionDefinition && jumpTarget)
{ {
m_assembly.appendLabel(*jumpTarget); m_assembly.appendLabel(*jumpTarget);
jumpTarget = boost::none; jumpTarget = std::nullopt;
} }
boost::apply_visitor(*this, statement); boost::apply_visitor(*this, statement);

View File

@ -28,8 +28,8 @@
#include <libyul/AsmScope.h> #include <libyul/AsmScope.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <optional>
#include <stack> #include <stack>
namespace langutil namespace langutil

View File

@ -47,7 +47,7 @@ struct BuiltinContext
struct BuiltinFunctionForEVM: BuiltinFunction struct BuiltinFunctionForEVM: BuiltinFunction
{ {
boost::optional<dev::eth::Instruction> instruction; std::optional<dev::eth::Instruction> instruction;
/// Function to generate code for the given function call and append it to the abstract /// Function to generate code for the given function call and append it to the abstract
/// assembly. The fourth parameter is called to visit (and generate code for) the arguments /// assembly. The fourth parameter is called to visit (and generate code for) the arguments
/// from right to left. /// from right to left.

View File

@ -658,7 +658,7 @@ Object EVMToEWasmTranslator::run(Object const& _object)
ErrorList errors; ErrorList errors;
ErrorReporter errorReporter(errors); ErrorReporter errorReporter(errors);
AsmAnalyzer analyzer(*ret.analysisInfo, errorReporter, boost::none, WasmDialect::instance(), {}, _object.dataNames()); AsmAnalyzer analyzer(*ret.analysisInfo, errorReporter, std::nullopt, WasmDialect::instance(), {}, _object.dataNames());
if (!analyzer.analyze(*ret.code)) if (!analyzer.analyze(*ret.code))
{ {
// TODO the errors here are "wrong" because they have invalid source references! // TODO the errors here are "wrong" because they have invalid source references!

View File

@ -82,7 +82,7 @@ void WordSizeTransform::operator()(Block& _block)
{ {
iterateReplacing( iterateReplacing(
_block.statements, _block.statements,
[&](Statement& _s) -> boost::optional<vector<Statement>> [&](Statement& _s) -> std::optional<vector<Statement>>
{ {
if (_s.type() == typeid(VariableDeclaration)) if (_s.type() == typeid(VariableDeclaration))
{ {
@ -95,7 +95,7 @@ void WordSizeTransform::operator()(Block& _block)
{ {
if (varDecl.value) visit(*varDecl.value); if (varDecl.value) visit(*varDecl.value);
rewriteVarDeclList(varDecl.variables); rewriteVarDeclList(varDecl.variables);
return boost::none; return std::nullopt;
} }
else if ( else if (
varDecl.value->type() == typeid(Identifier) || varDecl.value->type() == typeid(Identifier) ||
@ -114,7 +114,7 @@ void WordSizeTransform::operator()(Block& _block)
std::move(newRhs[i]) std::move(newRhs[i])
} }
); );
return ret; return {std::move(ret)};
} }
else else
yulAssert(false, ""); yulAssert(false, "");
@ -130,7 +130,7 @@ void WordSizeTransform::operator()(Block& _block)
{ {
if (assignment.value) visit(*assignment.value); if (assignment.value) visit(*assignment.value);
rewriteIdentifierList(assignment.variableNames); rewriteIdentifierList(assignment.variableNames);
return boost::none; return std::nullopt;
} }
else if ( else if (
assignment.value->type() == typeid(Identifier) || assignment.value->type() == typeid(Identifier) ||
@ -149,7 +149,7 @@ void WordSizeTransform::operator()(Block& _block)
std::move(newRhs[i]) std::move(newRhs[i])
} }
); );
return ret; return {std::move(ret)};
} }
else else
yulAssert(false, ""); yulAssert(false, "");
@ -158,7 +158,7 @@ void WordSizeTransform::operator()(Block& _block)
return handleSwitch(boost::get<Switch>(_s)); return handleSwitch(boost::get<Switch>(_s));
else else
visit(_s); visit(_s);
return boost::none; return std::nullopt;
} }
); );
} }
@ -174,7 +174,7 @@ void WordSizeTransform::rewriteVarDeclList(TypedNameList& _nameList)
{ {
iterateReplacing( iterateReplacing(
_nameList, _nameList,
[&](TypedName const& _n) -> boost::optional<TypedNameList> [&](TypedName const& _n) -> std::optional<TypedNameList>
{ {
TypedNameList ret; TypedNameList ret;
for (auto newName: generateU64IdentifierNames(_n.name)) for (auto newName: generateU64IdentifierNames(_n.name))
@ -188,7 +188,7 @@ void WordSizeTransform::rewriteIdentifierList(vector<Identifier>& _ids)
{ {
iterateReplacing( iterateReplacing(
_ids, _ids,
[&](Identifier const& _id) -> boost::optional<vector<Identifier>> [&](Identifier const& _id) -> std::optional<vector<Identifier>>
{ {
vector<Identifier> ret; vector<Identifier> ret;
for (auto newId: m_variableMapping.at(_id.name)) for (auto newId: m_variableMapping.at(_id.name))
@ -202,7 +202,7 @@ void WordSizeTransform::rewriteFunctionCallArguments(vector<Expression>& _args)
{ {
iterateReplacing( iterateReplacing(
_args, _args,
[&](Expression& _e) -> boost::optional<vector<Expression>> [&](Expression& _e) -> std::optional<vector<Expression>>
{ {
return expandValueToVector(_e); return expandValueToVector(_e);
} }

View File

@ -25,11 +25,11 @@
#include <libyul/YulString.h> #include <libyul/YulString.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <vector>
#include <set>
#include <memory> #include <memory>
#include <optional>
#include <set>
#include <vector>
namespace yul namespace yul
{ {

View File

@ -26,11 +26,11 @@
#include <libyul/YulString.h> #include <libyul/YulString.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <vector>
#include <set>
#include <map> #include <map>
#include <optional>
#include <set>
#include <vector>
namespace yul namespace yul
{ {

View File

@ -30,7 +30,7 @@ void BlockFlattener::operator()(Block& _block)
iterateReplacing( iterateReplacing(
_block.statements, _block.statements,
[](Statement& _s) -> boost::optional<vector<Statement>> [](Statement& _s) -> std::optional<vector<Statement>>
{ {
if (_s.type() == typeid(Block)) if (_s.type() == typeid(Block))
return std::move(boost::get<Block>(_s).statements); return std::move(boost::get<Block>(_s).statements);

View File

@ -24,10 +24,9 @@
#include <libdevcore/InvertibleMap.h> #include <libdevcore/InvertibleMap.h>
#include <boost/optional.hpp>
#include <set>
#include <map> #include <map>
#include <optional>
#include <set>
namespace yul namespace yul
{ {

View File

@ -30,7 +30,7 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace yul; using namespace yul;
using OptionalStatements = boost::optional<vector<Statement>>; using OptionalStatements = std::optional<vector<Statement>>;
namespace namespace
{ {

View File

@ -354,7 +354,7 @@ bool DataFlowAnalyzer::inScope(YulString _variableName) const
return false; return false;
} }
boost::optional<pair<YulString, YulString>> DataFlowAnalyzer::isSimpleStore( std::optional<pair<YulString, YulString>> DataFlowAnalyzer::isSimpleStore(
dev::eth::Instruction _store, dev::eth::Instruction _store,
ExpressionStatement const& _statement ExpressionStatement const& _statement
) const ) const

View File

@ -128,7 +128,7 @@ protected:
/// Returns true iff the variable is in scope. /// Returns true iff the variable is in scope.
bool inScope(YulString _variableName) const; bool inScope(YulString _variableName) const;
boost::optional<std::pair<YulString, YulString>> isSimpleStore( std::optional<std::pair<YulString, YulString>> isSimpleStore(
dev::eth::Instruction _store, dev::eth::Instruction _store,
ExpressionStatement const& _statement ExpressionStatement const& _statement
) const; ) const;

View File

@ -26,8 +26,8 @@
#include <libyul/optimiser/NameDispenser.h> #include <libyul/optimiser/NameDispenser.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <optional>
#include <set> #include <set>
namespace yul namespace yul

View File

@ -23,7 +23,7 @@
#include <libyul/AsmDataForward.h> #include <libyul/AsmDataForward.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp> #include <optional>
#include <set> #include <set>

View File

@ -85,8 +85,8 @@ void ExpressionSplitter::operator()(Block& _block)
vector<Statement> saved; vector<Statement> saved;
swap(saved, m_statementsToPrefix); swap(saved, m_statementsToPrefix);
function<boost::optional<vector<Statement>>(Statement&)> f = function<std::optional<vector<Statement>>(Statement&)> f =
[&](Statement& _statement) -> boost::optional<vector<Statement>> { [&](Statement& _statement) -> std::optional<vector<Statement>> {
m_statementsToPrefix.clear(); m_statementsToPrefix.clear();
visit(_statement); visit(_statement);
if (m_statementsToPrefix.empty()) if (m_statementsToPrefix.empty())

View File

@ -27,7 +27,7 @@ void ForLoopInitRewriter::operator()(Block& _block)
{ {
iterateReplacing( iterateReplacing(
_block.statements, _block.statements,
[&](Statement& _stmt) -> boost::optional<vector<Statement>> [&](Statement& _stmt) -> std::optional<vector<Statement>>
{ {
if (_stmt.type() == typeid(ForLoop)) if (_stmt.type() == typeid(ForLoop))
{ {

View File

@ -147,14 +147,14 @@ bool FullInliner::recursive(FunctionDefinition const& _fun) const
void InlineModifier::operator()(Block& _block) void InlineModifier::operator()(Block& _block)
{ {
function<boost::optional<vector<Statement>>(Statement&)> f = [&](Statement& _statement) -> boost::optional<vector<Statement>> { function<std::optional<vector<Statement>>(Statement&)> f = [&](Statement& _statement) -> std::optional<vector<Statement>> {
visit(_statement); visit(_statement);
return tryInlineStatement(_statement); return tryInlineStatement(_statement);
}; };
iterateReplacing(_block.statements, f); iterateReplacing(_block.statements, f);
} }
boost::optional<vector<Statement>> InlineModifier::tryInlineStatement(Statement& _statement) std::optional<vector<Statement>> InlineModifier::tryInlineStatement(Statement& _statement)
{ {
// Only inline for expression statements, assignments and variable declarations. // Only inline for expression statements, assignments and variable declarations.
Expression* e = boost::apply_visitor(GenericFallbackReturnsVisitor<Expression*, ExpressionStatement, Assignment, VariableDeclaration>( Expression* e = boost::apply_visitor(GenericFallbackReturnsVisitor<Expression*, ExpressionStatement, Assignment, VariableDeclaration>(

View File

@ -30,8 +30,8 @@
#include <liblangutil/SourceLocation.h> #include <liblangutil/SourceLocation.h>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <optional>
#include <set> #include <set>
namespace yul namespace yul
@ -126,7 +126,7 @@ public:
void operator()(Block& _block) override; void operator()(Block& _block) override;
private: private:
boost::optional<std::vector<Statement>> tryInlineStatement(Statement& _statement); std::optional<std::vector<Statement>> tryInlineStatement(Statement& _statement);
std::vector<Statement> performInline(Statement& _statement, FunctionCall& _funCall); std::vector<Statement> performInline(Statement& _statement, FunctionCall& _funCall);
YulString m_currentFunction; YulString m_currentFunction;

View File

@ -35,7 +35,7 @@ void SSAReverser::operator()(Block& _block)
walkVector(_block.statements); walkVector(_block.statements);
iterateReplacingWindow<2>( iterateReplacingWindow<2>(
_block.statements, _block.statements,
[&](Statement& _stmt1, Statement& _stmt2) -> boost::optional<vector<Statement>> [&](Statement& _stmt1, Statement& _stmt2) -> std::optional<vector<Statement>>
{ {
auto* varDecl = boost::get<VariableDeclaration>(&_stmt1); auto* varDecl = boost::get<VariableDeclaration>(&_stmt1);

View File

@ -58,7 +58,7 @@ void IntroduceSSA::operator()(Block& _block)
{ {
iterateReplacing( iterateReplacing(
_block.statements, _block.statements,
[&](Statement& _s) -> boost::optional<vector<Statement>> [&](Statement& _s) -> std::optional<vector<Statement>>
{ {
if (_s.type() == typeid(VariableDeclaration)) if (_s.type() == typeid(VariableDeclaration))
{ {
@ -213,7 +213,7 @@ void IntroduceControlFlowSSA::operator()(Block& _block)
iterateReplacing( iterateReplacing(
_block.statements, _block.statements,
[&](Statement& _s) -> boost::optional<vector<Statement>> [&](Statement& _s) -> std::optional<vector<Statement>>
{ {
vector<Statement> toPrepend; vector<Statement> toPrepend;
for (YulString toReassign: m_variablesToReassign) for (YulString toReassign: m_variablesToReassign)
@ -253,7 +253,7 @@ void IntroduceControlFlowSSA::operator()(Block& _block)
else else
{ {
toPrepend.emplace_back(std::move(_s)); toPrepend.emplace_back(std::move(_s));
return toPrepend; return {std::move(toPrepend)};
} }
} }
); );

View File

@ -64,7 +64,7 @@ bool SimplificationRules::isInitialized() const
return !m_rules[uint8_t(dev::eth::Instruction::ADD)].empty(); return !m_rules[uint8_t(dev::eth::Instruction::ADD)].empty();
} }
boost::optional<std::pair<dev::eth::Instruction, vector<Expression> const*>> std::optional<std::pair<dev::eth::Instruction, vector<Expression> const*>>
SimplificationRules::instructionAndArguments(Dialect const& _dialect, Expression const& _expr) SimplificationRules::instructionAndArguments(Dialect const& _dialect, Expression const& _expr)
{ {
if (_expr.type() == typeid(FunctionalInstruction)) if (_expr.type() == typeid(FunctionalInstruction))

View File

@ -26,9 +26,9 @@
#include <libyul/AsmData.h> #include <libyul/AsmData.h>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <functional> #include <functional>
#include <optional>
#include <vector> #include <vector>
namespace yul namespace yul
@ -57,7 +57,7 @@ public:
/// by the constructor, but we had some issues with static initialization. /// by the constructor, but we had some issues with static initialization.
bool isInitialized() const; bool isInitialized() const;
static boost::optional<std::pair<dev::eth::Instruction, std::vector<Expression> const*>> static std::optional<std::pair<dev::eth::Instruction, std::vector<Expression> const*>>
instructionAndArguments(Dialect const& _dialect, Expression const& _expr); instructionAndArguments(Dialect const& _dialect, Expression const& _expr);
private: private:

View File

@ -28,7 +28,7 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace yul; using namespace yul;
using OptionalStatements = boost::optional<vector<Statement>>; using OptionalStatements = std::optional<vector<Statement>>;
namespace { namespace {
@ -54,7 +54,7 @@ OptionalStatements replaceConstArgSwitch(Switch& _switchStmt, u256 const& _const
if (matchingCaseBlock) if (matchingCaseBlock)
return make_vector<Statement>(std::move(*matchingCaseBlock)); return make_vector<Statement>(std::move(*matchingCaseBlock));
else else
return {{}}; return optional<vector<Statement>>{vector<Statement>{}};
} }
} }
@ -80,8 +80,8 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
return {}; return {};
}, },
[&](Switch& _switchStmt) -> OptionalStatements { [&](Switch& _switchStmt) -> OptionalStatements {
if (boost::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression)) if (std::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression))
return replaceConstArgSwitch(_switchStmt, constExprVal.get()); return replaceConstArgSwitch(_switchStmt, constExprVal.value());
return {}; return {};
}, },
[&](ForLoop& _forLoop) -> OptionalStatements { [&](ForLoop& _forLoop) -> OptionalStatements {
@ -107,7 +107,7 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
bool StructuralSimplifier::expressionAlwaysTrue(Expression const& _expression) bool StructuralSimplifier::expressionAlwaysTrue(Expression const& _expression)
{ {
if (boost::optional<u256> value = hasLiteralValue(_expression)) if (std::optional<u256> value = hasLiteralValue(_expression))
return *value != 0; return *value != 0;
else else
return false; return false;
@ -115,16 +115,16 @@ bool StructuralSimplifier::expressionAlwaysTrue(Expression const& _expression)
bool StructuralSimplifier::expressionAlwaysFalse(Expression const& _expression) bool StructuralSimplifier::expressionAlwaysFalse(Expression const& _expression)
{ {
if (boost::optional<u256> value = hasLiteralValue(_expression)) if (std::optional<u256> value = hasLiteralValue(_expression))
return *value == 0; return *value == 0;
else else
return false; return false;
} }
boost::optional<dev::u256> StructuralSimplifier::hasLiteralValue(Expression const& _expression) const std::optional<dev::u256> StructuralSimplifier::hasLiteralValue(Expression const& _expression) const
{ {
if (_expression.type() == typeid(Literal)) if (_expression.type() == typeid(Literal))
return valueOfLiteral(boost::get<Literal>(_expression)); return valueOfLiteral(boost::get<Literal>(_expression));
else else
return boost::optional<u256>(); return std::optional<u256>();
} }

View File

@ -51,7 +51,7 @@ private:
void simplify(std::vector<Statement>& _statements); void simplify(std::vector<Statement>& _statements);
bool expressionAlwaysTrue(Expression const& _expression); bool expressionAlwaysTrue(Expression const& _expression);
bool expressionAlwaysFalse(Expression const& _expression); bool expressionAlwaysFalse(Expression const& _expression);
boost::optional<dev::u256> hasLiteralValue(Expression const& _expression) const; std::optional<dev::u256> hasLiteralValue(Expression const& _expression) const;
}; };
} }

View File

@ -29,7 +29,7 @@ void VarDeclInitializer::operator()(Block& _block)
{ {
ASTModifier::operator()(_block); ASTModifier::operator()(_block);
using OptionalStatements = boost::optional<vector<Statement>>; using OptionalStatements = std::optional<vector<Statement>>;
GenericFallbackReturnsVisitor<OptionalStatements, VariableDeclaration> visitor{ GenericFallbackReturnsVisitor<OptionalStatements, VariableDeclaration> visitor{
[](VariableDeclaration& _varDecl) -> OptionalStatements [](VariableDeclaration& _varDecl) -> OptionalStatements
{ {

View File

@ -869,7 +869,7 @@ bool CommandLineInterface::processInput()
if (m_args.count(g_strEVMVersion)) if (m_args.count(g_strEVMVersion))
{ {
string versionOptionStr = m_args[g_strEVMVersion].as<string>(); string versionOptionStr = m_args[g_strEVMVersion].as<string>();
boost::optional<langutil::EVMVersion> versionOption = langutil::EVMVersion::fromString(versionOptionStr); std::optional<langutil::EVMVersion> versionOption = langutil::EVMVersion::fromString(versionOptionStr);
if (!versionOption) if (!versionOption)
{ {
serr() << "Invalid option for --evm-version: " << versionOptionStr << endl; serr() << "Invalid option for --evm-version: " << versionOptionStr << endl;

View File

@ -150,7 +150,7 @@ private:
bytes const& m_metadata; bytes const& m_metadata;
}; };
boost::optional<map<string, string>> parseCBORMetadata(bytes const& _metadata) std::optional<map<string, string>> parseCBORMetadata(bytes const& _metadata)
{ {
try try
{ {

View File

@ -21,9 +21,8 @@
#include <libdevcore/CommonData.h> #include <libdevcore/CommonData.h>
#include <boost/optional.hpp>
#include <map> #include <map>
#include <optional>
#include <string> #include <string>
namespace dev namespace dev
@ -48,7 +47,7 @@ std::string bytecodeSansMetadata(std::string const& _bytecode);
/// - bytes into hex strings /// - bytes into hex strings
/// - booleans into "true"/"false" strings /// - booleans into "true"/"false" strings
/// - everything else is invalid /// - everything else is invalid
boost::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata); std::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata);
/// Expects a serialised metadata JSON and returns true if the /// Expects a serialised metadata JSON and returns true if the
/// content is valid metadata. /// content is valid metadata.

View File

@ -184,7 +184,7 @@ bool EVMVersionRestrictedTestCase::validateSettings(langutil::EVMVersion _evmVer
break; break;
versionString = versionString.substr(versionBegin); versionString = versionString.substr(versionBegin);
boost::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(versionString); std::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(versionString);
if (!version) if (!version)
throw runtime_error("Invalid EVM version: \"" + versionString + "\""); throw runtime_error("Invalid EVM version: \"" + versionString + "\"");

View File

@ -34,7 +34,7 @@ BOOST_AUTO_TEST_SUITE(IterateReplacing)
BOOST_AUTO_TEST_CASE(no_replacement) BOOST_AUTO_TEST_CASE(no_replacement)
{ {
vector<string> v{"abc", "def", "ghi"}; vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; }; function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
iterateReplacing(v, f); iterateReplacing(v, f);
vector<string> expectation{"abc", "def", "ghi"}; vector<string> expectation{"abc", "def", "ghi"};
BOOST_CHECK(v == expectation); BOOST_CHECK(v == expectation);
@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(no_replacement)
BOOST_AUTO_TEST_CASE(empty_input) BOOST_AUTO_TEST_CASE(empty_input)
{ {
vector<string> v; vector<string> v;
function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; }; function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
iterateReplacing(v, f); iterateReplacing(v, f);
vector<string> expectation; vector<string> expectation;
BOOST_CHECK(v == expectation); BOOST_CHECK(v == expectation);
@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(empty_input)
BOOST_AUTO_TEST_CASE(delete_some) BOOST_AUTO_TEST_CASE(delete_some)
{ {
vector<string> v{"abc", "def", "ghi"}; vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> { function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "def") if (_s == "def")
return vector<string>(); return vector<string>();
else else
@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(delete_some)
BOOST_AUTO_TEST_CASE(inject_some_start) BOOST_AUTO_TEST_CASE(inject_some_start)
{ {
vector<string> v{"abc", "def", "ghi"}; vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> { function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "abc") if (_s == "abc")
return vector<string>{"x", "y"}; return vector<string>{"x", "y"};
else else
@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(inject_some_start)
BOOST_AUTO_TEST_CASE(inject_some_end) BOOST_AUTO_TEST_CASE(inject_some_end)
{ {
vector<string> v{"abc", "def", "ghi"}; vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> { function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "ghi") if (_s == "ghi")
return vector<string>{"x", "y"}; return vector<string>{"x", "y"};
else else

View File

@ -34,11 +34,11 @@
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory> #include <memory>
#include <optional>
#include <string>
using namespace std; using namespace std;
using namespace langutil; using namespace langutil;
@ -54,7 +54,7 @@ namespace test
namespace namespace
{ {
boost::optional<Error> parseAndReturnFirstError( std::optional<Error> parseAndReturnFirstError(
string const& _source, string const& _source,
bool _assemble = false, bool _assemble = false,
bool _allowWarnings = true, bool _allowWarnings = true,

View File

@ -41,7 +41,7 @@ map<string, string> requireParsedCBORMetadata(bytes const& _bytecode)
{ {
bytes cborMetadata = dev::test::onlyMetadata(_bytecode); bytes cborMetadata = dev::test::onlyMetadata(_bytecode);
BOOST_REQUIRE(!cborMetadata.empty()); BOOST_REQUIRE(!cborMetadata.empty());
boost::optional<map<string, string>> tmp = dev::test::parseCBORMetadata(cborMetadata); std::optional<map<string, string>> tmp = dev::test::parseCBORMetadata(cborMetadata);
BOOST_REQUIRE(tmp); BOOST_REQUIRE(tmp);
return *tmp; return *tmp;
} }

View File

@ -104,7 +104,7 @@ public:
/// @returns the number of instructions in the given bytecode, not taking the metadata hash /// @returns the number of instructions in the given bytecode, not taking the metadata hash
/// into account. /// into account.
size_t numInstructions(bytes const& _bytecode, boost::optional<Instruction> _which = boost::optional<Instruction>{}) size_t numInstructions(bytes const& _bytecode, std::optional<Instruction> _which = std::optional<Instruction>{})
{ {
bytes realCode = bytecodeSansMetadata(_bytecode); bytes realCode = bytecodeSansMetadata(_bytecode);
BOOST_REQUIRE_MESSAGE(!realCode.empty(), "Invalid or missing metadata in bytecode."); BOOST_REQUIRE_MESSAGE(!realCode.empty(), "Invalid or missing metadata in bytecode.");

View File

@ -141,14 +141,14 @@ string functionSignatureFromABI(Json::Value const& _functionABI)
} }
boost::optional<dev::solidity::test::ParameterList> ContractABIUtils::parametersFromJsonOutputs( std::optional<dev::solidity::test::ParameterList> ContractABIUtils::parametersFromJsonOutputs(
ErrorReporter& _errorReporter, ErrorReporter& _errorReporter,
Json::Value const& _contractABI, Json::Value const& _contractABI,
string const& _functionSignature string const& _functionSignature
) )
{ {
if (!_contractABI) if (!_contractABI)
return boost::none; return std::nullopt;
for (auto const& function: _contractABI) for (auto const& function: _contractABI)
if (_functionSignature == functionSignatureFromABI(function)) if (_functionSignature == functionSignatureFromABI(function))
@ -177,17 +177,17 @@ boost::optional<dev::solidity::test::ParameterList> ContractABIUtils::parameters
"Could not convert \"" + type + "Could not convert \"" + type +
"\" to internal ABI type representation. Falling back to default encoding." "\" to internal ABI type representation. Falling back to default encoding."
); );
return boost::none; return std::nullopt;
} }
finalParams += inplaceTypeParams; finalParams += inplaceTypeParams;
inplaceTypeParams.clear(); inplaceTypeParams.clear();
} }
return boost::optional<ParameterList>(finalParams + dynamicTypeParams); return std::optional<ParameterList>(finalParams + dynamicTypeParams);
} }
return boost::none; return std::nullopt;
} }
bool ContractABIUtils::appendTypesFromName( bool ContractABIUtils::appendTypesFromName(

View File

@ -42,7 +42,7 @@ public:
/// a list of internal type representations of isoltest. /// a list of internal type representations of isoltest.
/// Creates parameters from Contract ABI and is used to generate values for /// Creates parameters from Contract ABI and is used to generate values for
/// auto-correction during interactive update routine. /// auto-correction during interactive update routine.
static boost::optional<ParameterList> parametersFromJsonOutputs( static std::optional<ParameterList> parametersFromJsonOutputs(
ErrorReporter& _errorReporter, ErrorReporter& _errorReporter,
Json::Value const& _contractABI, Json::Value const& _contractABI,
std::string const& _functionSignature std::string const& _functionSignature

View File

@ -24,11 +24,11 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <optional>
#include <stdexcept> #include <stdexcept>
using namespace dev; using namespace dev;

View File

@ -20,8 +20,8 @@
#include <libdevcore/AnsiColorized.h> #include <libdevcore/AnsiColorized.h>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/optional/optional.hpp>
#include <optional>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -124,12 +124,12 @@ string TestFunctionCall::format(
if (!matchesExpectation()) if (!matchesExpectation())
{ {
boost::optional<ParameterList> abiParams; std::optional<ParameterList> abiParams;
if (isFailure) if (isFailure)
{ {
if (!output.empty()) if (!output.empty())
abiParams = boost::make_optional(ContractABIUtils::failureParameters(output)); abiParams = ContractABIUtils::failureParameters(output);
} }
else else
abiParams = ContractABIUtils::parametersFromJsonOutputs( abiParams = ContractABIUtils::parametersFromJsonOutputs(
@ -139,7 +139,7 @@ string TestFunctionCall::format(
); );
string bytesOutput = abiParams ? string bytesOutput = abiParams ?
BytesUtils::formatRawBytes(output, abiParams.get(), _linePrefix) : BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
BytesUtils::formatRawBytes( BytesUtils::formatRawBytes(
output, output,
ContractABIUtils::defaultParameters(ceil(output.size() / 32)), ContractABIUtils::defaultParameters(ceil(output.size() / 32)),
@ -208,7 +208,7 @@ string TestFunctionCall::formatBytesParameters(
} }
else else
{ {
boost::optional<ParameterList> abiParams = ContractABIUtils::parametersFromJsonOutputs( std::optional<ParameterList> abiParams = ContractABIUtils::parametersFromJsonOutputs(
_errorReporter, _errorReporter,
m_contractABI, m_contractABI,
_signature _signature
@ -216,17 +216,17 @@ string TestFunctionCall::formatBytesParameters(
if (abiParams) if (abiParams)
{ {
boost::optional<ParameterList> preferredParams = ContractABIUtils::preferredParameters( std::optional<ParameterList> preferredParams = ContractABIUtils::preferredParameters(
_errorReporter, _errorReporter,
_parameters, _parameters,
abiParams.get(), abiParams.value(),
_bytes _bytes
); );
if (preferredParams) if (preferredParams)
{ {
ContractABIUtils::overwriteParameters(_errorReporter, preferredParams.get(), abiParams.get()); ContractABIUtils::overwriteParameters(_errorReporter, preferredParams.value(), abiParams.value());
os << BytesUtils::formatBytesRange(_bytes, preferredParams.get(), _highlight); os << BytesUtils::formatBytesRange(_bytes, preferredParams.value(), _highlight);
} }
} }
else else

View File

@ -27,11 +27,11 @@
#include <libsolidity/interface/OptimiserSettings.h> #include <libsolidity/interface/OptimiserSettings.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory> #include <memory>
#include <optional>
#include <string>
using namespace std; using namespace std;
using namespace langutil; using namespace langutil;
@ -63,7 +63,7 @@ std::pair<bool, ErrorList> parse(string const& _source)
return {false, {}}; return {false, {}};
} }
boost::optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true) std::optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true)
{ {
bool success; bool success;
ErrorList errors; ErrorList errors;

View File

@ -31,11 +31,11 @@
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h> #include <liblangutil/ErrorReporter.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory> #include <memory>
#include <optional>
#include <string>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -61,7 +61,7 @@ bool parse(string const& _source, Dialect const& _dialect, ErrorReporter& errorR
return (yul::AsmAnalyzer( return (yul::AsmAnalyzer(
analysisInfo, analysisInfo,
errorReporter, errorReporter,
boost::none, std::nullopt,
_dialect _dialect
)).analyze(*parserResult); )).analyze(*parserResult);
} }
@ -73,7 +73,7 @@ bool parse(string const& _source, Dialect const& _dialect, ErrorReporter& errorR
return false; return false;
} }
boost::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarnings = true) std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarnings = true)
{ {
ErrorList errors; ErrorList errors;
ErrorReporter errorReporter(errors); ErrorReporter errorReporter(errors);

View File

@ -350,7 +350,7 @@ void setupTerminal()
#endif #endif
} }
boost::optional<TestStats> runTestSuite( std::optional<TestStats> runTestSuite(
TestCreator _testCaseCreator, TestCreator _testCaseCreator,
TestOptions const& _options, TestOptions const& _options,
fs::path const& _basePath, fs::path const& _basePath,
@ -364,7 +364,7 @@ boost::optional<TestStats> runTestSuite(
if (!fs::exists(testPath) || !fs::is_directory(testPath)) if (!fs::exists(testPath) || !fs::is_directory(testPath))
{ {
cerr << _name << " tests not found. Use the --testpath argument." << endl; cerr << _name << " tests not found. Use the --testpath argument." << endl;
return {}; return std::nullopt;
} }
TestStats stats = TestTool::processPath( TestStats stats = TestTool::processPath(