Merge pull request #14488 from ethereum/purge-using-namespace-std-from-libsolidity-analysis

Purge using namespace std from libsolidity/analysis
This commit is contained in:
Nikola Matić 2023-08-14 14:53:32 +02:00 committed by GitHub
commit b4d4b49dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 331 additions and 353 deletions

View File

@ -29,7 +29,6 @@
#include <limits>
using namespace std;
using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::langutil;
@ -47,9 +46,9 @@ bool fitsPrecisionExp(bigint const& _base, bigint const& _exp)
solAssert(_base > 0, "");
size_t const bitsMax = 4096;
std::size_t const bitsMax = 4096;
size_t mostSignificantBaseBit = static_cast<size_t>(boost::multiprecision::msb(_base));
std::size_t mostSignificantBaseBit = static_cast<std::size_t>(boost::multiprecision::msb(_base));
if (mostSignificantBaseBit == 0) // _base == 1
return true;
if (mostSignificantBaseBit > bitsMax) // _base >= 2 ^ 4096
@ -68,7 +67,7 @@ bool fitsPrecisionBase2(bigint const& _mantissa, uint32_t _expBase2)
}
optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, rational const& _left, rational const& _right)
std::optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, rational const& _left, rational const& _right)
{
bool fractional = _left.denominator() != 1 || _right.denominator() != 1;
switch (_operator)
@ -76,17 +75,17 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
//bit operations will only be enabled for integers and fixed types that resemble integers
case Token::BitOr:
if (fractional)
return nullopt;
return std::nullopt;
else
return _left.numerator() | _right.numerator();
case Token::BitXor:
if (fractional)
return nullopt;
return std::nullopt;
else
return _left.numerator() ^ _right.numerator();
case Token::BitAnd:
if (fractional)
return nullopt;
return std::nullopt;
else
return _left.numerator() & _right.numerator();
case Token::Add: return _left + _right;
@ -94,12 +93,12 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
case Token::Mul: return _left * _right;
case Token::Div:
if (_right == rational(0))
return nullopt;
return std::nullopt;
else
return _left / _right;
case Token::Mod:
if (_right == rational(0))
return nullopt;
return std::nullopt;
else if (fractional)
{
rational tempValue = _left / _right;
@ -111,7 +110,7 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
case Token::Exp:
{
if (_right.denominator() != 1)
return nullopt;
return std::nullopt;
bigint const& exp = _right.numerator();
// x ** 0 = 1
@ -127,13 +126,13 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
}
else
{
if (abs(exp) > numeric_limits<uint32_t>::max())
return nullopt; // This will need too much memory to represent.
if (abs(exp) > std::numeric_limits<uint32_t>::max())
return std::nullopt; // This will need too much memory to represent.
uint32_t absExp = bigint(abs(exp)).convert_to<uint32_t>();
if (!fitsPrecisionExp(abs(_left.numerator()), absExp) || !fitsPrecisionExp(abs(_left.denominator()), absExp))
return nullopt;
return std::nullopt;
static auto const optimizedPow = [](bigint const& _base, uint32_t _exponent) -> bigint {
if (_base == 1)
@ -158,18 +157,18 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
case Token::SHL:
{
if (fractional)
return nullopt;
return std::nullopt;
else if (_right < 0)
return nullopt;
else if (_right > numeric_limits<uint32_t>::max())
return nullopt;
return std::nullopt;
else if (_right > std::numeric_limits<uint32_t>::max())
return std::nullopt;
if (_left.numerator() == 0)
return 0;
else
{
uint32_t exponent = _right.numerator().convert_to<uint32_t>();
if (!fitsPrecisionBase2(abs(_left.numerator()), exponent))
return nullopt;
return std::nullopt;
return _left.numerator() * boost::multiprecision::pow(bigint(2), exponent);
}
break;
@ -179,11 +178,11 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
case Token::SAR:
{
if (fractional)
return nullopt;
return std::nullopt;
else if (_right < 0)
return nullopt;
else if (_right > numeric_limits<uint32_t>::max())
return nullopt;
return std::nullopt;
else if (_right > std::numeric_limits<uint32_t>::max())
return std::nullopt;
if (_left.numerator() == 0)
return 0;
else
@ -209,60 +208,60 @@ optional<rational> ConstantEvaluator::evaluateBinaryOperator(Token _operator, ra
break;
}
default:
return nullopt;
return std::nullopt;
}
}
optional<rational> ConstantEvaluator::evaluateUnaryOperator(Token _operator, rational const& _input)
std::optional<rational> ConstantEvaluator::evaluateUnaryOperator(Token _operator, rational const& _input)
{
switch (_operator)
{
case Token::BitNot:
if (_input.denominator() != 1)
return nullopt;
return std::nullopt;
else
return ~_input.numerator();
case Token::Sub:
return -_input;
default:
return nullopt;
return std::nullopt;
}
}
namespace
{
optional<TypedRational> convertType(rational const& _value, Type const& _type)
std::optional<TypedRational> convertType(rational const& _value, Type const& _type)
{
if (_type.category() == Type::Category::RationalNumber)
return TypedRational{TypeProvider::rationalNumber(_value), _value};
else if (auto const* integerType = dynamic_cast<IntegerType const*>(&_type))
{
if (_value > integerType->maxValue() || _value < integerType->minValue())
return nullopt;
return std::nullopt;
else
return TypedRational{&_type, _value.numerator() / _value.denominator()};
}
else
return nullopt;
return std::nullopt;
}
optional<TypedRational> convertType(optional<TypedRational> const& _value, Type const& _type)
std::optional<TypedRational> convertType(std::optional<TypedRational> const& _value, Type const& _type)
{
return _value ? convertType(_value->value, _type) : nullopt;
return _value ? convertType(_value->value, _type) : std::nullopt;
}
optional<TypedRational> constantToTypedValue(Type const& _type)
std::optional<TypedRational> constantToTypedValue(Type const& _type)
{
if (_type.category() == Type::Category::RationalNumber)
return TypedRational{&_type, dynamic_cast<RationalNumberType const&>(_type).value()};
else
return nullopt;
return std::nullopt;
}
}
optional<TypedRational> ConstantEvaluator::evaluate(
std::optional<TypedRational> ConstantEvaluator::evaluate(
langutil::ErrorReporter& _errorReporter,
Expression const& _expr
)
@ -271,7 +270,7 @@ optional<TypedRational> ConstantEvaluator::evaluate(
}
optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
std::optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
{
if (!m_values.count(&_node))
{
@ -280,7 +279,7 @@ optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
solAssert(varDecl->isConstant(), "");
// In some circumstances, we do not yet have a type for the variable.
if (!varDecl->value() || !varDecl->type())
m_values[&_node] = nullopt;
m_values[&_node] = std::nullopt;
else
{
m_depth++;
@ -298,7 +297,7 @@ optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
{
expression->accept(*this);
if (!m_values.count(&_node))
m_values[&_node] = nullopt;
m_values[&_node] = std::nullopt;
}
}
return m_values.at(&_node);
@ -306,7 +305,7 @@ optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
{
optional<TypedRational> value = evaluate(_operation.subExpression());
std::optional<TypedRational> value = evaluate(_operation.subExpression());
if (!value)
return;
@ -317,9 +316,9 @@ void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
if (!value)
return;
if (optional<rational> result = evaluateUnaryOperator(_operation.getOperator(), value->value))
if (std::optional<rational> result = evaluateUnaryOperator(_operation.getOperator(), value->value))
{
optional<TypedRational> convertedValue = convertType(*result, *resultType);
std::optional<TypedRational> convertedValue = convertType(*result, *resultType);
if (!convertedValue)
m_errorReporter.fatalTypeError(
3667_error,
@ -332,8 +331,8 @@ void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
{
optional<TypedRational> left = evaluate(_operation.leftExpression());
optional<TypedRational> right = evaluate(_operation.rightExpression());
std::optional<TypedRational> left = evaluate(_operation.leftExpression());
std::optional<TypedRational> right = evaluate(_operation.rightExpression());
if (!left || !right)
return;
@ -349,7 +348,7 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
6020_error,
_operation.location(),
"Operator " +
string(TokenTraits::toString(_operation.getOperator())) +
std::string(TokenTraits::toString(_operation.getOperator())) +
" not compatible with types " +
left->type->toString() +
" and " +
@ -363,9 +362,9 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
if (!left || !right)
return;
if (optional<rational> value = evaluateBinaryOperator(_operation.getOperator(), left->value, right->value))
if (std::optional<rational> value = evaluateBinaryOperator(_operation.getOperator(), left->value, right->value))
{
optional<TypedRational> convertedValue = convertType(*value, *resultType);
std::optional<TypedRational> convertedValue = convertType(*value, *resultType);
if (!convertedValue)
m_errorReporter.fatalTypeError(
2643_error,

View File

@ -32,7 +32,6 @@
#include <range/v3/view/reverse.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -49,10 +48,10 @@ bool hasEqualExternalCallableParameters(T const& _a, B const& _b)
}
template<typename T>
map<ASTString, vector<T const*>> filterDeclarations(
map<ASTString, vector<Declaration const*>> const& _declarations)
std::map<ASTString, std::vector<T const*>> filterDeclarations(
std::map<ASTString, std::vector<Declaration const*>> const& _declarations)
{
map<ASTString, vector<T const*>> filteredDeclarations;
std::map<ASTString, std::vector<T const*>> filteredDeclarations;
for (auto const& [name, overloads]: _declarations)
for (auto const* declaration: overloads)
if (auto typedDeclaration = dynamic_cast<T const*>(declaration))
@ -106,7 +105,7 @@ void ContractLevelChecker::checkDuplicateFunctions(ContractDefinition const& _co
{
/// Checks that two functions with the same name defined in this contract have different
/// argument types and that there is at most one constructor.
map<string, vector<FunctionDefinition const*>> functions;
std::map<std::string, std::vector<FunctionDefinition const*>> functions;
FunctionDefinition const* constructor = nullptr;
FunctionDefinition const* fallback = nullptr;
FunctionDefinition const* receive = nullptr;
@ -157,7 +156,7 @@ void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contr
{
/// Checks that two events with the same name defined in this contract have different
/// argument types
map<string, vector<EventDefinition const*>> events;
std::map<std::string, std::vector<EventDefinition const*>> events;
for (auto const* contract: _contract.annotation().linearizedBaseContracts)
for (EventDefinition const* event: contract->events())
events[event->name()].push_back(event);
@ -195,12 +194,12 @@ void ContractLevelChecker::checkReceiveFunction(ContractDefinition const& _contr
}
template <class T>
void ContractLevelChecker::findDuplicateDefinitions(map<string, vector<T>> const& _definitions)
void ContractLevelChecker::findDuplicateDefinitions(std::map<std::string, std::vector<T>> const& _definitions)
{
for (auto const& it: _definitions)
{
vector<T> const& overloads = it.second;
set<size_t> reported;
std::vector<T> const& overloads = it.second;
std::set<size_t> reported;
for (size_t i = 0; i < overloads.size() && !reported.count(i); ++i)
{
SecondarySourceLocation ssl;
@ -228,15 +227,15 @@ void ContractLevelChecker::findDuplicateDefinitions(map<string, vector<T>> const
if (ssl.infos.size() > 0)
{
ErrorId error;
string message;
if constexpr (is_same_v<T, FunctionDefinition const*>)
std::string message;
if constexpr (std::is_same_v<T, FunctionDefinition const*>)
{
error = 1686_error;
message = "Function with same name and parameter types defined twice.";
}
else
{
static_assert(is_same_v<T, EventDefinition const*>, "Expected \"FunctionDefinition const*\" or \"EventDefinition const*\"");
static_assert(std::is_same_v<T, EventDefinition const*>, "Expected \"FunctionDefinition const*\" or \"EventDefinition const*\"");
error = 5883_error;
message = "Event with same name and parameter types defined twice.";
}
@ -258,7 +257,7 @@ void ContractLevelChecker::checkAbstractDefinitions(ContractDefinition const& _c
{
// Collects functions, static variable getters and modifiers. If they
// override (unimplemented) base class ones, they are replaced.
set<OverrideProxy, OverrideProxy::CompareBySignature> proxies;
std::set<OverrideProxy, OverrideProxy::CompareBySignature> proxies;
auto registerProxy = [&proxies](OverrideProxy const& _overrideProxy)
{
@ -323,7 +322,7 @@ void ContractLevelChecker::checkAbstractDefinitions(ContractDefinition const& _c
void ContractLevelChecker::checkBaseConstructorArguments(ContractDefinition const& _contract)
{
vector<ContractDefinition const*> const& bases = _contract.annotation().linearizedBaseContracts;
std::vector<ContractDefinition const*> const& bases = _contract.annotation().linearizedBaseContracts;
// Determine the arguments that are used for the base constructors.
for (ContractDefinition const* contract: bases)
@ -430,7 +429,7 @@ void ContractLevelChecker::annotateBaseConstructorArguments(
void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _contract)
{
map<string, vector<pair<Declaration const*, FunctionTypePointer>>> externalDeclarations;
std::map<std::string, std::vector<std::pair<Declaration const*, FunctionTypePointer>>> externalDeclarations;
for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts)
{
for (FunctionDefinition const* f: contract->definedFunctions())
@ -467,7 +466,7 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contract)
{
set<util::FixedHash<4>> hashes;
std::set<util::FixedHash<4>> hashes;
for (auto const& it: _contract.interfaceFunctionList())
{
util::FixedHash<4> const& hash = it.first;
@ -475,7 +474,7 @@ void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contra
m_errorReporter.fatalTypeError(
1860_error,
_contract.location(),
string("Function signature hash collision for ") + it.second->externalSignature()
std::string("Function signature hash collision for ") + it.second->externalSignature()
);
hashes.insert(hash);
}

View File

@ -25,7 +25,6 @@
#include <functional>
using namespace std;
using namespace std::placeholders;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -44,7 +43,7 @@ void ControlFlowAnalyzer::analyze(FunctionDefinition const& _function, ContractD
if (!_function.isImplemented())
return;
optional<string> mostDerivedContractName;
std::optional<std::string> mostDerivedContractName;
// The name of the most derived contract only required if it differs from
// the functions contract
@ -61,13 +60,13 @@ void ControlFlowAnalyzer::analyze(FunctionDefinition const& _function, ContractD
}
void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, optional<string> _contractName)
void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, std::optional<std::string> _contractName)
{
struct NodeInfo
{
set<VariableDeclaration const*> unassignedVariablesAtEntry;
set<VariableDeclaration const*> unassignedVariablesAtExit;
set<VariableOccurrence const*> uninitializedVariableAccesses;
std::set<VariableDeclaration const*> unassignedVariablesAtEntry;
std::set<VariableDeclaration const*> unassignedVariablesAtExit;
std::set<VariableOccurrence const*> uninitializedVariableAccesses;
/// Propagate the information from another node to this node.
/// To be used to propagate information from a node to its exit nodes.
/// Returns true, if new variables were added and thus the current node has
@ -84,8 +83,8 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
;
}
};
map<CFGNode const*, NodeInfo> nodeInfos;
set<CFGNode const*> nodesToTraverse;
std::map<CFGNode const*, NodeInfo> nodeInfos;
std::set<CFGNode const*> nodesToTraverse;
nodesToTraverse.insert(_entry);
// Walk all paths starting from the nodes in ``nodesToTraverse`` until ``NodeInfo::propagateFrom``
@ -138,7 +137,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
auto const& exitInfo = nodeInfos[_exit];
if (!exitInfo.uninitializedVariableAccesses.empty())
{
vector<VariableOccurrence const*> uninitializedAccessesOrdered(
std::vector<VariableOccurrence const*> uninitializedAccessesOrdered(
exitInfo.uninitializedVariableAccesses.begin(),
exitInfo.uninitializedVariableAccesses.end()
);
@ -168,7 +167,7 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
varDecl.location(),
ssl,
"This variable is of " +
string(isStorage ? "storage" : "calldata") +
std::string(isStorage ? "storage" : "calldata") +
" pointer type and can be " +
(variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") +
" without prior assignment, which would lead to undefined behaviour."

View File

@ -21,10 +21,8 @@
#include <libyul/AST.h>
#include <libyul/backends/evm/EVMDialect.h>
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
using namespace std;
ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, FunctionFlow const& _functionFlow, ContractDefinition const* _contract):
m_nodeContainer(_nodeContainer),
@ -37,13 +35,13 @@ ControlFlowBuilder::ControlFlowBuilder(CFG::NodeContainer& _nodeContainer, Funct
}
unique_ptr<FunctionFlow> ControlFlowBuilder::createFunctionFlow(
std::unique_ptr<FunctionFlow> ControlFlowBuilder::createFunctionFlow(
CFG::NodeContainer& _nodeContainer,
FunctionDefinition const& _function,
ContractDefinition const* _contract
)
{
auto functionFlow = make_unique<FunctionFlow>();
auto functionFlow = std::make_unique<FunctionFlow>();
functionFlow->entry = _nodeContainer.newNode();
functionFlow->exit = _nodeContainer.newNode();
functionFlow->revert = _nodeContainer.newNode();

View File

@ -20,7 +20,6 @@
#include <libsolidity/analysis/ControlFlowBuilder.h>
using namespace std;
using namespace solidity::langutil;
using namespace solidity::frontend;

View File

@ -29,7 +29,6 @@
#include <range/v3/view/filter.hpp>
#include <range/v3/range/conversion.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::frontend;
@ -41,7 +40,7 @@ Declaration const* DeclarationContainer::conflictingDeclaration(
if (!_name)
_name = &_declaration.name();
solAssert(!_name->empty(), "");
vector<Declaration const*> declarations;
std::vector<Declaration const*> declarations;
if (m_declarations.count(*_name))
declarations += m_declarations.at(*_name);
if (m_invisibleDeclarations.count(*_name))
@ -127,7 +126,7 @@ bool DeclarationContainer::registerDeclaration(
m_homonymCandidates.emplace_back(*_name, _location ? _location : &_declaration.location());
}
vector<Declaration const*>& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name];
std::vector<Declaration const*>& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name];
if (!util::contains(decls, &_declaration))
decls.push_back(&_declaration);
return true;
@ -142,13 +141,13 @@ bool DeclarationContainer::registerDeclaration(
return registerDeclaration(_declaration, nullptr, nullptr, _invisible, _update);
}
vector<Declaration const*> DeclarationContainer::resolveName(
std::vector<Declaration const*> DeclarationContainer::resolveName(
ASTString const& _name,
ResolvingSettings _settings
) const
{
solAssert(!_name.empty(), "Attempt to resolve empty name.");
vector<Declaration const*> result;
std::vector<Declaration const*> result;
if (m_declarations.count(_name))
{
@ -172,24 +171,24 @@ vector<Declaration const*> DeclarationContainer::resolveName(
return result;
}
vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) const
std::vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) const
{
// because the function below has quadratic runtime - it will not magically improve once a better algorithm is discovered ;)
// since 80 is the suggested line length limit, we use 80^2 as length threshold
static size_t const MAXIMUM_LENGTH_THRESHOLD = 80 * 80;
vector<ASTString> similar;
std::vector<ASTString> similar;
size_t maximumEditDistance = _name.size() > 3 ? 2 : _name.size() / 2;
for (auto const& declaration: m_declarations)
{
string const& declarationName = declaration.first;
std::string const& declarationName = declaration.first;
if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
for (auto const& declaration: m_invisibleDeclarations)
{
string const& declarationName = declaration.first;
std::string const& declarationName = declaration.first;
if (util::stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
@ -200,7 +199,7 @@ vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) con
return similar;
}
void DeclarationContainer::populateHomonyms(back_insert_iterator<Homonyms> _it) const
void DeclarationContainer::populateHomonyms(std::back_insert_iterator<Homonyms> _it) const
{
for (DeclarationContainer const* innerContainer: m_innerContainers)
innerContainer->populateHomonyms(_it);
@ -210,7 +209,7 @@ void DeclarationContainer::populateHomonyms(back_insert_iterator<Homonyms> _it)
ResolvingSettings settings;
settings.recursive = true;
settings.alsoInvisible = true;
vector<Declaration const*> const& declarations = m_enclosingContainer->resolveName(name, std::move(settings));
std::vector<Declaration const*> const& declarations = m_enclosingContainer->resolveName(name, std::move(settings));
if (!declarations.empty())
_it = make_pair(location, declarations);
}

View File

@ -29,7 +29,6 @@
#include <range/v3/view/transform.hpp>
using namespace std;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -336,10 +335,10 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
if (Expression const* length = _typeName.length())
{
optional<rational> lengthValue;
std::optional<rational> lengthValue;
if (length->annotation().type && length->annotation().type->category() == Type::Category::RationalNumber)
lengthValue = dynamic_cast<RationalNumberType const&>(*length->annotation().type).value();
else if (optional<ConstantEvaluator::TypedRational> value = ConstantEvaluator::evaluate(m_errorReporter, *length))
else if (std::optional<ConstantEvaluator::TypedRational> value = ConstantEvaluator::evaluate(m_errorReporter, *length))
lengthValue = value->value;
if (!lengthValue)
@ -399,10 +398,10 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
Location varLoc = _variable.referenceLocation();
DataLocation typeLoc = DataLocation::Memory;
set<Location> allowedDataLocations = _variable.allowedDataLocations();
std::set<Location> allowedDataLocations = _variable.allowedDataLocations();
if (!allowedDataLocations.count(varLoc))
{
auto locationToString = [](VariableDeclaration::Location _location) -> string
auto locationToString = [](VariableDeclaration::Location _location) -> std::string
{
switch (_location)
{
@ -414,7 +413,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
return {};
};
string errorString;
std::string errorString;
if (!_variable.hasReferenceOrMappingType())
errorString = "Data location can only be specified for array, struct or mapping types";
else
@ -430,9 +429,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
else if (_variable.isCallableOrCatchParameter())
errorString +=
" for " +
string(_variable.isReturnParameter() ? "return " : "") +
std::string(_variable.isReturnParameter() ? "return " : "") +
"parameter in" +
string(_variable.isExternalCallableParameter() ? " external" : "") +
std::string(_variable.isExternalCallableParameter() ? " external" : "") +
" function";
else
errorString += " for variable";

View File

@ -30,7 +30,6 @@
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -38,7 +37,7 @@ using namespace solidity::frontend;
namespace
{
void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, StructurallyDocumentedAnnotation& _target, FunctionType const* _functionType = nullptr)
void copyMissingTags(std::set<CallableDeclaration const*> const& _baseFunctions, StructurallyDocumentedAnnotation& _target, FunctionType const* _functionType = nullptr)
{
// Only copy if there is exactly one direct base function.
if (_baseFunctions.size() != 1)
@ -50,7 +49,7 @@ void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, Stru
for (auto it = sourceDoc.docTags.begin(); it != sourceDoc.docTags.end();)
{
string const& tag = it->first;
std::string const& tag = it->first;
// Don't copy tag "inheritdoc", custom tags or already existing tags
if (tag == "inheritdoc" || _target.docTags.count(tag) || boost::starts_with(tag, "custom"))
{
@ -68,7 +67,7 @@ void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, Stru
if (_functionType && tag == "return")
{
size_t docParaNameEndPos = content.content.find_first_of(" \t");
string const docParameterName = content.content.substr(0, docParaNameEndPos);
std::string const docParameterName = content.content.substr(0, docParaNameEndPos);
if (
_functionType->returnParameterNames().size() > n &&
@ -80,10 +79,10 @@ void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, Stru
baseFunction.returnParameters().size() > n &&
baseFunction.returnParameters().at(n)->name().empty();
string paramName = _functionType->returnParameterNames().at(n);
std::string paramName = _functionType->returnParameterNames().at(n);
content.content =
(paramName.empty() ? "" : std::move(paramName) + " ") + (
string::npos == docParaNameEndPos || baseHasNoName ?
std::string::npos == docParaNameEndPos || baseHasNoName ?
content.content :
content.content.substr(docParaNameEndPos + 1)
);
@ -95,7 +94,7 @@ void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, Stru
}
}
CallableDeclaration const* findBaseCallable(set<CallableDeclaration const*> const& _baseFunctions, int64_t _contractId)
CallableDeclaration const* findBaseCallable(std::set<CallableDeclaration const*> const& _baseFunctions, int64_t _contractId)
{
for (CallableDeclaration const* baseFuncCandidate: _baseFunctions)
if (baseFuncCandidate->annotation().contract->id() == _contractId)
@ -181,7 +180,7 @@ void DocStringAnalyser::handleCallable(
}
CallableDeclaration const* DocStringAnalyser::resolveInheritDoc(
set<CallableDeclaration const*> const& _baseFuncs,
std::set<CallableDeclaration const*> const& _baseFuncs,
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation
)

View File

@ -37,7 +37,6 @@
#include <regex>
#include <string_view>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -67,7 +66,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU
if (tagName == "return")
{
returnTagsVisited++;
vector<string> returnParameterNames;
std::vector<std::string> returnParameterNames;
if (auto const* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))
{
@ -82,8 +81,8 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU
else
continue;
string content = tagValue.content;
string firstWord = content.substr(0, content.find_first_of(" \t"));
std::string content = tagValue.content;
std::string firstWord = content.substr(0, content.find_first_of(" \t"));
if (returnTagsVisited > returnParameterNames.size())
m_errorReporter.docstringParsingError(
@ -94,7 +93,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU
);
else
{
string const& parameter = returnParameterNames.at(returnTagsVisited - 1);
std::string const& parameter = returnParameterNames.at(returnTagsVisited - 1);
if (!parameter.empty() && parameter != firstWord)
m_errorReporter.docstringParsingError(
5856_error,
@ -113,7 +112,7 @@ bool DocStringTagParser::validateDocStringsUsingTypes(SourceUnit const& _sourceU
bool DocStringTagParser::visit(ContractDefinition const& _contract)
{
static set<string> const validTags = set<string>{"author", "title", "dev", "notice"};
static std::set<std::string> const validTags = std::set<std::string>{"author", "title", "dev", "notice"};
parseDocStrings(_contract, _contract.annotation(), validTags, "contracts");
return true;
@ -193,12 +192,12 @@ bool DocStringTagParser::visit(InlineAssembly const& _assembly)
{
if (tagName == "solidity")
{
vector<string> values;
std::vector<std::string> values;
boost::split(values, tagValue.content, isWhiteSpace);
set<string> valuesSeen;
set<string> duplicates;
for (auto const& value: values | ranges::views::filter(not_fn(&string::empty)))
std::set<std::string> valuesSeen;
std::set<std::string> duplicates;
for (auto const& value: values | ranges::views::filter(not_fn(&std::string::empty)))
if (valuesSeen.insert(value).second)
{
if (value == "memory-safe-assembly")
@ -244,7 +243,7 @@ void DocStringTagParser::checkParameters(
StructurallyDocumentedAnnotation& _annotation
)
{
set<string> validParams;
std::set<std::string> validParams;
for (auto const& p: _callable.parameters())
validParams.insert(p->name());
if (_callable.returnParameterList())
@ -268,7 +267,7 @@ void DocStringTagParser::handleConstructor(
StructurallyDocumentedAnnotation& _annotation
)
{
static set<string> const validTags = set<string>{"author", "dev", "notice", "param"};
static std::set<std::string> const validTags = std::set<std::string>{"author", "dev", "notice", "param"};
parseDocStrings(_node, _annotation, validTags, "constructor");
checkParameters(_callable, _node, _annotation);
}
@ -279,10 +278,10 @@ void DocStringTagParser::handleCallable(
StructurallyDocumentedAnnotation& _annotation
)
{
static set<string> const validEventTags = set<string>{"dev", "notice", "return", "param"};
static set<string> const validErrorTags = set<string>{"dev", "notice", "param"};
static set<string> const validModifierTags = set<string>{"dev", "notice", "param", "inheritdoc"};
static set<string> const validTags = set<string>{"dev", "notice", "return", "param", "inheritdoc"};
static std::set<std::string> const validEventTags = std::set<std::string>{"dev", "notice", "return", "param"};
static std::set<std::string> const validErrorTags = std::set<std::string>{"dev", "notice", "param"};
static std::set<std::string> const validModifierTags = std::set<std::string>{"dev", "notice", "param", "inheritdoc"};
static std::set<std::string> const validTags = std::set<std::string>{"dev", "notice", "return", "param", "inheritdoc"};
if (dynamic_cast<EventDefinition const*>(&_callable))
parseDocStrings(_node, _annotation, validEventTags, "events");
@ -299,8 +298,8 @@ void DocStringTagParser::handleCallable(
void DocStringTagParser::parseDocStrings(
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation,
set<string> const& _validTags,
string const& _nodeName
std::set<std::string> const& _validTags,
std::string const& _nodeName
)
{
if (!_node.documentation())
@ -310,7 +309,7 @@ void DocStringTagParser::parseDocStrings(
for (auto const& [tagName, tagValue]: _annotation.docTags)
{
string_view static constexpr customPrefix("custom:");
std::string_view static constexpr customPrefix("custom:");
if (tagName == "custom" || tagName == "custom:")
m_errorReporter.docstringParsingError(
6564_error,
@ -319,7 +318,7 @@ void DocStringTagParser::parseDocStrings(
);
else if (boost::starts_with(tagName, customPrefix) && tagName.size() > customPrefix.size())
{
regex static const customRegex("^custom:[a-z][a-z-]*$");
std::regex static const customRegex("^custom:[a-z][a-z-]*$");
if (!regex_match(tagName, customRegex))
m_errorReporter.docstringParsingError(
2968_error,

View File

@ -24,7 +24,6 @@
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/transform.hpp>
using namespace std;
using namespace solidity::frontend;
using namespace solidity::util;
@ -72,7 +71,7 @@ CallGraph FunctionCallGraphBuilder::buildDeployedGraph(
FunctionCallGraphBuilder builder(_contract);
solAssert(builder.m_currentNode == CallGraph::Node(CallGraph::SpecialNode::Entry), "");
auto getSecondElement = [](auto const& _tuple){ return get<1>(_tuple); };
auto getSecondElement = [](auto const& _tuple){ return std::get<1>(_tuple); };
// Create graph for all publicly reachable functions
for (FunctionTypePointer functionType: _contract.interfaceFunctionList() | ranges::views::transform(getSecondElement))
@ -96,14 +95,14 @@ CallGraph FunctionCallGraphBuilder::buildDeployedGraph(
// All functions present in internal dispatch at creation time could potentially be pointers
// assigned to state variables and as such may be reachable after deployment as well.
builder.m_currentNode = CallGraph::SpecialNode::InternalDispatch;
set<CallGraph::Node, CallGraph::CompareByID> defaultNode;
std::set<CallGraph::Node, CallGraph::CompareByID> defaultNode;
for (CallGraph::Node const& dispatchTarget: util::valueOrDefault(_creationGraph.edges, CallGraph::SpecialNode::InternalDispatch, defaultNode))
{
solAssert(!holds_alternative<CallGraph::SpecialNode>(dispatchTarget), "");
solAssert(get<CallableDeclaration const*>(dispatchTarget) != nullptr, "");
solAssert(!std::holds_alternative<CallGraph::SpecialNode>(dispatchTarget), "");
solAssert(std::get<CallableDeclaration const*>(dispatchTarget) != nullptr, "");
// Visit the callable to add not only it but also everything it calls too
builder.functionReferenced(*get<CallableDeclaration const*>(dispatchTarget), false);
builder.functionReferenced(*std::get<CallableDeclaration const*>(dispatchTarget), false);
}
builder.m_currentNode = CallGraph::SpecialNode::Entry;
@ -262,10 +261,10 @@ void FunctionCallGraphBuilder::processQueue()
while (!m_visitQueue.empty())
{
m_currentNode = m_visitQueue.front();
solAssert(holds_alternative<CallableDeclaration const*>(m_currentNode), "");
solAssert(std::holds_alternative<CallableDeclaration const*>(m_currentNode), "");
m_visitQueue.pop_front();
get<CallableDeclaration const*>(m_currentNode)->accept(*this);
std::get<CallableDeclaration const*>(m_currentNode)->accept(*this);
}
m_currentNode = CallGraph::SpecialNode::Entry;
@ -281,7 +280,7 @@ void FunctionCallGraphBuilder::functionReferenced(CallableDeclaration const& _ca
if (_calledDirectly)
{
solAssert(
holds_alternative<CallGraph::SpecialNode>(m_currentNode) || m_graph.edges.count(m_currentNode) > 0,
std::holds_alternative<CallGraph::SpecialNode>(m_currentNode) || m_graph.edges.count(m_currentNode) > 0,
"Adding an edge from a node that has not been visited yet."
);
@ -293,10 +292,10 @@ void FunctionCallGraphBuilder::functionReferenced(CallableDeclaration const& _ca
enqueueCallable(_callable);
}
ostream& solidity::frontend::operator<<(ostream& _out, CallGraph::Node const& _node)
std::ostream& solidity::frontend::operator<<(std::ostream& _out, CallGraph::Node const& _node)
{
if (holds_alternative<CallGraph::SpecialNode>(_node))
switch (get<CallGraph::SpecialNode>(_node))
if (std::holds_alternative<CallGraph::SpecialNode>(_node))
switch (std::get<CallGraph::SpecialNode>(_node))
{
case CallGraph::SpecialNode::InternalDispatch:
_out << "InternalDispatch";
@ -309,19 +308,19 @@ ostream& solidity::frontend::operator<<(ostream& _out, CallGraph::Node const& _n
}
else
{
solAssert(holds_alternative<CallableDeclaration const*>(_node), "");
solAssert(std::holds_alternative<CallableDeclaration const*>(_node), "");
auto const* callableDeclaration = get<CallableDeclaration const*>(_node);
auto const* callableDeclaration = std::get<CallableDeclaration const*>(_node);
solAssert(callableDeclaration, "");
auto const* function = dynamic_cast<FunctionDefinition const *>(callableDeclaration);
auto const* event = dynamic_cast<EventDefinition const *>(callableDeclaration);
auto const* modifier = dynamic_cast<ModifierDefinition const *>(callableDeclaration);
auto typeToString = [](auto const& _var) -> string { return _var->type()->toString(true); };
vector<string> parameters = callableDeclaration->parameters() | ranges::views::transform(typeToString) | ranges::to<vector<string>>();
auto typeToString = [](auto const& _var) -> std::string { return _var->type()->toString(true); };
std::vector<std::string> parameters = callableDeclaration->parameters() | ranges::views::transform(typeToString) | ranges::to<std::vector<std::string>>();
string scopeName;
std::string scopeName;
if (!function || !function->isFree())
{
solAssert(callableDeclaration->annotation().scope, "");

View File

@ -29,8 +29,6 @@
#include <libsolidity/ast/Types.h>
#include <memory>
using namespace std;
namespace solidity::frontend
{
@ -65,10 +63,10 @@ int magicVariableToID(std::string const& _name)
solAssert(false, "Unknown magic variable: \"" + _name + "\".");
}
inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariables()
inline std::vector<std::shared_ptr<MagicVariableDeclaration const>> constructMagicVariables()
{
static auto const magicVarDecl = [](string const& _name, Type const* _type) {
return make_shared<MagicVariableDeclaration>(magicVariableToID(_name), _name, _type);
static auto const magicVarDecl = [](std::string const& _name, Type const* _type) {
return std::make_shared<MagicVariableDeclaration>(magicVariableToID(_name), _name, _type);
};
return {
@ -116,9 +114,9 @@ void GlobalContext::setCurrentContract(ContractDefinition const& _contract)
m_currentContract = &_contract;
}
vector<Declaration const*> GlobalContext::declarations() const
std::vector<Declaration const*> GlobalContext::declarations() const
{
vector<Declaration const*> declarations;
std::vector<Declaration const*> declarations;
declarations.reserve(m_magicVariables.size());
for (ASTPointer<MagicVariableDeclaration const> const& variable: m_magicVariables)
declarations.push_back(variable.get());
@ -133,7 +131,7 @@ MagicVariableDeclaration const* GlobalContext::currentThis() const
if (m_currentContract)
type = TypeProvider::contract(*m_currentContract);
m_thisPointer[m_currentContract] =
make_shared<MagicVariableDeclaration>(magicVariableToID("this"), "this", type);
std::make_shared<MagicVariableDeclaration>(magicVariableToID("this"), "this", type);
}
return m_thisPointer[m_currentContract].get();
}
@ -146,7 +144,7 @@ MagicVariableDeclaration const* GlobalContext::currentSuper() const
if (m_currentContract)
type = TypeProvider::typeType(TypeProvider::contract(*m_currentContract, true));
m_superPointer[m_currentContract] =
make_shared<MagicVariableDeclaration>(magicVariableToID("super"), "super", type);
std::make_shared<MagicVariableDeclaration>(magicVariableToID("super"), "super", type);
}
return m_superPointer[m_currentContract].get();
}

View File

@ -30,7 +30,6 @@
#include <boost/algorithm/string.hpp>
#include <unordered_set>
using namespace std;
using namespace solidity::langutil;
namespace solidity::frontend
@ -45,7 +44,7 @@ NameAndTypeResolver::NameAndTypeResolver(
m_errorReporter(_errorReporter),
m_globalContext(_globalContext)
{
m_scopes[nullptr] = make_shared<DeclarationContainer>();
m_scopes[nullptr] = std::make_shared<DeclarationContainer>();
for (Declaration const* declaration: _globalContext.declarations())
{
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration, false, false), "Unable to register global declaration.");
@ -68,14 +67,14 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode
return true;
}
bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map<string, SourceUnit const*> const& _sourceUnits)
bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, std::map<std::string, SourceUnit const*> const& _sourceUnits)
{
DeclarationContainer& target = *m_scopes.at(&_sourceUnit);
bool error = false;
for (auto const& node: _sourceUnit.nodes())
if (auto imp = dynamic_cast<ImportDirective const*>(node.get()))
{
string const& path = *imp->annotation().absolutePath;
std::string const& path = *imp->annotation().absolutePath;
// The import resolution in CompilerStack enforces this.
solAssert(_sourceUnits.count(path), "");
auto scope = m_scopes.find(_sourceUnits.at(path));
@ -127,7 +126,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source)
{
try
{
for (shared_ptr<ASTNode> const& node: _source.nodes())
for (std::shared_ptr<ASTNode> const& node: _source.nodes())
{
setScope(&_source);
if (!resolveNamesAndTypesInternal(*node, true))
@ -159,7 +158,7 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
return true;
}
void NameAndTypeResolver::activateVariable(string const& _name)
void NameAndTypeResolver::activateVariable(std::string const& _name)
{
solAssert(m_currentScope, "");
// Scoped local variables are invisible before activation.
@ -171,15 +170,15 @@ void NameAndTypeResolver::activateVariable(string const& _name)
m_currentScope->activateVariable(_name);
}
vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const
std::vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const
{
auto iterator = m_scopes.find(_scope);
if (iterator == end(m_scopes))
return vector<Declaration const*>({});
return std::vector<Declaration const*>({});
return iterator->second->resolveName(_name);
}
vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _includeInvisibles) const
std::vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _includeInvisibles) const
{
ResolvingSettings settings;
settings.recursive = true;
@ -187,7 +186,7 @@ vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString c
return m_currentScope->resolveName(_name, std::move(settings));
}
Declaration const* NameAndTypeResolver::pathFromCurrentScope(vector<ASTString> const& _path) const
Declaration const* NameAndTypeResolver::pathFromCurrentScope(std::vector<ASTString> const& _path) const
{
if (auto declarations = pathFromCurrentScopeWithAllDeclarations(_path); !declarations.empty())
return declarations.back();
@ -201,13 +200,13 @@ std::vector<Declaration const*> NameAndTypeResolver::pathFromCurrentScopeWithAll
) const
{
solAssert(!_path.empty(), "");
vector<Declaration const*> pathDeclarations;
std::vector<Declaration const*> pathDeclarations;
ResolvingSettings settings;
settings.recursive = true;
settings.alsoInvisible = _includeInvisibles;
settings.onlyVisibleAsUnqualifiedNames = true;
vector<Declaration const*> candidates = m_currentScope->resolveName(_path.front(), settings);
std::vector<Declaration const*> candidates = m_currentScope->resolveName(_path.front(), settings);
// inside the loop, use default settings, except for alsoInvisible
settings.recursive = false;
@ -305,7 +304,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
if (success)
{
linearizeBaseContracts(*contract);
vector<ContractDefinition const*> properBases(
std::vector<ContractDefinition const*> properBases(
++contract->annotation().linearizedBaseContracts.begin(),
contract->annotation().linearizedBaseContracts.end()
);
@ -405,7 +404,7 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract)
{
// order in the lists is from derived to base
// list of lists to linearize, the last element is the list of direct bases
list<list<ContractDefinition const*>> input(1, list<ContractDefinition const*>{});
std::list<std::list<ContractDefinition const*>> input(1, std::list<ContractDefinition const*>{});
for (ASTPointer<InheritanceSpecifier> const& baseSpecifier: _contract.baseContracts())
{
IdentifierPath const& baseName = baseSpecifier->name();
@ -415,25 +414,25 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract)
// "push_front" has the effect that bases mentioned later can overwrite members of bases
// mentioned earlier
input.back().push_front(base);
vector<ContractDefinition const*> const& basesBases = base->annotation().linearizedBaseContracts;
std::vector<ContractDefinition const*> const& basesBases = base->annotation().linearizedBaseContracts;
if (basesBases.empty())
m_errorReporter.fatalTypeError(2449_error, baseName.location(), "Definition of base has to precede definition of derived contract");
input.push_front(list<ContractDefinition const*>(basesBases.begin(), basesBases.end()));
input.push_front(std::list<ContractDefinition const*>(basesBases.begin(), basesBases.end()));
}
input.back().push_front(&_contract);
vector<ContractDefinition const*> result = cThreeMerge(input);
std::vector<ContractDefinition const*> result = cThreeMerge(input);
if (result.empty())
m_errorReporter.fatalTypeError(5005_error, _contract.location(), "Linearization of inheritance graph impossible");
_contract.annotation().linearizedBaseContracts = result;
}
template <class T>
vector<T const*> NameAndTypeResolver::cThreeMerge(list<list<T const*>>& _toMerge)
std::vector<T const*> NameAndTypeResolver::cThreeMerge(std::list<std::list<T const*>>& _toMerge)
{
// returns true iff _candidate appears only as last element of the lists
auto appearsOnlyAtHead = [&](T const* _candidate) -> bool
{
for (list<T const*> const& bases: _toMerge)
for (std::list<T const*> const& bases: _toMerge)
{
solAssert(!bases.empty(), "");
if (find(++bases.begin(), bases.end(), _candidate) != bases.end())
@ -444,7 +443,7 @@ vector<T const*> NameAndTypeResolver::cThreeMerge(list<list<T const*>>& _toMerge
// returns the next candidate to append to the linearized list or nullptr on failure
auto nextCandidate = [&]() -> T const*
{
for (list<T const*> const& bases: _toMerge)
for (std::list<T const*> const& bases: _toMerge)
{
solAssert(!bases.empty(), "");
if (appearsOnlyAtHead(bases.front()))
@ -465,26 +464,26 @@ vector<T const*> NameAndTypeResolver::cThreeMerge(list<list<T const*>>& _toMerge
}
};
_toMerge.remove_if([](list<T const*> const& _bases) { return _bases.empty(); });
vector<T const*> result;
_toMerge.remove_if([](std::list<T const*> const& _bases) { return _bases.empty(); });
std::vector<T const*> result;
while (!_toMerge.empty())
{
T const* candidate = nextCandidate();
if (!candidate)
return vector<T const*>();
return std::vector<T const*>();
result.push_back(candidate);
removeCandidate(candidate);
}
return result;
}
string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const
std::string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const
{
return util::quotedAlternativesList(m_currentScope->similarNames(_name));
}
DeclarationRegistrationHelper::DeclarationRegistrationHelper(
map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes,
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes,
ASTNode& _astRoot,
ErrorReporter& _errorReporter,
GlobalContext& _globalContext,
@ -502,7 +501,7 @@ DeclarationRegistrationHelper::DeclarationRegistrationHelper(
bool DeclarationRegistrationHelper::registerDeclaration(
DeclarationContainer& _container,
Declaration const& _declaration,
string const* _name,
std::string const* _name,
SourceLocation const* _errorLocation,
bool _inactive,
ErrorReporter& _errorReporter
@ -511,13 +510,13 @@ bool DeclarationRegistrationHelper::registerDeclaration(
if (!_errorLocation)
_errorLocation = &_declaration.location();
string name = _name ? *_name : _declaration.name();
std::string name = _name ? *_name : _declaration.name();
// We use "invisible" for both inactive variables in blocks and for members invisible in contracts.
// They cannot both be true at the same time.
solAssert(!(_inactive && !_declaration.isVisibleInContract()), "");
static set<string> illegalNames{"_", "super", "this"};
static std::set<std::string> illegalNames{"_", "super", "this"};
if (illegalNames.count(name))
{
@ -580,7 +579,7 @@ bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit)
{
if (!m_scopes[&_sourceUnit])
// By importing, it is possible that the container already exists.
m_scopes[&_sourceUnit] = make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get());
m_scopes[&_sourceUnit] = std::make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get());
return ASTVisitor::visit(_sourceUnit);
}
@ -594,7 +593,7 @@ bool DeclarationRegistrationHelper::visit(ImportDirective& _import)
SourceUnit const* importee = _import.annotation().sourceUnit;
solAssert(!!importee, "");
if (!m_scopes[importee])
m_scopes[importee] = make_shared<DeclarationContainer>(nullptr, m_scopes[nullptr].get());
m_scopes[importee] = std::make_shared<DeclarationContainer>(nullptr, m_scopes[nullptr].get());
m_scopes[&_import] = m_scopes[importee];
ASTVisitor::visit(_import);
return false; // Do not recurse into child nodes (Identifier for symbolAliases)
@ -641,7 +640,7 @@ bool DeclarationRegistrationHelper::visitNode(ASTNode& _node)
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
{
string canonicalName = dynamic_cast<Declaration const&>(_node).name();
std::string canonicalName = dynamic_cast<Declaration const&>(_node).name();
solAssert(!canonicalName.empty(), "");
for (
@ -684,7 +683,7 @@ void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope)
{
bool newlyAdded = m_scopes.emplace(
&_subScope,
make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get())
std::make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get())
).second;
solAssert(newlyAdded, "Unable to add new scope.");
}

View File

@ -31,7 +31,6 @@
#include <boost/algorithm/string/predicate.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::langutil;
@ -46,7 +45,7 @@ namespace
// Helper struct to do a search by name
struct MatchByName
{
string const& m_name;
std::string const& m_name;
bool operator()(OverrideProxy const& _item)
{
return _item.name() == m_name;
@ -61,7 +60,7 @@ struct MatchByName
*/
struct OverrideGraph
{
OverrideGraph(set<OverrideProxy> const& _baseCallables)
OverrideGraph(std::set<OverrideProxy> const& _baseCallables)
{
for (auto const& baseFunction: _baseCallables)
addEdge(0, visit(baseFunction));
@ -131,17 +130,17 @@ private:
run(vInd, _depth + 1);
if (m_low[vInd] >= m_depths[_u] && m_parent[_u] != -1)
m_cutVertices.insert(m_graph.nodeInv.at(static_cast<int>(_u)));
m_low[_u] = min(m_low[_u], m_low[vInd]);
m_low[_u] = std::min(m_low[_u], m_low[vInd]);
}
else if (v != m_parent[_u])
m_low[_u] = min(m_low[_u], m_depths[vInd]);
m_low[_u] = std::min(m_low[_u], m_depths[vInd]);
}
}
};
vector<ContractDefinition const*> resolveDirectBaseContracts(ContractDefinition const& _contract)
std::vector<ContractDefinition const*> resolveDirectBaseContracts(ContractDefinition const& _contract)
{
vector<ContractDefinition const*> resolvedContracts;
std::vector<ContractDefinition const*> resolvedContracts;
for (ASTPointer<InheritanceSpecifier> const& specifier: _contract.baseContracts())
{
@ -155,7 +154,7 @@ vector<ContractDefinition const*> resolveDirectBaseContracts(ContractDefinition
return resolvedContracts;
}
vector<ASTPointer<IdentifierPath>> sortByContract(vector<ASTPointer<IdentifierPath>> const& _list)
std::vector<ASTPointer<IdentifierPath>> sortByContract(std::vector<ASTPointer<IdentifierPath>> const& _list)
{
auto sorted = _list;
@ -197,17 +196,17 @@ bool OverrideProxy::operator<(OverrideProxy const& _other) const
bool OverrideProxy::isVariable() const
{
return holds_alternative<VariableDeclaration const*>(m_item);
return std::holds_alternative<VariableDeclaration const*>(m_item);
}
bool OverrideProxy::isFunction() const
{
return holds_alternative<FunctionDefinition const*>(m_item);
return std::holds_alternative<FunctionDefinition const*>(m_item);
}
bool OverrideProxy::isModifier() const
{
return holds_alternative<ModifierDefinition const*>(m_item);
return std::holds_alternative<ModifierDefinition const*>(m_item);
}
bool OverrideProxy::CompareBySignature::operator()(OverrideProxy const& _a, OverrideProxy const& _b) const
@ -222,18 +221,18 @@ size_t OverrideProxy::id() const
}, m_item);
}
shared_ptr<OverrideSpecifier> OverrideProxy::overrides() const
std::shared_ptr<OverrideSpecifier> OverrideProxy::overrides() const
{
return std::visit(GenericVisitor{
[&](auto const* _item) { return _item->overrides(); }
}, m_item);
}
set<OverrideProxy> OverrideProxy::baseFunctions() const
std::set<OverrideProxy> OverrideProxy::baseFunctions() const
{
return std::visit(GenericVisitor{
[&](auto const* _item) -> set<OverrideProxy> {
set<OverrideProxy> ret;
[&](auto const* _item) -> std::set<OverrideProxy> {
std::set<OverrideProxy> ret;
for (auto const* f: _item->annotation().baseFunctions)
ret.insert(makeOverrideProxy(*f));
return ret;
@ -256,10 +255,10 @@ void OverrideProxy::storeBaseFunction(OverrideProxy const& _base) const
}, m_item);
}
string const& OverrideProxy::name() const
std::string const& OverrideProxy::name() const
{
return std::visit(GenericVisitor{
[&](auto const* _item) -> string const& { return _item->name(); }
[&](auto const* _item) -> std::string const& { return _item->name(); }
}, m_item);
}
@ -272,7 +271,7 @@ ContractDefinition const& OverrideProxy::contract() const
}, m_item);
}
string const& OverrideProxy::contractName() const
std::string const& OverrideProxy::contractName() const
{
return contract().name();
}
@ -357,7 +356,7 @@ SourceLocation const& OverrideProxy::location() const
}, m_item);
}
string OverrideProxy::astNodeName() const
std::string OverrideProxy::astNodeName() const
{
return std::visit(GenericVisitor{
[&](FunctionDefinition const*) { return "function"; },
@ -366,7 +365,7 @@ string OverrideProxy::astNodeName() const
}, m_item);
}
string OverrideProxy::astNodeNameCapitalized() const
std::string OverrideProxy::astNodeNameCapitalized() const
{
return std::visit(GenericVisitor{
[&](FunctionDefinition const*) { return "Function"; },
@ -375,7 +374,7 @@ string OverrideProxy::astNodeNameCapitalized() const
}, m_item);
}
string OverrideProxy::distinguishingProperty() const
std::string OverrideProxy::distinguishingProperty() const
{
return std::visit(GenericVisitor{
[&](FunctionDefinition const*) { return "name and parameter types"; },
@ -418,10 +417,10 @@ OverrideProxy::OverrideComparator const& OverrideProxy::overrideComparator() con
{
if (!m_comparator)
{
m_comparator = make_shared<OverrideComparator>(std::visit(GenericVisitor{
m_comparator = std::make_shared<OverrideComparator>(std::visit(GenericVisitor{
[&](FunctionDefinition const* _function)
{
vector<string> paramTypes;
std::vector<std::string> paramTypes;
for (Type const* t: externalFunctionType()->parameterTypes())
paramTypes.emplace_back(t->richIdentifier());
return OverrideComparator{
@ -432,7 +431,7 @@ OverrideProxy::OverrideComparator const& OverrideProxy::overrideComparator() con
},
[&](VariableDeclaration const* _var)
{
vector<string> paramTypes;
std::vector<std::string> paramTypes;
for (Type const* t: externalFunctionType()->parameterTypes())
paramTypes.emplace_back(t->richIdentifier());
return OverrideComparator{
@ -674,21 +673,21 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
void OverrideChecker::overrideListError(
OverrideProxy const& _item,
set<ContractDefinition const*, CompareByID> _secondary,
std::set<ContractDefinition const*, CompareByID> _secondary,
ErrorId _error,
string const& _message1,
string const& _message2
std::string const& _message1,
std::string const& _message2
)
{
// Using a set rather than a vector so the order is always the same
set<string> names;
std::set<std::string> names;
SecondarySourceLocation ssl;
for (Declaration const* c: _secondary)
{
ssl.append("This contract: ", c->location());
names.insert("\"" + c->name() + "\"");
}
string contractSingularPlural = "contract ";
std::string contractSingularPlural = "contract ";
if (_secondary.size() > 1)
contractSingularPlural = "contracts ";
@ -708,8 +707,8 @@ void OverrideChecker::overrideError(
OverrideProxy const& _overriding,
OverrideProxy const& _super,
ErrorId _error,
string const& _message,
optional<string> const& _secondaryMsg
std::string const& _message,
std::optional<std::string> const& _secondaryMsg
)
{
m_errorReporter.typeError(
@ -766,7 +765,7 @@ void OverrideChecker::checkAmbiguousOverrides(ContractDefinition const& _contrac
}
}
void OverrideChecker::checkAmbiguousOverridesInternal(set<OverrideProxy> _baseCallables, SourceLocation const& _location) const
void OverrideChecker::checkAmbiguousOverridesInternal(std::set<OverrideProxy> _baseCallables, SourceLocation const& _location) const
{
if (_baseCallables.size() <= 1)
return;
@ -799,17 +798,17 @@ void OverrideChecker::checkAmbiguousOverridesInternal(set<OverrideProxy> _baseCa
for (OverrideProxy const& baseFunction: _baseCallables)
ssl.append("Definition in \"" + baseFunction.contractName() + "\": ", baseFunction.location());
string callableName = _baseCallables.begin()->astNodeName();
std::string callableName = _baseCallables.begin()->astNodeName();
if (_baseCallables.begin()->isVariable())
callableName = "function";
string distinguishigProperty = _baseCallables.begin()->distinguishingProperty();
std::string distinguishigProperty = _baseCallables.begin()->distinguishingProperty();
bool foundVariable = false;
for (auto const& base: _baseCallables)
if (base.isVariable())
foundVariable = true;
string message =
std::string message =
"Derived contract must override " + callableName + " \"" +
_baseCallables.begin()->name() +
"\". Two or more base classes define " + callableName + " with same " + distinguishigProperty + ".";
@ -822,9 +821,9 @@ void OverrideChecker::checkAmbiguousOverridesInternal(set<OverrideProxy> _baseCa
m_errorReporter.typeError(6480_error, _location, ssl, message);
}
set<ContractDefinition const*, OverrideChecker::CompareByID> OverrideChecker::resolveOverrideList(OverrideSpecifier const& _overrides) const
std::set<ContractDefinition const*, OverrideChecker::CompareByID> OverrideChecker::resolveOverrideList(OverrideSpecifier const& _overrides) const
{
set<ContractDefinition const*, CompareByID> resolved;
std::set<ContractDefinition const*, CompareByID> resolved;
for (ASTPointer<IdentifierPath> const& override: _overrides.overrides())
{
@ -842,7 +841,7 @@ set<ContractDefinition const*, OverrideChecker::CompareByID> OverrideChecker::re
void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySignatureMultiSet const& _inherited)
{
set<ContractDefinition const*, CompareByID> specifiedContracts =
std::set<ContractDefinition const*, CompareByID> specifiedContracts =
_item.overrides() ?
resolveOverrideList(*_item.overrides()) :
decltype(specifiedContracts){};
@ -851,7 +850,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
if (_item.overrides() && specifiedContracts.size() != _item.overrides()->overrides().size())
{
// Sort by contract id to find duplicate for error reporting
vector<ASTPointer<IdentifierPath>> list =
std::vector<ASTPointer<IdentifierPath>> list =
sortByContract(_item.overrides()->overrides());
// Find duplicates and output error
@ -880,7 +879,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
}
}
set<ContractDefinition const*, CompareByID> expectedContracts;
std::set<ContractDefinition const*, CompareByID> expectedContracts;
// Build list of expected contracts
for (auto [begin, end] = _inherited.equal_range(_item); begin != end; begin++)
@ -898,7 +897,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
_item.astNodeNameCapitalized() + " has override specified but does not override anything."
);
set<ContractDefinition const*, CompareByID> missingContracts;
std::set<ContractDefinition const*, CompareByID> missingContracts;
// If we expect only one contract, no contract needs to be specified
if (expectedContracts.size() > 1)
missingContracts = expectedContracts - specifiedContracts;
@ -931,7 +930,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri
for (auto const* base: resolveDirectBaseContracts(_contract))
{
set<OverrideProxy, OverrideProxy::CompareBySignature> functionsInBase;
std::set<OverrideProxy, OverrideProxy::CompareBySignature> functionsInBase;
for (FunctionDefinition const* fun: base->definedFunctions())
if (!fun->isConstructor())
functionsInBase.emplace(OverrideProxy{fun});
@ -960,7 +959,7 @@ OverrideChecker::OverrideProxyBySignatureMultiSet const& OverrideChecker::inheri
for (auto const* base: resolveDirectBaseContracts(_contract))
{
set<OverrideProxy, OverrideProxy::CompareBySignature> modifiersInBase;
std::set<OverrideProxy, OverrideProxy::CompareBySignature> modifiersInBase;
for (ModifierDefinition const* mod: base->functionModifiers())
modifiersInBase.emplace(OverrideProxy{mod});

View File

@ -27,7 +27,6 @@
#include <memory>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -204,7 +203,7 @@ struct ConstStateVarCircularReferenceChecker: public PostTypeChecker::Checker
// Iterating through the dependencies needs to be deterministic and thus cannot
// depend on the memory layout.
// Because of that, we sort by AST node id.
vector<VariableDeclaration const*> dependencies(
std::vector<VariableDeclaration const*> dependencies(
m_constVariableDependencies[&_variable].begin(),
m_constVariableDependencies[&_variable].end()
);
@ -427,10 +426,10 @@ struct ReservedErrorSelector: public PostTypeChecker::Checker
PostTypeChecker::PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter)
{
m_checkers.push_back(make_shared<ConstStateVarCircularReferenceChecker>(_errorReporter));
m_checkers.push_back(make_shared<OverrideSpecifierChecker>(_errorReporter));
m_checkers.push_back(make_shared<ModifierContextChecker>(_errorReporter));
m_checkers.push_back(make_shared<EventOutsideEmitErrorOutsideRevertChecker>(_errorReporter));
m_checkers.push_back(make_shared<NoVariablesInInterfaceChecker>(_errorReporter));
m_checkers.push_back(make_shared<ReservedErrorSelector>(_errorReporter));
m_checkers.push_back(std::make_shared<ConstStateVarCircularReferenceChecker>(_errorReporter));
m_checkers.push_back(std::make_shared<OverrideSpecifierChecker>(_errorReporter));
m_checkers.push_back(std::make_shared<ModifierContextChecker>(_errorReporter));
m_checkers.push_back(std::make_shared<EventOutsideEmitErrorOutsideRevertChecker>(_errorReporter));
m_checkers.push_back(std::make_shared<NoVariablesInInterfaceChecker>(_errorReporter));
m_checkers.push_back(std::make_shared<ReservedErrorSelector>(_errorReporter));
}

View File

@ -26,7 +26,6 @@
#include <libsolutil/FunctionSelector.h>
#include <liblangutil/ErrorReporter.h>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -48,10 +47,10 @@ bool PostTypeContractLevelChecker::check(ContractDefinition const& _contract)
""
);
map<uint32_t, map<string, SourceLocation>> errorHashes;
std::map<uint32_t, std::map<std::string, SourceLocation>> errorHashes;
for (ErrorDefinition const* error: _contract.interfaceErrors())
{
string signature = error->functionType(true)->externalSignature();
std::string signature = error->functionType(true)->externalSignature();
uint32_t hash = util::selectorFromSignatureU32(signature);
// Fail if there is a different signature for the same hash.
if (!errorHashes[hash].empty() && !errorHashes[hash].count(signature))

View File

@ -39,7 +39,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -121,8 +120,8 @@ bool ReferencesResolver::visit(Identifier const& _identifier)
auto declarations = m_resolver.nameFromCurrentScope(_identifier.name());
if (declarations.empty())
{
string suggestions = m_resolver.similarNameSuggestions(_identifier.name());
string errorMessage = "Undeclared identifier.";
std::string suggestions = m_resolver.similarNameSuggestions(_identifier.name());
std::string errorMessage = "Undeclared identifier.";
if (!suggestions.empty())
{
if ("\"" + _identifier.name() + "\"" == suggestions)
@ -192,10 +191,10 @@ bool ReferencesResolver::visit(UsingForDirective const& _usingFor)
// _includeInvisibles is enabled here because external library functions are marked invisible.
// As unintended side-effects other invisible names (eg.: super, this) may be returned as well.
// DeclarationTypeChecker should detect and report such situations.
vector<Declaration const*> declarations = m_resolver.pathFromCurrentScopeWithAllDeclarations(path->path(), true /* _includeInvisibles */);
std::vector<Declaration const*> declarations = m_resolver.pathFromCurrentScopeWithAllDeclarations(path->path(), true /* _includeInvisibles */);
if (declarations.empty())
{
string libraryOrFunctionNameErrorMessage =
std::string libraryOrFunctionNameErrorMessage =
_usingFor.usesBraces() ?
"Identifier is not a function name or not unique." :
"Identifier is not a library name.";
@ -253,9 +252,9 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
{
solAssert(nativeLocationOf(_identifier) == originLocationOf(_identifier), "");
static set<string> suffixes{"slot", "offset", "length", "address", "selector"};
string suffix;
for (string const& s: suffixes)
static std::set<std::string> suffixes{"slot", "offset", "length", "address", "selector"};
std::string suffix;
for (std::string const& s: suffixes)
if (boost::algorithm::ends_with(_identifier.name.str(), "." + s))
suffix = s;
@ -269,7 +268,7 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
if (!declarations.empty())
// the special identifier exists itself, we should not allow that.
return;
string realName = _identifier.name.str().substr(0, _identifier.name.str().size() - suffix.size() - 1);
std::string realName = _identifier.name.str().substr(0, _identifier.name.str().size() - suffix.size() - 1);
solAssert(!realName.empty(), "Empty name.");
declarations = m_resolver.nameFromCurrentScope(realName);
if (!declarations.empty())
@ -350,7 +349,7 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum
break;
case 1:
{
string const& name = _annotation.docTags.find("inheritdoc")->second.content;
std::string const& name = _annotation.docTags.find("inheritdoc")->second.content;
if (name.empty())
{
m_errorReporter.docstringParsingError(
@ -361,7 +360,7 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum
return;
}
vector<string> path;
std::vector<std::string> path;
boost::split(path, name, boost::is_any_of("."));
if (any_of(path.begin(), path.end(), [](auto& _str) { return _str.empty(); }))
{
@ -421,7 +420,7 @@ void ReferencesResolver::validateYulIdentifierName(yul::YulString _name, SourceL
"User-defined identifiers in inline assembly cannot contain '.'."
);
if (set<string>{"this", "super", "_"}.count(_name.str()))
if (std::set<std::string>{"this", "super", "_"}.count(_name.str()))
m_errorReporter.declarationError(
4113_error,
_location,

View File

@ -20,7 +20,6 @@
#include <libsolidity/ast/AST.h>
using namespace std;
using namespace solidity;
using namespace solidity::frontend;

View File

@ -28,7 +28,6 @@
#include <liblangutil/ErrorReporter.h>
#include <memory>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -71,7 +70,7 @@ private:
return m_usesAssembly[&_contract];
}
map<ContractDefinition const*, bool> m_usesAssembly;
std::map<ContractDefinition const*, bool> m_usesAssembly;
};
StaticAnalyzer::StaticAnalyzer(ErrorReporter& _errorReporter):
@ -124,7 +123,7 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&)
5667_error,
var.first.second->location(),
"Unused " +
string(var.first.second->isTryCatchParameter() ? "try/catch" : "function") +
std::string(var.first.second->isTryCatchParameter() ? "try/catch" : "function") +
" parameter. Remove or comment out the variable name to silence this warning."
);
else
@ -142,7 +141,7 @@ bool StaticAnalyzer::visit(Identifier const& _identifier)
{
solAssert(!var->name().empty(), "");
if (var->isLocalVariable())
m_localVarUseCount[make_pair(var->id(), var)] += 1;
m_localVarUseCount[std::make_pair(var->id(), var)] += 1;
}
return true;
}
@ -154,7 +153,7 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable)
solAssert(_variable.isLocalVariable(), "");
if (_variable.name() != "")
// This is not a no-op, the entry might pre-exist.
m_localVarUseCount[make_pair(_variable.id(), &_variable)] += 0;
m_localVarUseCount[std::make_pair(_variable.id(), &_variable)] += 0;
}
if (_variable.isStateVariable() || _variable.referenceLocation() == VariableDeclaration::Location::Storage)
@ -162,7 +161,7 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable)
for (Type const* type: varType->fullDecomposition())
if (type->storageSizeUpperBound() >= (bigint(1) << 64))
{
string message = "Type " + type->toString(true) +
std::string message = "Type " + type->toString(true) +
" covers a large part of storage and thus makes collisions likely."
" Either use mappings or dynamic arrays and allow their size to be increased only"
" in small quantities per transaction.";
@ -179,7 +178,7 @@ bool StaticAnalyzer::visit(Return const& _return)
if (m_currentFunction && _return.expression())
for (auto const& var: m_currentFunction->returnParameters())
if (!var->name().empty())
m_localVarUseCount[make_pair(var->id(), var.get())] += 1;
m_localVarUseCount[std::make_pair(var->id(), var.get())] += 1;
return true;
}
@ -214,7 +213,7 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess)
else if (type->kind() == MagicType::Kind::MetaType && _memberAccess.memberName() == "runtimeCode")
{
if (!m_constructorUsesAssembly)
m_constructorUsesAssembly = make_unique<ConstructorUsesAssembly>();
m_constructorUsesAssembly = std::make_unique<ConstructorUsesAssembly>();
ContractType const& contract = dynamic_cast<ContractType const&>(*type->typeArgument());
if (m_constructorUsesAssembly->check(contract.contractDefinition()))
m_errorReporter.warning(
@ -288,7 +287,7 @@ bool StaticAnalyzer::visit(InlineAssembly const& _inlineAssembly)
{
solAssert(!var->name().empty(), "");
if (var->isLocalVariable())
m_localVarUseCount[make_pair(var->id(), var)] += 1;
m_localVarUseCount[std::make_pair(var->id(), var)] += 1;
}
}

View File

@ -32,7 +32,6 @@
#include <string>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -55,17 +54,17 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit)
{
if (!m_versionPragmaFound)
{
string errorString("Source file does not specify required compiler version!");
SemVerVersion recommendedVersion{string(VersionString)};
std::string errorString("Source file does not specify required compiler version!");
SemVerVersion recommendedVersion{std::string(VersionString)};
if (!recommendedVersion.isPrerelease())
errorString +=
" Consider adding \"pragma solidity ^" +
to_string(recommendedVersion.major()) +
string(".") +
to_string(recommendedVersion.minor()) +
string(".") +
to_string(recommendedVersion.patch()) +
string(";\"");
std::to_string(recommendedVersion.major()) +
std::string(".") +
std::to_string(recommendedVersion.minor()) +
std::string(".") +
std::to_string(recommendedVersion.patch()) +
std::string(";\"");
// when reporting the warning, print the source name only
m_errorReporter.warning(3420_error, {-1, -1, _sourceUnit.location().sourceName}, errorString);
@ -84,7 +83,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
else if (_pragma.literals()[0] == "experimental")
{
solAssert(m_sourceUnit, "");
vector<string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
std::vector<std::string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
if (literals.empty())
m_errorReporter.syntaxError(
9679_error,
@ -99,7 +98,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
);
else
{
string const literal = literals[0];
std::string const literal = literals[0];
if (literal.empty())
m_errorReporter.syntaxError(3250_error, _pragma.location(), "Empty experimental feature name is invalid.");
else if (!ExperimentalFeatureNames.count(literal))
@ -135,7 +134,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
solAssert(m_sourceUnit, "");
if (
_pragma.literals().size() != 2 ||
!set<string>{"v1", "v2"}.count(_pragma.literals()[1])
!std::set<std::string>{"v1", "v2"}.count(_pragma.literals()[1])
)
m_errorReporter.syntaxError(
2745_error,
@ -155,17 +154,17 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
{
try
{
vector<Token> tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end());
vector<string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
std::vector<Token> tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end());
std::vector<std::string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
SemVerMatchExpressionParser parser(tokens, literals);
SemVerMatchExpression matchExpression = parser.parse();
static SemVerVersion const currentVersion{string(VersionString)};
static SemVerVersion const currentVersion{std::string(VersionString)};
if (!matchExpression.matches(currentVersion))
m_errorReporter.syntaxError(
3997_error,
_pragma.location(),
"Source file requires different compiler version (current compiler is " +
string(VersionString) + ") - note that nightly builds are considered to be "
std::string(VersionString) + ") - note that nightly builds are considered to be "
"strictly less than the released version"
);
m_versionPragmaFound = true;
@ -412,7 +411,7 @@ bool SyntaxChecker::visit(UsingForDirective const& _usingFor)
if (!_usingFor.usesBraces())
solAssert(
_usingFor.functionsAndOperators().size() == 1 &&
!get<1>(_usingFor.functionsAndOperators().front())
!std::get<1>(_usingFor.functionsAndOperators().front())
);
if (!m_currentContractKind && !_usingFor.typeName())
@ -455,7 +454,7 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
if (!_function.isFree() && !_function.isConstructor() && _function.noVisibilitySpecified())
{
string suggestedVisibility =
std::string suggestedVisibility =
_function.isFallback() ||
_function.isReceive() ||
m_currentContractKind == ContractKind::Interface

View File

@ -51,7 +51,6 @@
#include <memory>
#include <vector>
using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
@ -205,7 +204,7 @@ void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment)
TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall const& _functionCall, bool _abiEncoderV2)
{
vector<ASTPointer<Expression const>> arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> arguments = _functionCall.arguments();
if (arguments.size() != 2)
m_errorReporter.typeError(
5782_error,
@ -296,7 +295,7 @@ TypePointers TypeChecker::typeCheckABIDecodeAndRetrieveReturnType(FunctionCall c
TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(FunctionCall const& _functionCall)
{
vector<ASTPointer<Expression const>> arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> arguments = _functionCall.arguments();
if (arguments.size() != 1)
m_errorReporter.fatalTypeError(
8885_error,
@ -442,7 +441,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
m_errorReporter.typeError(5587_error, _function.location(), "\"internal\" and \"private\" functions cannot be payable.");
}
vector<VariableDeclaration const*> internalParametersInConstructor;
std::vector<VariableDeclaration const*> internalParametersInConstructor;
auto checkArgumentAndReturnParameter = [&](VariableDeclaration const& _var) {
if (type(_var)->containsNestedMapping())
@ -472,7 +471,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
if (!iType)
{
string message = iType.message();
std::string message = iType.message();
solAssert(!message.empty(), "Expected detailed error message!");
if (_function.isConstructor())
message += " You can make the contract abstract to avoid this problem.";
@ -483,7 +482,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
!typeSupportedByOldABIEncoder(*type(_var), _function.libraryFunction())
)
{
string message =
std::string message =
"This type is only supported in ABI coder v2. "
"Use \"pragma abicoder v2;\" to enable the feature.";
if (_function.isConstructor())
@ -509,10 +508,10 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
var->accept(*this);
}
set<Declaration const*> modifiers;
std::set<Declaration const*> modifiers;
for (ASTPointer<ModifierInvocation> const& modifier: _function.modifiers())
{
vector<ContractDefinition const*> baseContracts;
std::vector<ContractDefinition const*> baseContracts;
if (auto contract = dynamic_cast<ContractDefinition const*>(_function.scope()))
{
baseContracts = contract->annotation().linearizedBaseContracts;
@ -522,7 +521,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
visitManually(
*modifier,
_function.isConstructor() ? baseContracts : vector<ContractDefinition const*>()
_function.isConstructor() ? baseContracts : std::vector<ContractDefinition const*>()
);
Declaration const* decl = &dereference(modifier->name());
if (modifiers.count(decl))
@ -642,7 +641,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
FunctionType getter(_variable);
if (!useABICoderV2())
{
vector<string> unsupportedTypes;
std::vector<std::string> unsupportedTypes;
for (auto const& param: getter.parameterTypes() + getter.returnParameterTypes())
if (!typeSupportedByOldABIEncoder(*param, false /* isLibrary */))
unsupportedTypes.emplace_back(param->humanReadableName());
@ -713,7 +712,7 @@ void TypeChecker::endVisit(StructDefinition const& _struct)
void TypeChecker::visitManually(
ModifierInvocation const& _modifier,
vector<ContractDefinition const*> const& _bases
std::vector<ContractDefinition const*> const& _bases
)
{
std::vector<ASTPointer<Expression>> const& arguments =
@ -724,8 +723,8 @@ void TypeChecker::visitManually(
_modifier.name().accept(*this);
auto const* declaration = &dereference(_modifier.name());
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
std::vector<ASTPointer<VariableDeclaration>> emptyParameterList;
std::vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
if (auto modifierDecl = dynamic_cast<ModifierDefinition const*>(declaration))
{
parameters = &modifierDecl->parameters();
@ -920,8 +919,8 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
if (!identifierInfo.suffix.empty())
{
string const& suffix = identifierInfo.suffix;
solAssert((set<string>{"offset", "slot", "length", "selector", "address"}).count(suffix), "");
std::string const& suffix = identifierInfo.suffix;
solAssert((std::set<std::string>{"offset", "slot", "length", "selector", "address"}).count(suffix), "");
if (!var->isConstant() && (var->isStateVariable() || var->type()->dataStoredIn(DataLocation::Storage)))
{
if (suffix != "slot" && suffix != "offset")
@ -1042,7 +1041,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return true;
};
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
_inlineAssembly.annotation().analysisInfo = make_shared<yul::AsmAnalysisInfo>();
_inlineAssembly.annotation().analysisInfo = std::make_shared<yul::AsmAnalysisInfo>();
yul::AsmAnalyzer analyzer(
*_inlineAssembly.annotation().analysisInfo,
m_errorReporter,
@ -1113,9 +1112,9 @@ void TypeChecker::endVisit(TryStatement const& _tryStatement)
2800_error,
successClause.location(),
"Function returns " +
to_string(functionType.returnParameterTypes().size()) +
std::to_string(functionType.returnParameterTypes().size()) +
" values, but returns clause has " +
to_string(parameters.size()) +
std::to_string(parameters.size()) +
" variables."
);
for (auto&& [parameter, returnType]: ranges::views::zip(parameters, returnTypes))
@ -1363,7 +1362,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
else
valueTypes = TypePointers{type(*_statement.initialValue())};
vector<ASTPointer<VariableDeclaration>> const& variables = _statement.declarations();
std::vector<ASTPointer<VariableDeclaration>> const& variables = _statement.declarations();
if (variables.empty())
// We already have an error for this in the SyntaxChecker.
solAssert(m_errorReporter.hasErrors(), "");
@ -1378,7 +1377,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
")."
);
for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i)
for (size_t i = 0; i < std::min(variables.size(), valueTypes.size()); ++i)
{
if (!variables[i])
continue;
@ -1535,14 +1534,14 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const&
m_errorReporter.typeError(5547_error, _expression.location(), "Empty tuple on the left hand side.");
auto const* tupleType = dynamic_cast<TupleType const*>(&_type);
auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : vector<Type const*> { &_type };
auto const& types = tupleType && tupleExpression->components().size() != 1 ? tupleType->components() : std::vector<Type const*> { &_type };
solAssert(
tupleExpression->components().size() == types.size() || m_errorReporter.hasErrors(),
"Array sizes don't match and no errors generated."
);
for (size_t i = 0; i < min(tupleExpression->components().size(), types.size()); i++)
for (size_t i = 0; i < std::min(tupleExpression->components().size(), types.size()); i++)
if (types[i])
{
solAssert(!!tupleExpression->components()[i], "");
@ -1607,7 +1606,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
7366_error,
_assignment.location(),
"Operator " +
string(TokenTraits::friendlyName(_assignment.assignmentOperator())) +
std::string(TokenTraits::friendlyName(_assignment.assignmentOperator())) +
" not compatible with types " +
t->humanReadableName() +
" and " +
@ -1621,7 +1620,7 @@ bool TypeChecker::visit(Assignment const& _assignment)
bool TypeChecker::visit(TupleExpression const& _tuple)
{
_tuple.annotation().isConstant = false;
vector<ASTPointer<Expression>> const& components = _tuple.components();
std::vector<ASTPointer<Expression>> const& components = _tuple.components();
TypePointers types;
if (_tuple.annotation().willBeWrittenTo)
@ -1734,7 +1733,7 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
// Check if the operator is built-in or user-defined.
TypeResult builtinResult = operandType->unaryOperatorResult(op);
set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = operandType->operatorDefinitions(
std::set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = operandType->operatorDefinitions(
op,
*currentDefinitionScope(),
true // _unary
@ -1760,7 +1759,7 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
}
else
{
string description = fmt::format(
std::string description = fmt::format(
"Built-in unary operator {} cannot be applied to type {}.",
TokenTraits::friendlyName(op),
operandType->humanReadableName()
@ -1802,7 +1801,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
// Check if the operator is built-in or user-defined.
TypeResult builtinResult = leftType->binaryOperatorResult(_operation.getOperator(), rightType);
set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = leftType->operatorDefinitions(
std::set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = leftType->operatorDefinitions(
_operation.getOperator(),
*currentDefinitionScope(),
false // _unary
@ -1828,7 +1827,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
}
else
{
string description = fmt::format(
std::string description = fmt::format(
"Built-in binary operator {} cannot be applied to types {} and {}.",
TokenTraits::friendlyName(_operation.getOperator()),
leftType->humanReadableName(),
@ -1893,7 +1892,7 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
if (_operation.getOperator() == Token::Exp || _operation.getOperator() == Token::SHL)
{
string operation = _operation.getOperator() == Token::Exp ? "exponentiation" : "shift";
std::string operation = _operation.getOperator() == Token::Exp ? "exponentiation" : "shift";
if (
leftType->category() == Type::Category::RationalNumber &&
rightType->category() != Type::Category::RationalNumber
@ -1933,7 +1932,7 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
solAssert(*_functionCall.annotation().kind == FunctionCallKind::TypeConversion, "");
Type const* expressionType = type(_functionCall.expression());
vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
bool const isPositionalCall = _functionCall.names().empty();
Type const* resultType = dynamic_cast<TypeType const&>(*expressionType).actualType();
@ -2215,7 +2214,7 @@ void TypeChecker::typeCheckABIEncodeFunctions(
}
// Check additional arguments for variadic functions
vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
for (size_t i = 0; i < arguments.size(); ++i)
{
auto const& argType = type(*arguments[i]);
@ -2274,7 +2273,7 @@ void TypeChecker::typeCheckABIEncodeFunctions(
void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCall)
{
vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
// Expecting first argument to be the function pointer and second to be a tuple.
if (arguments.size() != 2)
@ -2311,7 +2310,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
externalFunctionType->kind() != FunctionType::Kind::Declaration
)
{
string msg = "Expected regular external function type, or external view on public function.";
std::string msg = "Expected regular external function type, or external view on public function.";
switch (externalFunctionType->kind())
{
@ -2360,7 +2359,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
}
solAssert(!externalFunctionType->takesArbitraryParameters(), "Function must have fixed parameters.");
// Tuples with only one component become that component
vector<ASTPointer<Expression const>> callArguments;
std::vector<ASTPointer<Expression const>> callArguments;
auto const* tupleType = dynamic_cast<TupleType const*>(type(*arguments[1]));
if (tupleType)
@ -2387,9 +2386,9 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
7788_error,
_functionCall.location(),
"Expected " +
to_string(externalFunctionType->parameterTypes().size()) +
std::to_string(externalFunctionType->parameterTypes().size()) +
" instead of " +
to_string(callArguments.size()) +
std::to_string(callArguments.size()) +
" components for the tuple parameter."
);
else
@ -2397,13 +2396,13 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
7515_error,
_functionCall.location(),
"Expected a tuple with " +
to_string(externalFunctionType->parameterTypes().size()) +
std::to_string(externalFunctionType->parameterTypes().size()) +
" components instead of a single non-tuple parameter."
);
}
// Use min() to check as much as we can before failing fatally
size_t const numParameters = min(callArguments.size(), externalFunctionType->parameterTypes().size());
size_t const numParameters = std::min(callArguments.size(), externalFunctionType->parameterTypes().size());
for (size_t i = 0; i < numParameters; i++)
{
@ -2414,7 +2413,7 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
5407_error,
callArguments[i]->location(),
"Cannot implicitly convert component at position " +
to_string(i) +
std::to_string(i) +
" from \"" +
argType.humanReadableName() +
"\" to \"" +
@ -2437,7 +2436,7 @@ void TypeChecker::typeCheckStringConcatFunction(
typeCheckFunctionGeneralChecks(_functionCall, _functionType);
for (shared_ptr<Expression const> const& argument: _functionCall.arguments())
for (std::shared_ptr<Expression const> const& argument: _functionCall.arguments())
{
Type const* argumentType = type(*argument);
bool notConvertibleToString = !argumentType->isImplicitlyConvertibleTo(*TypeProvider::stringMemory());
@ -2464,7 +2463,7 @@ void TypeChecker::typeCheckBytesConcatFunction(
typeCheckFunctionGeneralChecks(_functionCall, _functionType);
for (shared_ptr<Expression const> const& argument: _functionCall.arguments())
for (std::shared_ptr<Expression const> const& argument: _functionCall.arguments())
{
Type const* argumentType = type(*argument);
bool notConvertibleToBytes =
@ -2504,8 +2503,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
);
TypePointers const& parameterTypes = _functionType->parameterTypes();
vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
vector<ASTPointer<ASTString>> const& argumentNames = _functionCall.names();
std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
std::vector<ASTPointer<ASTString>> const& argumentNames = _functionCall.names();
// Check number of passed in arguments
if (
@ -2516,22 +2515,22 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
bool const isStructConstructorCall =
functionCallKind == FunctionCallKind::StructConstructorCall;
auto [errorId, description] = [&]() -> tuple<ErrorId, string> {
string msg = isVariadic ?
auto [errorId, description] = [&]() -> std::tuple<ErrorId, std::string> {
std::string msg = isVariadic ?
"Need at least " +
toString(parameterTypes.size()) +
" arguments for " +
string(isStructConstructorCall ? "struct constructor" : "function call") +
std::string(isStructConstructorCall ? "struct constructor" : "function call") +
", but provided only " +
toString(arguments.size()) +
"."
:
"Wrong argument count for " +
string(isStructConstructorCall ? "struct constructor" : "function call") +
std::string(isStructConstructorCall ? "struct constructor" : "function call") +
": " +
toString(arguments.size()) +
" arguments given but " +
string(isVariadic ? "need at least " : "expected ") +
std::string(isVariadic ? "need at least " : "expected ") +
toString(parameterTypes.size()) +
".";
@ -2659,8 +2658,8 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
BoolResult result = type(*paramArgMap[i])->isImplicitlyConvertibleTo(*parameterTypes[i]);
if (!result)
{
auto [errorId, description] = [&]() -> tuple<ErrorId, string> {
string msg =
auto [errorId, description] = [&]() -> std::tuple<ErrorId, std::string> {
std::string msg =
"Invalid type for argument in function call. "
"Invalid implicit conversion from " +
type(*paramArgMap[i])->humanReadableName() +
@ -2751,7 +2750,7 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
bool TypeChecker::visit(FunctionCall const& _functionCall)
{
vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
bool argumentsArePure = true;
// We need to check arguments' type first as they will be needed for overload resolution.
@ -2991,7 +2990,7 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions)
"{...}-option."
);
auto setCheckOption = [&](bool& _option, string const& _name)
auto setCheckOption = [&](bool& _option, std::string const& _name)
{
if (_option)
m_errorReporter.typeError(
@ -3005,7 +3004,7 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions)
for (size_t i = 0; i < _functionCallOptions.names().size(); ++i)
{
string const& name = *(_functionCallOptions.names()[i]);
std::string const& name = *(_functionCallOptions.names()[i]);
if (name == "salt")
{
if (kind == FunctionType::Kind::Creation)
@ -3185,8 +3184,8 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
);
}
auto [errorId, description] = [&]() -> tuple<ErrorId, string> {
string errorMsg = "Member \"" + memberName + "\" not found or not visible "
auto [errorId, description] = [&]() -> std::tuple<ErrorId, std::string> {
std::string errorMsg = "Member \"" + memberName + "\" not found or not visible "
"after argument-dependent lookup in " + exprType->humanReadableName() + ".";
if (auto const* funType = dynamic_cast<FunctionType const*>(exprType))
@ -3222,7 +3221,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (addressMember.name == memberName)
{
auto const* var = dynamic_cast<Identifier const*>(&_memberAccess.expression());
string varName = var ? var->name() : "...";
std::string varName = var ? var->name() : "...";
errorMsg += " Use \"address(" + varName + ")." + memberName + "\" to access this address member.";
return { 3125_error, errorMsg };
}
@ -3606,13 +3605,13 @@ bool TypeChecker::visit(IndexRangeAccess const& _access)
return false;
}
vector<Declaration const*> TypeChecker::cleanOverloadedDeclarations(
std::vector<Declaration const*> TypeChecker::cleanOverloadedDeclarations(
Identifier const& _identifier,
vector<Declaration const*> const& _candidates
std::vector<Declaration const*> const& _candidates
)
{
solAssert(_candidates.size() > 1, "");
vector<Declaration const*> uniqueDeclarations;
std::vector<Declaration const*> uniqueDeclarations;
for (Declaration const* declaration: _candidates)
{
@ -3665,7 +3664,7 @@ bool TypeChecker::visit(Identifier const& _identifier)
else if (!annotation.arguments)
{
// The identifier should be a public state variable shadowing other functions
vector<Declaration const*> candidates;
std::vector<Declaration const*> candidates;
for (Declaration const* declaration: annotation.overloadedDeclarations)
{
@ -3681,7 +3680,7 @@ bool TypeChecker::visit(Identifier const& _identifier)
}
else
{
vector<Declaration const*> candidates;
std::vector<Declaration const*> candidates;
for (Declaration const* declaration: annotation.overloadedDeclarations)
{
@ -3700,7 +3699,7 @@ bool TypeChecker::visit(Identifier const& _identifier)
if (!declaration->location().isValid())
{
// Try to re-construct function definition
string description;
std::string description;
for (auto const& param: declaration->functionType(true)->parameterTypes())
description += (description.empty() ? "" : ", ") + param->humanReadableName();
description = "function " + _identifier.name() + "(" + description + ")";
@ -3816,12 +3815,12 @@ void TypeChecker::endVisit(Literal const& _literal)
// Assign type here if it even looks like an address. This prevents double errors for invalid addresses
_literal.annotation().type = TypeProvider::address();
string msg;
std::string msg;
if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits
// looksLikeAddress enforces that it is a hex literal starting with "0x"
msg =
"This looks like an address but is not exactly 40 hex digits. It is " +
to_string(_literal.valueWithoutUnderscores().length() - 2) +
std::to_string(_literal.valueWithoutUnderscores().length() - 2) +
" hex digits.";
else if (!_literal.passesAddressChecksum())
{
@ -4034,7 +4033,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
bool isBinaryOnlyOperator = (TokenTraits::isBinaryOp(operator_.value()) && !TokenTraits::isUnaryOp(operator_.value()));
bool firstParameterMatchesUsingFor = parameterCount == 0 || *usingForType == *parameterTypes.front();
optional<string> wrongParametersMessage;
std::optional<std::string> wrongParametersMessage;
if (isBinaryOnlyOperator && (parameterCount != 2 || !identicalFirstTwoParameters))
wrongParametersMessage = fmt::format("two parameters of type {} and the same data location", usingForType->canonicalName());
else if (isUnaryOnlyOperator && (parameterCount != 1 || !firstParameterMatchesUsingFor))
@ -4065,7 +4064,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
TypePointers const& returnParameterTypes = functionType->returnParameterTypes();
size_t const returnParameterCount = returnParameterTypes.size();
optional<string> wrongReturnParametersMessage;
std::optional<std::string> wrongReturnParametersMessage;
if (!TokenTraits::isCompareOp(operator_.value()) && operator_.value() != Token::Not)
{
if (returnParameterCount != 1 || *usingForType != *returnParameterTypes.front())
@ -4100,7 +4099,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
{
// TODO: This is pretty inefficient. For every operator binding we find, we're
// traversing all bindings in all `using for` directives in the current scope.
set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = usingForType->operatorDefinitions(
std::set<FunctionDefinition const*, ASTNode::CompareByID> matchingDefinitions = usingForType->operatorDefinitions(
operator_.value(),
*currentDefinitionScope(),
parameterCount == 1 // _unary
@ -4133,7 +4132,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
void TypeChecker::checkErrorAndEventParameters(CallableDeclaration const& _callable)
{
string kind = dynamic_cast<EventDefinition const*>(&_callable) ? "event" : "error";
std::string kind = dynamic_cast<EventDefinition const*>(&_callable) ? "event" : "error";
for (ASTPointer<VariableDeclaration> const& var: _callable.parameters())
{
if (type(*var)->containsNestedMapping())
@ -4223,7 +4222,7 @@ void TypeChecker::requireLValue(Expression const& _expression, bool _ordinaryAss
if (*_expression.annotation().isLValue)
return;
auto [errorId, description] = [&]() -> tuple<ErrorId, string> {
auto [errorId, description] = [&]() -> std::tuple<ErrorId, std::string> {
if (*_expression.annotation().isConstant)
return { 6520_error, "Cannot assign to a constant variable." };

View File

@ -27,7 +27,6 @@
#include <utility>
#include <variant>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
@ -312,13 +311,13 @@ ViewPureChecker::MutabilityAndLocation const& ViewPureChecker::modifierMutabilit
{
MutabilityAndLocation bestMutabilityAndLocation{};
FunctionDefinition const* currentFunction = nullptr;
swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation);
swap(currentFunction, m_currentFunction);
std::swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation);
std::swap(currentFunction, m_currentFunction);
_modifier.accept(*this);
swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation);
swap(currentFunction, m_currentFunction);
std::swap(bestMutabilityAndLocation, m_bestMutabilityAndLocation);
std::swap(currentFunction, m_currentFunction);
}
return m_inferredMutability.at(&_modifier);
}
@ -384,8 +383,8 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
break;
case Type::Category::Magic:
{
using MagicMember = pair<MagicType::Kind, string>;
set<MagicMember> static const pureMembers{
using MagicMember = std::pair<MagicType::Kind, std::string>;
std::set<MagicMember> static const pureMembers{
{MagicType::Kind::ABI, "decode"},
{MagicType::Kind::ABI, "encode"},
{MagicType::Kind::ABI, "encodePacked"},
@ -401,7 +400,7 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
{MagicType::Kind::MetaType, "min"},
{MagicType::Kind::MetaType, "max"},
};
set<MagicMember> static const payableMembers{
std::set<MagicMember> static const payableMembers{
{MagicType::Kind::Message, "value"}
};

View File

@ -25,6 +25,7 @@ NAMESPACE_STD_FREE_FILES=(
liblangutil/*
libsmtutil/*
libsolc/*
libsolidity/analysis/*
)
(