mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7551 from ethereum/060-cxx17-std-optional
Use `std::optional<>` rather than `boost::optional<>`
This commit is contained in:
@@ -122,7 +122,7 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName)
|
||||
if (!_typeName.annotation().type)
|
||||
{
|
||||
_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
|
||||
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
|
||||
// We use the latest EVM version because we will re-run it anyway.
|
||||
yul::AsmAnalysisInfo analysisInfo;
|
||||
boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
|
||||
std::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
|
||||
yul::AsmAnalyzer(
|
||||
analysisInfo,
|
||||
errorsIgnored,
|
||||
|
||||
@@ -241,7 +241,7 @@ void ViewPureChecker::endVisit(InlineAssembly const& _inlineAssembly)
|
||||
void ViewPureChecker::reportMutability(
|
||||
StateMutability _mutability,
|
||||
SourceLocation const& _location,
|
||||
boost::optional<SourceLocation> const& _nestedLocation
|
||||
std::optional<SourceLocation> const& _nestedLocation
|
||||
)
|
||||
{
|
||||
if (_mutability > m_bestMutabilityAndLocation.mutability)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
@@ -67,7 +68,7 @@ private:
|
||||
void reportMutability(
|
||||
StateMutability _mutability,
|
||||
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;
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <json/json.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -912,10 +913,10 @@ public:
|
||||
ElementaryTypeName(
|
||||
SourceLocation const& _location,
|
||||
ElementaryTypeNameToken const& _elem,
|
||||
boost::optional<StateMutability> _stateMutability = {}
|
||||
std::optional<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;
|
||||
@@ -923,11 +924,11 @@ public:
|
||||
|
||||
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:
|
||||
ElementaryTypeNameToken m_type;
|
||||
boost::optional<StateMutability> m_stateMutability; ///< state mutability for address type
|
||||
std::optional<StateMutability> m_stateMutability; ///< state mutability for address type
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,10 +26,9 @@
|
||||
#include <libsolidity/ast/ASTEnums.h>
|
||||
#include <libsolidity/ast/ExperimentalFeatures.h>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
@@ -183,7 +182,7 @@ struct ExpressionAnnotation: ASTAnnotation
|
||||
|
||||
/// Types and - if given - names of arguments if the expr. is a function
|
||||
/// that is called, used for overload resoultion
|
||||
boost::optional<FuncCallArguments> arguments;
|
||||
std::optional<FuncCallArguments> arguments;
|
||||
};
|
||||
|
||||
struct IdentifierAnnotation: ExpressionAnnotation
|
||||
|
||||
@@ -148,7 +148,7 @@ Json::Value ASTJsonConverter::typePointerToJson(TypePointer _tp, bool _short)
|
||||
return typeDescriptions;
|
||||
|
||||
}
|
||||
Json::Value ASTJsonConverter::typePointerToJson(boost::optional<FuncCallArguments> const& _tps)
|
||||
Json::Value ASTJsonConverter::typePointerToJson(std::optional<FuncCallArguments> const& _tps)
|
||||
{
|
||||
if (_tps)
|
||||
{
|
||||
|
||||
@@ -27,10 +27,12 @@
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
@@ -169,7 +171,7 @@ private:
|
||||
return json;
|
||||
}
|
||||
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(
|
||||
std::vector<std::pair<std::string, Json::Value>> &_attributes,
|
||||
ExpressionAnnotation const& _annotation
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
namespace dev
|
||||
|
||||
@@ -1812,10 +1812,10 @@ TypePointer ArrayType::decodingType() 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;
|
||||
|
||||
if (!_inLibrary && m_interfaceType.is_initialized())
|
||||
if (!_inLibrary && m_interfaceType.has_value())
|
||||
return *m_interfaceType;
|
||||
|
||||
TypeResult result{TypePointer{}};
|
||||
@@ -2106,10 +2106,10 @@ MemberList::MemberMap StructType::nativeMembers(ContractDefinition const*) 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;
|
||||
|
||||
if (!_inLibrary && m_interfaceType.is_initialized())
|
||||
if (!_inLibrary && m_interfaceType.has_value())
|
||||
return *m_interfaceType;
|
||||
|
||||
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.";
|
||||
|
||||
@@ -2179,13 +2179,13 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
|
||||
else
|
||||
m_interfaceType_library = TypeProvider::withLocation(this, DataLocation::Memory, true);
|
||||
|
||||
if (m_recursive.get())
|
||||
if (m_recursive.value())
|
||||
m_interfaceType = TypeResult::err(recursiveErrMsg);
|
||||
|
||||
return *m_interfaceType_library;
|
||||
}
|
||||
|
||||
if (m_recursive.get())
|
||||
if (m_recursive.value())
|
||||
m_interfaceType = TypeResult::err(recursiveErrMsg);
|
||||
else if (!result.message().empty())
|
||||
m_interfaceType = result;
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libdevcore/Result.h>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/rational.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
@@ -769,8 +769,8 @@ private:
|
||||
Type const* m_baseType;
|
||||
bool m_hasDynamicLength = true;
|
||||
u256 m_length;
|
||||
mutable boost::optional<TypeResult> m_interfaceType;
|
||||
mutable boost::optional<TypeResult> m_interfaceType_library;
|
||||
mutable std::optional<TypeResult> m_interfaceType;
|
||||
mutable std::optional<TypeResult> m_interfaceType_library;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -865,12 +865,12 @@ public:
|
||||
|
||||
bool recursive() const
|
||||
{
|
||||
if (m_recursive.is_initialized())
|
||||
return m_recursive.get();
|
||||
if (m_recursive.has_value())
|
||||
return m_recursive.value();
|
||||
|
||||
interfaceType(false);
|
||||
|
||||
return m_recursive.get();
|
||||
return m_recursive.value();
|
||||
}
|
||||
|
||||
std::unique_ptr<ReferenceType> copyForLocation(DataLocation _location, bool _isPointer) const override;
|
||||
@@ -898,9 +898,9 @@ public:
|
||||
private:
|
||||
StructDefinition const& m_struct;
|
||||
// Caches for interfaceType(bool)
|
||||
mutable boost::optional<TypeResult> m_interfaceType;
|
||||
mutable boost::optional<TypeResult> m_interfaceType_library;
|
||||
mutable boost::optional<bool> m_recursive;
|
||||
mutable std::optional<TypeResult> m_interfaceType;
|
||||
mutable std::optional<TypeResult> m_interfaceType_library;
|
||||
mutable std::optional<bool> m_recursive;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -411,7 +411,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
analyzerResult = yul::AsmAnalyzer(
|
||||
analysisInfo,
|
||||
errorReporter,
|
||||
boost::none,
|
||||
std::nullopt,
|
||||
dialect,
|
||||
identifierAccess.resolve
|
||||
).analyze(*parserResult);
|
||||
|
||||
@@ -962,11 +962,11 @@ string YulUtilFunctions::readFromCalldata(Type const& _type)
|
||||
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 =
|
||||
"update_storage_value_" +
|
||||
(_offset.is_initialized() ? ("offset_" + to_string(*_offset)) : "") +
|
||||
(_offset.has_value() ? ("offset_" + to_string(*_offset)) : "") +
|
||||
_type.identifier();
|
||||
|
||||
return m_functionCollector->createFunction(functionName, [&] {
|
||||
@@ -983,11 +983,11 @@ string YulUtilFunctions::updateStorageValueFunction(Type const& _type, boost::op
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("update",
|
||||
_offset.is_initialized() ?
|
||||
_offset.has_value() ?
|
||||
updateByteSliceFunction(_type.storageBytes(), *_offset) :
|
||||
updateByteSliceFunctionDynamic(_type.storageBytes())
|
||||
)
|
||||
("offset", _offset.is_initialized() ? "" : "offset, ")
|
||||
("offset", _offset.has_value() ? "" : "offset, ")
|
||||
("prepare", prepareStoreFunction(_type))
|
||||
.render();
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
/// the specified slot and offset. If offset is not given, it is expected as
|
||||
/// runtime parameter.
|
||||
/// 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
|
||||
/// the specified address.
|
||||
|
||||
@@ -115,7 +115,7 @@ string IRStorageItem::storeValue(string const& _value, Type const& _sourceType)
|
||||
if (m_type->isValueType())
|
||||
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))
|
||||
offset = get<unsigned>(m_offset);
|
||||
|
||||
@@ -95,7 +95,7 @@ CompilerStack::~CompilerStack()
|
||||
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(), '=');
|
||||
if (eq == _remapping.end())
|
||||
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
void reset(bool _keepSettings = false);
|
||||
|
||||
// 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.
|
||||
/// Must be set before parsing.
|
||||
|
||||
@@ -31,8 +31,9 @@
|
||||
|
||||
#include <boost/algorithm/cxx11/any_of.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
@@ -317,7 +318,7 @@ Json::Value collectEVMObject(eth::LinkerObject const& _object, string const* _so
|
||||
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())
|
||||
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))
|
||||
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"};
|
||||
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"};
|
||||
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"};
|
||||
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"};
|
||||
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"};
|
||||
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"};
|
||||
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))
|
||||
{
|
||||
@@ -376,7 +377,7 @@ boost::optional<Json::Value> checkOptimizerDetail(Json::Value const& _details, s
|
||||
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())
|
||||
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");
|
||||
}
|
||||
|
||||
boost::optional<Json::Value> checkOutputSelection(Json::Value const& _outputSelection)
|
||||
std::optional<Json::Value> checkOutputSelection(Json::Value const& _outputSelection)
|
||||
{
|
||||
if (!!_outputSelection && !_outputSelection.isObject())
|
||||
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.
|
||||
/// On error returns the json-formatted error message.
|
||||
@@ -635,7 +636,7 @@ boost::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompile
|
||||
{
|
||||
if (!settings["evmVersion"].isString())
|
||||
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)
|
||||
return formatFatalError("JSONError", "Invalid EVM version requested.");
|
||||
ret.evmVersion = *version;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <libsolidity/interface/CompilerStack.h>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <optional>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
namespace dev
|
||||
|
||||
@@ -874,7 +874,9 @@ ASTPointer<TypeName> Parser::parseTypeName(bool _allowVar)
|
||||
ASTNodeFactory nodeFactory(*this);
|
||||
nodeFactory.markEndPosition();
|
||||
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 (elemTypeName.token() == Token::Address)
|
||||
|
||||
Reference in New Issue
Block a user