Merge pull request #14522 from junaire/purge-using-namespace-std-in-libyul

Purge using namespace std in libyul
This commit is contained in:
Nikola Matić 2023-08-29 12:38:50 +02:00 committed by GitHub
commit df03f1412d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 227 additions and 241 deletions

View File

@ -44,7 +44,7 @@
#include <memory>
#include <functional>
using namespace std;
using namespace std::string_literals;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
@ -52,7 +52,7 @@ using namespace solidity::langutil;
namespace
{
inline string to_string(LiteralKind _kind)
inline std::string to_string(LiteralKind _kind)
{
switch (_kind)
{
@ -98,14 +98,14 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
return analysisInfo;
}
vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
std::vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
{
expectValidType(_literal.type, nativeLocationOf(_literal));
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
m_errorReporter.typeError(
3069_error,
nativeLocationOf(_literal),
"String literal too long (" + to_string(_literal.value.str().size()) + " > 32)"
"String literal too long (" + std::to_string(_literal.value.str().size()) + " > 32)"
);
else if (_literal.kind == LiteralKind::Number && bigint(_literal.value.str()) > u256(-1))
m_errorReporter.typeError(6708_error, nativeLocationOf(_literal), "Number literal too large (> 256 bits)");
@ -122,7 +122,7 @@ vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
return {_literal.type};
}
vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
std::vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
{
yulAssert(!_identifier.name.empty(), "");
auto watcher = m_errorReporter.errorWatcher();
@ -180,13 +180,13 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
void AsmAnalyzer::operator()(ExpressionStatement const& _statement)
{
auto watcher = m_errorReporter.errorWatcher();
vector<YulString> types = std::visit(*this, _statement.expression);
std::vector<YulString> types = std::visit(*this, _statement.expression);
if (watcher.ok() && !types.empty())
m_errorReporter.typeError(
3083_error,
nativeLocationOf(_statement),
"Top-level expressions are not supposed to return values (this expression returns " +
to_string(types.size()) +
std::to_string(types.size()) +
" value" +
(types.size() == 1 ? "" : "s") +
"). Use ``pop()`` or assign them."
@ -199,7 +199,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
size_t const numVariables = _assignment.variableNames.size();
yulAssert(numVariables >= 1, "");
set<YulString> variables;
std::set<YulString> variables;
for (auto const& _variableName: _assignment.variableNames)
if (!variables.insert(_variableName.name).second)
m_errorReporter.declarationError(
@ -210,7 +210,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
" occurs multiple times on the left-hand side of the assignment."
);
vector<YulString> types = std::visit(*this, *_assignment.value);
std::vector<YulString> types = std::visit(*this, *_assignment.value);
if (types.size() != numVariables)
m_errorReporter.declarationError(
@ -219,9 +219,9 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
"Variable count for assignment to \"" +
joinHumanReadable(applyMap(_assignment.variableNames, [](auto const& _identifier){ return _identifier.name.str(); })) +
"\" does not match number of values (" +
to_string(numVariables) +
std::to_string(numVariables) +
" vs. " +
to_string(types.size()) +
std::to_string(types.size()) +
")"
);
@ -249,7 +249,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
if (_varDecl.value)
{
vector<YulString> types = std::visit(*this, *_varDecl.value);
std::vector<YulString> types = std::visit(*this, *_varDecl.value);
if (types.size() != numVariables)
m_errorReporter.declarationError(
3812_error,
@ -257,9 +257,9 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
"Variable count mismatch for declaration of \"" +
joinHumanReadable(applyMap(_varDecl.variables, [](auto const& _identifier){ return _identifier.name.str(); })) +
+ "\": " +
to_string(numVariables) +
std::to_string(numVariables) +
" variables and " +
to_string(types.size()) +
std::to_string(types.size()) +
" values."
);
@ -301,13 +301,13 @@ void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
(*this)(_funDef.body);
}
vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
std::vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
{
yulAssert(!_funCall.functionName.name.empty(), "");
auto watcher = m_errorReporter.errorWatcher();
vector<YulString> const* parameterTypes = nullptr;
vector<YulString> const* returnTypes = nullptr;
vector<optional<LiteralKind>> const* literalArguments = nullptr;
std::vector<YulString> const* parameterTypes = nullptr;
std::vector<YulString> const* returnTypes = nullptr;
std::vector<std::optional<LiteralKind>> const* literalArguments = nullptr;
if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name))
{
@ -367,12 +367,12 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
7000_error,
nativeLocationOf(_funCall.functionName),
"Function \"" + _funCall.functionName.name.str() + "\" expects " +
to_string(parameterTypes->size()) +
std::to_string(parameterTypes->size()) +
" arguments but got " +
to_string(_funCall.arguments.size()) + "."
std::to_string(_funCall.arguments.size()) + "."
);
vector<YulString> argTypes;
std::vector<YulString> argTypes;
for (size_t i = _funCall.arguments.size(); i > 0; i--)
{
Expression const& arg = _funCall.arguments[i - 1];
@ -382,13 +382,13 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
std::nullopt
)
{
if (!holds_alternative<Literal>(arg))
if (!std::holds_alternative<Literal>(arg))
m_errorReporter.typeError(
9114_error,
nativeLocationOf(_funCall.functionName),
"Function expects direct literals as arguments."
);
else if (*literalArgumentKind != get<Literal>(arg).kind)
else if (*literalArgumentKind != std::get<Literal>(arg).kind)
m_errorReporter.typeError(
5859_error,
nativeLocationOf(arg),
@ -396,10 +396,10 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
);
else if (*literalArgumentKind == LiteralKind::String)
{
string functionName = _funCall.functionName.name.str();
std::string functionName = _funCall.functionName.name.str();
if (functionName == "datasize" || functionName == "dataoffset")
{
if (!m_dataNames.count(get<Literal>(arg).value))
if (!m_dataNames.count(std::get<Literal>(arg).value))
m_errorReporter.typeError(
3517_error,
nativeLocationOf(arg),
@ -408,7 +408,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
}
else if (functionName.substr(0, "verbatim_"s.size()) == "verbatim_")
{
if (get<Literal>(arg).value.empty())
if (std::get<Literal>(arg).value.empty())
m_errorReporter.typeError(
1844_error,
nativeLocationOf(arg),
@ -416,7 +416,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
);
}
argTypes.emplace_back(expectUnlimitedStringLiteral(get<Literal>(arg)));
argTypes.emplace_back(expectUnlimitedStringLiteral(std::get<Literal>(arg)));
continue;
}
}
@ -435,7 +435,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
return *returnTypes;
}
else if (returnTypes)
return vector<YulString>(returnTypes->size(), m_dialect.defaultType);
return std::vector<YulString>(returnTypes->size(), m_dialect.defaultType);
else
return {};
}
@ -460,7 +460,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
YulString valueType = expectExpression(*_switch.expression);
set<u256> cases;
std::set<u256> cases;
for (auto const& _case: _switch.cases)
{
if (_case.value)
@ -525,13 +525,13 @@ void AsmAnalyzer::operator()(Block const& _block)
YulString AsmAnalyzer::expectExpression(Expression const& _expr)
{
vector<YulString> types = std::visit(*this, _expr);
std::vector<YulString> types = std::visit(*this, _expr);
if (types.size() != 1)
m_errorReporter.typeError(
3950_error,
nativeLocationOf(_expr),
"Expected expression to evaluate to one value, but got " +
to_string(types.size()) +
std::to_string(types.size()) +
" values instead."
);
return types.empty() ? m_dialect.defaultType : types.front();
@ -576,7 +576,7 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
m_currentScope->insideFunction()
);
if (!holds_alternative<Scope::Variable>(*var))
if (!std::holds_alternative<Scope::Variable>(*var))
m_errorReporter.typeError(2657_error, nativeLocationOf(_variable), "Assignment requires variable.");
else if (!m_activeVariables.count(&std::get<Scope::Variable>(*var)))
m_errorReporter.declarationError(
@ -692,7 +692,7 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
_instr != evmasm::Instruction::JUMPDEST,
"");
auto errorForVM = [&](ErrorId _errorId, string const& vmKindMessage) {
auto errorForVM = [&](ErrorId _errorId, std::string const& vmKindMessage) {
m_errorReporter.typeError(
_errorId,
_location,

View File

@ -26,8 +26,6 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/UTF8.h>
using namespace std;
namespace solidity::yul
{
@ -183,14 +181,14 @@ Json::Value AsmJsonConverter::operator()(Leave const& _node) const
return createAstNode(originLocationOf(_node), nativeLocationOf(_node), "YulLeave");
}
Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, string _nodeType) const
Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, std::string _nodeType) const
{
Json::Value ret{Json::objectValue};
ret["nodeType"] = std::move(_nodeType);
auto srcLocation = [&](int start, int end) -> string
auto srcLocation = [&](int start, int end) -> std::string
{
int length = (start >= 0 && end >= 0 && end >= start) ? end - start : -1;
return to_string(start) + ":" + to_string(length) + ":" + (m_sourceIndex.has_value() ? to_string(m_sourceIndex.value()) : "-1");
return std::to_string(start) + ":" + std::to_string(length) + ":" + (m_sourceIndex.has_value() ? std::to_string(m_sourceIndex.value()) : "-1");
};
ret["src"] = srcLocation(_originLocation.start, _originLocation.end);
ret["nativeSrc"] = srcLocation(_nativeLocation.start, _nativeLocation.end);
@ -198,7 +196,7 @@ Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _ori
}
template <class T>
Json::Value AsmJsonConverter::vectorOfVariantsToJson(vector<T> const& _vec) const
Json::Value AsmJsonConverter::vectorOfVariantsToJson(std::vector<T> const& _vec) const
{
Json::Value ret{Json::arrayValue};
for (auto const& var: _vec)

View File

@ -34,7 +34,6 @@
#include <vector>
using namespace std;
using namespace solidity::langutil;
namespace solidity::yul
@ -62,7 +61,7 @@ T AsmJsonImporter::createAsmNode(Json::Value const& _node)
return r;
}
Json::Value AsmJsonImporter::member(Json::Value const& _node, string const& _name)
Json::Value AsmJsonImporter::member(Json::Value const& _node, std::string const& _name)
{
if (!_node.isMember(_name))
return Json::nullValue;
@ -81,7 +80,7 @@ Statement AsmJsonImporter::createStatement(Json::Value const& _node)
{
Json::Value jsonNodeType = member(_node, "nodeType");
yulAssert(jsonNodeType.isString(), "Expected \"nodeType\" to be of type string!");
string nodeType = jsonNodeType.asString();
std::string nodeType = jsonNodeType.asString();
yulAssert(nodeType.substr(0, 3) == "Yul", "Invalid nodeType prefix");
nodeType = nodeType.substr(3);
@ -119,7 +118,7 @@ Expression AsmJsonImporter::createExpression(Json::Value const& _node)
{
Json::Value jsonNodeType = member(_node, "nodeType");
yulAssert(jsonNodeType.isString(), "Expected \"nodeType\" to be of type string!");
string nodeType = jsonNodeType.asString();
std::string nodeType = jsonNodeType.asString();
yulAssert(nodeType.substr(0, 3) == "Yul", "Invalid nodeType prefix");
nodeType = nodeType.substr(3);
@ -137,17 +136,17 @@ Expression AsmJsonImporter::createExpression(Json::Value const& _node)
util::unreachable();
}
vector<Expression> AsmJsonImporter::createExpressionVector(Json::Value const& _array)
std::vector<Expression> AsmJsonImporter::createExpressionVector(Json::Value const& _array)
{
vector<Expression> ret;
std::vector<Expression> ret;
for (auto& var: _array)
ret.emplace_back(createExpression(var));
return ret;
}
vector<Statement> AsmJsonImporter::createStatementVector(Json::Value const& _array)
std::vector<Statement> AsmJsonImporter::createStatementVector(Json::Value const& _array)
{
vector<Statement> ret;
std::vector<Statement> ret;
for (auto& var: _array)
ret.emplace_back(createStatement(var));
return ret;
@ -163,7 +162,7 @@ Block AsmJsonImporter::createBlock(Json::Value const& _node)
Literal AsmJsonImporter::createLiteral(Json::Value const& _node)
{
auto lit = createAsmNode<Literal>(_node);
string kind = member(_node, "kind").asString();
std::string kind = member(_node, "kind").asString();
solAssert(member(_node, "hexValue").isString() || member(_node, "value").isString(), "");
if (_node.isMember("hexValue"))
@ -180,7 +179,7 @@ Literal AsmJsonImporter::createLiteral(Json::Value const& _node)
lit.kind = LiteralKind::Number;
yulAssert(
scanner.currentToken() == Token::Number,
"Expected number but got " + langutil::TokenTraits::friendlyName(scanner.currentToken()) + string(" while scanning ") + lit.value.str()
"Expected number but got " + langutil::TokenTraits::friendlyName(scanner.currentToken()) + std::string(" while scanning ") + lit.value.str()
);
}
else if (kind == "bool")
@ -199,7 +198,7 @@ Literal AsmJsonImporter::createLiteral(Json::Value const& _node)
lit.kind = LiteralKind::String;
yulAssert(
lit.value.str().size() <= 32,
"String literal too long (" + to_string(lit.value.str().size()) + " > 32)"
"String literal too long (" + std::to_string(lit.value.str().size()) + " > 32)"
);
}
else
@ -228,7 +227,7 @@ Assignment AsmJsonImporter::createAssignment(Json::Value const& _node)
for (auto const& var: member(_node, "variableNames"))
assignment.variableNames.emplace_back(createIdentifier(var));
assignment.value = make_unique<Expression>(createExpression(member(_node, "value")));
assignment.value = std::make_unique<Expression>(createExpression(member(_node, "value")));
return assignment;
}
@ -256,7 +255,7 @@ VariableDeclaration AsmJsonImporter::createVariableDeclaration(Json::Value const
auto varDec = createAsmNode<VariableDeclaration>(_node);
for (auto const& var: member(_node, "variables"))
varDec.variables.emplace_back(createTypedName(var));
varDec.value = make_unique<Expression>(createExpression(member(_node, "value")));
varDec.value = std::make_unique<Expression>(createExpression(member(_node, "value")));
return varDec;
}
@ -280,7 +279,7 @@ FunctionDefinition AsmJsonImporter::createFunctionDefinition(Json::Value const&
If AsmJsonImporter::createIf(Json::Value const& _node)
{
auto ifStatement = createAsmNode<If>(_node);
ifStatement.condition = make_unique<Expression>(createExpression(member(_node, "condition")));
ifStatement.condition = std::make_unique<Expression>(createExpression(member(_node, "condition")));
ifStatement.body = createBlock(member(_node, "body"));
return ifStatement;
}
@ -292,7 +291,7 @@ Case AsmJsonImporter::createCase(Json::Value const& _node)
if (value.isString())
yulAssert(value.asString() == "default", "Expected default case");
else
caseStatement.value = make_unique<Literal>(createLiteral(value));
caseStatement.value = std::make_unique<Literal>(createLiteral(value));
caseStatement.body = createBlock(member(_node, "body"));
return caseStatement;
}
@ -300,7 +299,7 @@ Case AsmJsonImporter::createCase(Json::Value const& _node)
Switch AsmJsonImporter::createSwitch(Json::Value const& _node)
{
auto switchStatement = createAsmNode<Switch>(_node);
switchStatement.expression = make_unique<Expression>(createExpression(member(_node, "expression")));
switchStatement.expression = std::make_unique<Expression>(createExpression(member(_node, "expression")));
for (auto const& var: member(_node, "cases"))
switchStatement.cases.emplace_back(createCase(var));
return switchStatement;
@ -310,7 +309,7 @@ ForLoop AsmJsonImporter::createForLoop(Json::Value const& _node)
{
auto forLoop = createAsmNode<ForLoop>(_node);
forLoop.pre = createBlock(member(_node, "pre"));
forLoop.condition = make_unique<Expression>(createExpression(member(_node, "condition")));
forLoop.condition = std::make_unique<Expression>(createExpression(member(_node, "condition")));
forLoop.post = createBlock(member(_node, "post"));
forLoop.body = createBlock(member(_node, "body"));
return forLoop;

View File

@ -37,7 +37,6 @@
#include <algorithm>
#include <regex>
using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
@ -46,7 +45,7 @@ using namespace solidity::yul;
namespace
{
optional<int> toInt(string const& _value)
std::optional<int> toInt(std::string const& _value)
{
try
{
@ -54,7 +53,7 @@ optional<int> toInt(string const& _value)
}
catch (...)
{
return nullopt;
return std::nullopt;
}
}
@ -75,7 +74,7 @@ std::shared_ptr<DebugData const> Parser::createDebugData() const
}
void Parser::updateLocationEndFrom(
shared_ptr<DebugData const>& _debugData,
std::shared_ptr<DebugData const>& _debugData,
SourceLocation const& _location
) const
{
@ -88,7 +87,7 @@ void Parser::updateLocationEndFrom(
DebugData updatedDebugData = *_debugData;
updatedDebugData.nativeLocation.end = _location.end;
updatedDebugData.originLocation.end = _location.end;
_debugData = make_shared<DebugData const>(std::move(updatedDebugData));
_debugData = std::make_shared<DebugData const>(std::move(updatedDebugData));
break;
}
case UseSourceLocationFrom::LocationOverride:
@ -98,21 +97,21 @@ void Parser::updateLocationEndFrom(
{
DebugData updatedDebugData = *_debugData;
updatedDebugData.nativeLocation.end = _location.end;
_debugData = make_shared<DebugData const>(std::move(updatedDebugData));
_debugData = std::make_shared<DebugData const>(std::move(updatedDebugData));
break;
}
}
}
unique_ptr<Block> Parser::parse(CharStream& _charStream)
std::unique_ptr<Block> Parser::parse(CharStream& _charStream)
{
m_scanner = make_shared<Scanner>(_charStream);
unique_ptr<Block> block = parseInline(m_scanner);
m_scanner = std::make_shared<Scanner>(_charStream);
std::unique_ptr<Block> block = parseInline(m_scanner);
expectToken(Token::EOS);
return block;
}
unique_ptr<Block> Parser::parseInline(std::shared_ptr<Scanner> const& _scanner)
std::unique_ptr<Block> Parser::parseInline(std::shared_ptr<Scanner> const& _scanner)
{
m_recursionDepth = 0;
@ -124,7 +123,7 @@ unique_ptr<Block> Parser::parseInline(std::shared_ptr<Scanner> const& _scanner)
m_scanner = _scanner;
if (m_useSourceLocationFrom == UseSourceLocationFrom::Comments)
fetchDebugDataFromComment();
return make_unique<Block>(parseBlock());
return std::make_unique<Block>(parseBlock());
}
catch (FatalError const&)
{
@ -146,17 +145,17 @@ void Parser::fetchDebugDataFromComment()
{
solAssert(m_sourceNames.has_value(), "");
static regex const tagRegex = regex(
static std::regex const tagRegex = std::regex(
R"~~((?:^|\s+)(@[a-zA-Z0-9\-_]+)(?:\s+|$))~~", // tag, e.g: @src
regex_constants::ECMAScript | regex_constants::optimize
std::regex_constants::ECMAScript | std::regex_constants::optimize
);
string_view commentLiteral = m_scanner->currentCommentLiteral();
match_results<string_view::const_iterator> match;
std::string_view commentLiteral = m_scanner->currentCommentLiteral();
std::match_results<std::string_view::const_iterator> match;
langutil::SourceLocation originLocation = m_locationFromComment;
// Empty for each new node.
optional<int> astID;
std::optional<int> astID;
while (regex_search(commentLiteral.cbegin(), commentLiteral.cend(), match, tagRegex))
{
@ -186,17 +185,17 @@ void Parser::fetchDebugDataFromComment()
m_astIDFromComment = astID;
}
optional<pair<string_view, SourceLocation>> Parser::parseSrcComment(
string_view const _arguments,
std::optional<std::pair<std::string_view, SourceLocation>> Parser::parseSrcComment(
std::string_view const _arguments,
langutil::SourceLocation const& _commentLocation
)
{
static regex const argsRegex = regex(
static std::regex const argsRegex = std::regex(
R"~~(^(-1|\d+):(-1|\d+):(-1|\d+)(?:\s+|$))~~" // index and location, e.g.: 1:234:-1
R"~~(("(?:[^"\\]|\\.)*"?)?)~~", // optional code snippet, e.g.: "string memory s = \"abc\";..."
regex_constants::ECMAScript | regex_constants::optimize
std::regex_constants::ECMAScript | std::regex_constants::optimize
);
match_results<string_view::const_iterator> match;
std::match_results<std::string_view::const_iterator> match;
if (!regex_search(_arguments.cbegin(), _arguments.cend(), match, argsRegex))
{
m_errorReporter.syntaxError(
@ -204,11 +203,11 @@ optional<pair<string_view, SourceLocation>> Parser::parseSrcComment(
_commentLocation,
"Invalid values in source location mapping. Could not parse location specification."
);
return nullopt;
return std::nullopt;
}
solAssert(match.size() == 5, "");
string_view tail = _arguments.substr(static_cast<size_t>(match.position() + match.length()));
std::string_view tail = _arguments.substr(static_cast<size_t>(match.position() + match.length()));
if (match[4].matched && (
!boost::algorithm::ends_with(match[4].str(), "\"") ||
@ -223,9 +222,9 @@ optional<pair<string_view, SourceLocation>> Parser::parseSrcComment(
return {{tail, SourceLocation{}}};
}
optional<int> const sourceIndex = toInt(match[1].str());
optional<int> const start = toInt(match[2].str());
optional<int> const end = toInt(match[3].str());
std::optional<int> const sourceIndex = toInt(match[1].str());
std::optional<int> const start = toInt(match[2].str());
std::optional<int> const end = toInt(match[3].str());
if (!sourceIndex.has_value() || !start.has_value() || !end.has_value())
m_errorReporter.syntaxError(
@ -244,26 +243,26 @@ optional<pair<string_view, SourceLocation>> Parser::parseSrcComment(
);
else
{
shared_ptr<string const> sourceName = m_sourceNames->at(static_cast<unsigned>(sourceIndex.value()));
std::shared_ptr<std::string const> sourceName = m_sourceNames->at(static_cast<unsigned>(sourceIndex.value()));
solAssert(sourceName, "");
return {{tail, SourceLocation{start.value(), end.value(), std::move(sourceName)}}};
}
return {{tail, SourceLocation{}}};
}
optional<pair<string_view, optional<int>>> Parser::parseASTIDComment(
string_view _arguments,
std::optional<std::pair<std::string_view, std::optional<int>>> Parser::parseASTIDComment(
std::string_view _arguments,
langutil::SourceLocation const& _commentLocation
)
{
static regex const argRegex = regex(
static std::regex const argRegex = std::regex(
R"~~(^(\d+)(?:\s|$))~~",
regex_constants::ECMAScript | regex_constants::optimize
std::regex_constants::ECMAScript | std::regex_constants::optimize
);
match_results<string_view::const_iterator> match;
optional<int> astID;
std::match_results<std::string_view::const_iterator> match;
std::optional<int> astID;
bool matched = regex_search(_arguments.cbegin(), _arguments.cend(), match, argRegex);
string_view tail = _arguments;
std::string_view tail = _arguments;
if (matched)
{
solAssert(match.size() == 2, "");
@ -275,12 +274,12 @@ optional<pair<string_view, optional<int>>> Parser::parseASTIDComment(
if (!matched || !astID || *astID < 0 || static_cast<int64_t>(*astID) != *astID)
{
m_errorReporter.syntaxError(1749_error, _commentLocation, "Invalid argument for @ast-id.");
astID = nullopt;
astID = std::nullopt;
}
if (matched)
return {{_arguments, astID}};
else
return nullopt;
return std::nullopt;
}
Block Parser::parseBlock()
@ -310,7 +309,7 @@ Statement Parser::parseStatement()
{
If _if = createWithLocation<If>();
advance();
_if.condition = make_unique<Expression>(parseExpression());
_if.condition = std::make_unique<Expression>(parseExpression());
_if.body = parseBlock();
updateLocationEndFrom(_if.debugData, nativeLocationOf(_if.body));
return Statement{std::move(_if)};
@ -319,7 +318,7 @@ Statement Parser::parseStatement()
{
Switch _switch = createWithLocation<Switch>();
advance();
_switch.expression = make_unique<Expression>(parseExpression());
_switch.expression = std::make_unique<Expression>(parseExpression());
while (currentToken() == Token::Case)
_switch.cases.emplace_back(parseCase());
if (currentToken() == Token::Default)
@ -364,7 +363,7 @@ Statement Parser::parseStatement()
// Options left:
// Expression/FunctionCall
// Assignment
variant<Literal, Identifier> elementary(parseLiteralOrIdentifier());
std::variant<Literal, Identifier> elementary(parseLiteralOrIdentifier());
switch (currentToken())
{
@ -381,7 +380,7 @@ Statement Parser::parseStatement()
while (true)
{
if (!holds_alternative<Identifier>(elementary))
if (!std::holds_alternative<Identifier>(elementary))
{
auto const token = currentToken() == Token::Comma ? "," : ":=";
@ -411,7 +410,7 @@ Statement Parser::parseStatement()
expectToken(Token::AssemblyAssign);
assignment.value = make_unique<Expression>(parseExpression());
assignment.value = std::make_unique<Expression>(parseExpression());
updateLocationEndFrom(assignment.debugData, nativeLocationOf(*assignment.value));
return Statement{std::move(assignment)};
@ -434,10 +433,10 @@ Case Parser::parseCase()
else if (currentToken() == Token::Case)
{
advance();
variant<Literal, Identifier> literal = parseLiteralOrIdentifier();
if (!holds_alternative<Literal>(literal))
std::variant<Literal, Identifier> literal = parseLiteralOrIdentifier();
if (!std::holds_alternative<Literal>(literal))
fatalParserError(4805_error, "Literal expected.");
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
_case.value = std::make_unique<Literal>(std::get<Literal>(std::move(literal)));
}
else
yulAssert(false, "Case or default case expected.");
@ -457,7 +456,7 @@ ForLoop Parser::parseForLoop()
m_currentForLoopComponent = ForLoopComponent::ForLoopPre;
forLoop.pre = parseBlock();
m_currentForLoopComponent = ForLoopComponent::None;
forLoop.condition = make_unique<Expression>(parseExpression());
forLoop.condition = std::make_unique<Expression>(parseExpression());
m_currentForLoopComponent = ForLoopComponent::ForLoopPost;
forLoop.post = parseBlock();
m_currentForLoopComponent = ForLoopComponent::ForLoopBody;
@ -473,7 +472,7 @@ Expression Parser::parseExpression()
{
RecursionGuard recursionGuard(*this);
variant<Literal, Identifier> operation = parseLiteralOrIdentifier();
std::variant<Literal, Identifier> operation = parseLiteralOrIdentifier();
return visit(GenericVisitor{
[&](Identifier& _identifier) -> Expression
{
@ -494,7 +493,7 @@ Expression Parser::parseExpression()
}, operation);
}
variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
std::variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
{
RecursionGuard recursionGuard(*this);
switch (currentToken())
@ -572,7 +571,7 @@ VariableDeclaration Parser::parseVariableDeclaration()
if (currentToken() == Token::AssemblyAssign)
{
expectToken(Token::AssemblyAssign);
varDecl.value = make_unique<Expression>(parseExpression());
varDecl.value = std::make_unique<Expression>(parseExpression());
updateLocationEndFrom(varDecl.debugData, nativeLocationOf(*varDecl.value));
}
else
@ -628,11 +627,11 @@ FunctionDefinition Parser::parseFunctionDefinition()
return funDef;
}
FunctionCall Parser::parseCall(variant<Literal, Identifier>&& _initialOp)
FunctionCall Parser::parseCall(std::variant<Literal, Identifier>&& _initialOp)
{
RecursionGuard recursionGuard(*this);
if (!holds_alternative<Identifier>(_initialOp))
if (!std::holds_alternative<Identifier>(_initialOp))
fatalParserError(9980_error, "Function name expected.");
FunctionCall ret;
@ -681,7 +680,7 @@ YulString Parser::expectAsmIdentifier()
return name;
}
void Parser::checkBreakContinuePosition(string const& _which)
void Parser::checkBreakContinuePosition(std::string const& _which)
{
switch (m_currentForLoopComponent)
{
@ -699,7 +698,7 @@ void Parser::checkBreakContinuePosition(string const& _which)
}
}
bool Parser::isValidNumberLiteral(string const& _literal)
bool Parser::isValidNumberLiteral(std::string const& _literal)
{
try
{
@ -713,5 +712,5 @@ bool Parser::isValidNumberLiteral(string const& _literal)
if (boost::starts_with(_literal, "0x"))
return true;
else
return _literal.find_first_not_of("0123456789") == string::npos;
return _literal.find_first_not_of("0123456789") == std::string::npos;
}

View File

@ -37,15 +37,14 @@
#include <memory>
#include <functional>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::util;
using namespace solidity::yul;
string AsmPrinter::operator()(Literal const& _literal)
std::string AsmPrinter::operator()(Literal const& _literal)
{
string const locationComment = formatDebugData(_literal);
std::string const locationComment = formatDebugData(_literal);
switch (_literal.kind)
{
@ -62,34 +61,34 @@ string AsmPrinter::operator()(Literal const& _literal)
return locationComment + escapeAndQuoteString(_literal.value.str()) + appendTypeName(_literal.type);
}
string AsmPrinter::operator()(Identifier const& _identifier)
std::string AsmPrinter::operator()(Identifier const& _identifier)
{
yulAssert(!_identifier.name.empty(), "Invalid identifier.");
return formatDebugData(_identifier) + _identifier.name.str();
}
string AsmPrinter::operator()(ExpressionStatement const& _statement)
std::string AsmPrinter::operator()(ExpressionStatement const& _statement)
{
string const locationComment = formatDebugData(_statement);
std::string const locationComment = formatDebugData(_statement);
return locationComment + std::visit(*this, _statement.expression);
}
string AsmPrinter::operator()(Assignment const& _assignment)
std::string AsmPrinter::operator()(Assignment const& _assignment)
{
string const locationComment = formatDebugData(_assignment);
std::string const locationComment = formatDebugData(_assignment);
yulAssert(_assignment.variableNames.size() >= 1, "");
string variables = (*this)(_assignment.variableNames.front());
std::string variables = (*this)(_assignment.variableNames.front());
for (size_t i = 1; i < _assignment.variableNames.size(); ++i)
variables += ", " + (*this)(_assignment.variableNames[i]);
return locationComment + variables + " := " + std::visit(*this, *_assignment.value);
}
string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
std::string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
{
string out = formatDebugData(_variableDeclaration);
std::string out = formatDebugData(_variableDeclaration);
out += "let ";
out += boost::algorithm::join(
@ -106,11 +105,11 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration)
return out;
}
string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
std::string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
{
yulAssert(!_functionDefinition.name.empty(), "Invalid function name.");
string out = formatDebugData(_functionDefinition);
std::string out = formatDebugData(_functionDefinition);
out += "function " + _functionDefinition.name.str() + "(";
out += boost::algorithm::join(
_functionDefinition.parameters | ranges::views::transform(
@ -133,10 +132,10 @@ string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition)
return out + "\n" + (*this)(_functionDefinition.body);
}
string AsmPrinter::operator()(FunctionCall const& _functionCall)
std::string AsmPrinter::operator()(FunctionCall const& _functionCall)
{
string const locationComment = formatDebugData(_functionCall);
string const functionName = (*this)(_functionCall.functionName);
std::string const locationComment = formatDebugData(_functionCall);
std::string const functionName = (*this)(_functionCall.functionName);
return
locationComment +
functionName + "(" +
@ -146,26 +145,26 @@ string AsmPrinter::operator()(FunctionCall const& _functionCall)
")";
}
string AsmPrinter::operator()(If const& _if)
std::string AsmPrinter::operator()(If const& _if)
{
yulAssert(_if.condition, "Invalid if condition.");
string out = formatDebugData(_if);
std::string out = formatDebugData(_if);
out += "if " + std::visit(*this, *_if.condition);
string body = (*this)(_if.body);
std::string body = (*this)(_if.body);
char delim = '\n';
if (body.find('\n') == string::npos)
if (body.find('\n') == std::string::npos)
delim = ' ';
return out + delim + body;
}
string AsmPrinter::operator()(Switch const& _switch)
std::string AsmPrinter::operator()(Switch const& _switch)
{
yulAssert(_switch.expression, "Invalid expression pointer.");
string out = formatDebugData(_switch);
std::string out = formatDebugData(_switch);
out += "switch " + std::visit(*this, *_switch.expression);
for (auto const& _case: _switch.cases)
@ -179,20 +178,20 @@ string AsmPrinter::operator()(Switch const& _switch)
return out;
}
string AsmPrinter::operator()(ForLoop const& _forLoop)
std::string AsmPrinter::operator()(ForLoop const& _forLoop)
{
yulAssert(_forLoop.condition, "Invalid for loop condition.");
string const locationComment = formatDebugData(_forLoop);
std::string const locationComment = formatDebugData(_forLoop);
string pre = (*this)(_forLoop.pre);
string condition = std::visit(*this, *_forLoop.condition);
string post = (*this)(_forLoop.post);
std::string pre = (*this)(_forLoop.pre);
std::string condition = std::visit(*this, *_forLoop.condition);
std::string post = (*this)(_forLoop.post);
char delim = '\n';
if (
pre.size() + condition.size() + post.size() < 60 &&
pre.find('\n') == string::npos &&
post.find('\n') == string::npos
pre.find('\n') == std::string::npos &&
post.find('\n') == std::string::npos
)
delim = ' ';
return
@ -201,33 +200,33 @@ string AsmPrinter::operator()(ForLoop const& _forLoop)
(*this)(_forLoop.body);
}
string AsmPrinter::operator()(Break const& _break)
std::string AsmPrinter::operator()(Break const& _break)
{
return formatDebugData(_break) + "break";
}
string AsmPrinter::operator()(Continue const& _continue)
std::string AsmPrinter::operator()(Continue const& _continue)
{
return formatDebugData(_continue) + "continue";
}
// '_leave' and '__leave' is reserved in VisualStudio
string AsmPrinter::operator()(Leave const& leave_)
std::string AsmPrinter::operator()(Leave const& leave_)
{
return formatDebugData(leave_) + "leave";
}
string AsmPrinter::operator()(Block const& _block)
std::string AsmPrinter::operator()(Block const& _block)
{
string const locationComment = formatDebugData(_block);
std::string const locationComment = formatDebugData(_block);
if (_block.statements.empty())
return locationComment + "{ }";
string body = boost::algorithm::join(
std::string body = boost::algorithm::join(
_block.statements | ranges::views::transform([&](auto&& _node) { return std::visit(*this, _node); }),
"\n"
);
if (body.size() < 30 && body.find('\n') == string::npos)
if (body.size() < 30 && body.find('\n') == std::string::npos)
return locationComment + "{ " + body + " }";
else
{
@ -236,13 +235,13 @@ string AsmPrinter::operator()(Block const& _block)
}
}
string AsmPrinter::formatTypedName(TypedName _variable)
std::string AsmPrinter::formatTypedName(TypedName _variable)
{
yulAssert(!_variable.name.empty(), "Invalid variable name.");
return formatDebugData(_variable) + _variable.name.str() + appendTypeName(_variable.type);
}
string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
std::string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
{
if (m_dialect && !_type.empty())
{
@ -258,9 +257,9 @@ string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
return ":" + _type.str();
}
string AsmPrinter::formatSourceLocation(
std::string AsmPrinter::formatSourceLocation(
SourceLocation const& _location,
map<string, unsigned> const& _nameToSourceIndex,
std::map<std::string, unsigned> const& _nameToSourceIndex,
DebugInfoSelection const& _debugInfoSelection,
CharStreamProvider const* _soliditySourceProvider
)
@ -272,11 +271,11 @@ string AsmPrinter::formatSourceLocation(
if (_debugInfoSelection.none())
return "";
string sourceIndex = "-1";
string solidityCodeSnippet = "";
std::string sourceIndex = "-1";
std::string solidityCodeSnippet = "";
if (_location.sourceName)
{
sourceIndex = to_string(_nameToSourceIndex.at(*_location.sourceName));
sourceIndex = std::to_string(_nameToSourceIndex.at(*_location.sourceName));
if (
_debugInfoSelection.snippet &&
@ -295,26 +294,26 @@ string AsmPrinter::formatSourceLocation(
}
}
string sourceLocation =
std::string sourceLocation =
"@src " +
sourceIndex +
":" +
to_string(_location.start) +
std::to_string(_location.start) +
":" +
to_string(_location.end);
std::to_string(_location.end);
return sourceLocation + (solidityCodeSnippet.empty() ? "" : " ") + solidityCodeSnippet;
}
string AsmPrinter::formatDebugData(shared_ptr<DebugData const> const& _debugData, bool _statement)
std::string AsmPrinter::formatDebugData(std::shared_ptr<DebugData const> const& _debugData, bool _statement)
{
if (!_debugData || m_debugInfoSelection.none())
return "";
vector<string> items;
std::vector<std::string> items;
if (auto id = _debugData->astID)
if (m_debugInfoSelection.astID)
items.emplace_back("@ast-id " + to_string(*id));
items.emplace_back("@ast-id " + std::to_string(*id));
if (
m_lastLocation != _debugData->originLocation &&
@ -331,7 +330,7 @@ string AsmPrinter::formatDebugData(shared_ptr<DebugData const> const& _debugData
));
}
string commentBody = joinHumanReadable(items, " ");
std::string commentBody = joinHumanReadable(items, " ");
if (commentBody.empty())
return "";
else

View File

@ -26,7 +26,6 @@
#include <libyul/backends/evm/EVMCodeTransform.h>
#include <libyul/backends/evm/NoOutputAssembly.h>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;

View File

@ -30,7 +30,6 @@
#include <range/v3/view/reverse.hpp>
#include <range/v3/algorithm/find_if.hpp>
using namespace std;
using namespace solidity::yul;
@ -162,7 +161,7 @@ void ControlFlowBuilder::newConnectedNode()
ControlFlowNode* ControlFlowBuilder::newNode()
{
m_nodes.emplace_back(make_shared<ControlFlowNode>());
m_nodes.emplace_back(std::make_shared<ControlFlowNode>());
return m_nodes.back().get();
}
@ -230,9 +229,9 @@ ControlFlowSideEffectsCollector::ControlFlowSideEffectsCollector(
}
}
map<YulString, ControlFlowSideEffects> ControlFlowSideEffectsCollector::functionSideEffectsNamed() const
std::map<YulString, ControlFlowSideEffects> ControlFlowSideEffectsCollector::functionSideEffectsNamed() const
{
map<YulString, ControlFlowSideEffects> result;
std::map<YulString, ControlFlowSideEffects> result;
for (auto&& [function, sideEffects]: m_functionSideEffects)
yulAssert(result.insert({function->name, sideEffects}).second);
return result;

View File

@ -23,7 +23,6 @@
#include <libyul/AST.h>
using namespace solidity::yul;
using namespace std;
using namespace solidity::langutil;
Literal Dialect::zeroLiteralForType(solidity::yul::YulString _type) const
@ -52,13 +51,13 @@ bool Dialect::validTypeForLiteral(LiteralKind _kind, YulString, YulString _type)
Dialect const& Dialect::yulDeprecated()
{
static unique_ptr<Dialect> dialect;
static std::unique_ptr<Dialect> dialect;
static YulStringRepository::ResetCallback callback{[&] { dialect.reset(); }};
if (!dialect)
{
// TODO will probably change, especially the list of types.
dialect = make_unique<Dialect>();
dialect = std::make_unique<Dialect>();
dialect->defaultType = "u256"_yulstring;
dialect->boolType = "bool"_yulstring;
dialect->types = {

View File

@ -23,7 +23,6 @@
#include <range/v3/view/reverse.hpp>
using namespace std;
using namespace solidity::yul;
using namespace solidity::util;
@ -51,7 +50,7 @@ void FunctionReferenceResolver::operator()(Block const& _block)
{
m_scopes.emplace_back();
for (auto const& statement: _block.statements)
if (auto const* function = get_if<FunctionDefinition>(&statement))
if (auto const* function = std::get_if<FunctionDefinition>(&statement))
m_scopes.back()[function->name] = function;
ASTWalker::operator()(_block);

View File

@ -35,7 +35,6 @@
#include <range/v3/view/transform.hpp>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::util;
@ -44,7 +43,7 @@ using namespace solidity::yul;
namespace
{
string indent(std::string const& _input)
std::string indent(std::string const& _input)
{
if (_input.empty())
return _input;
@ -53,12 +52,12 @@ string indent(std::string const& _input)
}
string Data::toString(Dialect const*, DebugInfoSelection const&, CharStreamProvider const*) const
std::string Data::toString(Dialect const*, DebugInfoSelection const&, CharStreamProvider const*) const
{
return "data \"" + name.str() + "\" hex\"" + util::toHex(data) + "\"";
}
string Object::toString(
std::string Object::toString(
Dialect const* _dialect,
DebugInfoSelection const& _debugInfoSelection,
CharStreamProvider const* _soliditySourceProvider
@ -67,17 +66,17 @@ string Object::toString(
yulAssert(code, "No code");
yulAssert(debugData, "No debug data");
string useSrcComment;
std::string useSrcComment;
if (debugData->sourceNames)
useSrcComment =
"/// @use-src " +
joinHumanReadable(ranges::views::transform(*debugData->sourceNames, [](auto&& _pair) {
return to_string(_pair.first) + ":" + util::escapeAndQuoteString(*_pair.second);
return std::to_string(_pair.first) + ":" + util::escapeAndQuoteString(*_pair.second);
})) +
"\n";
string inner = "code " + AsmPrinter(
std::string inner = "code " + AsmPrinter(
_dialect,
debugData->sourceNames,
_debugInfoSelection,
@ -107,7 +106,7 @@ Json::Value Object::toJson() const
codeJson["block"] = AsmJsonConverter(0 /* sourceIndex */)(*code);
Json::Value subObjectsJson{Json::arrayValue};
for (shared_ptr<ObjectNode> const& subObject: subObjects)
for (std::shared_ptr<ObjectNode> const& subObject: subObjects)
subObjectsJson.append(subObject->toJson());
Json::Value ret{Json::objectValue};
@ -118,13 +117,13 @@ Json::Value Object::toJson() const
return ret;
}
set<YulString> Object::qualifiedDataNames() const
std::set<YulString> Object::qualifiedDataNames() const
{
set<YulString> qualifiedNames =
std::set<YulString> qualifiedNames =
name.empty() || util::contains(name.str(), '.') ?
set<YulString>{} :
set<YulString>{name};
for (shared_ptr<ObjectNode> const& subObjectNode: subObjects)
std::set<YulString>{} :
std::set<YulString>{name};
for (std::shared_ptr<ObjectNode> const& subObjectNode: subObjects)
{
yulAssert(qualifiedNames.count(subObjectNode->name) == 0, "");
if (util::contains(subObjectNode->name.str(), '.'))
@ -144,7 +143,7 @@ set<YulString> Object::qualifiedDataNames() const
return qualifiedNames;
}
vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
std::vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
{
yulAssert(_qualifiedName != name, "");
yulAssert(subIndexByName.count(name) == 0, "");
@ -153,12 +152,12 @@ vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
_qualifiedName = YulString{_qualifiedName.str().substr(name.str().length() + 1)};
yulAssert(!_qualifiedName.empty(), "");
vector<string> subObjectPathComponents;
std::vector<std::string> subObjectPathComponents;
boost::algorithm::split(subObjectPathComponents, _qualifiedName.str(), boost::is_any_of("."));
vector<size_t> path;
std::vector<size_t> path;
Object const* object = this;
for (string const& currentSubObjectName: subObjectPathComponents)
for (std::string const& currentSubObjectName: subObjectPathComponents)
{
yulAssert(!currentSubObjectName.empty(), "");
auto subIndexIt = object->subIndexByName.find(YulString{currentSubObjectName});
@ -168,7 +167,7 @@ vector<size_t> Object::pathToSubObject(YulString _qualifiedName) const
);
object = dynamic_cast<Object const*>(object->subObjects[subIndexIt->second].get());
yulAssert(object, "Assembly object <" + _qualifiedName.str() + "> not found or does not contain code.");
yulAssert(object->subId != numeric_limits<size_t>::max(), "");
yulAssert(object->subId != std::numeric_limits<size_t>::max(), "");
path.push_back({object->subId});
}

View File

@ -32,27 +32,26 @@
#include <regex>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
using namespace solidity::langutil;
shared_ptr<Object> ObjectParser::parse(shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
std::shared_ptr<Object> ObjectParser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
{
m_recursionDepth = 0;
try
{
shared_ptr<Object> object;
std::shared_ptr<Object> object;
m_scanner = _scanner;
if (currentToken() == Token::LBrace)
{
// Special case: Code-only form.
object = make_shared<Object>();
object = std::make_shared<Object>();
object->name = "object"_yulstring;
auto sourceNameMapping = tryParseSourceNameMapping();
object->debugData = make_shared<ObjectDebugData>(ObjectDebugData{sourceNameMapping});
object->debugData = std::make_shared<ObjectDebugData>(ObjectDebugData{sourceNameMapping});
object->code = parseBlock(sourceNameMapping);
if (!object->code)
return nullptr;
@ -71,14 +70,14 @@ shared_ptr<Object> ObjectParser::parse(shared_ptr<Scanner> const& _scanner, bool
return nullptr;
}
shared_ptr<Object> ObjectParser::parseObject(Object* _containingObject)
std::shared_ptr<Object> ObjectParser::parseObject(Object* _containingObject)
{
RecursionGuard guard(*this);
shared_ptr<Object> ret = make_shared<Object>();
std::shared_ptr<Object> ret = std::make_shared<Object>();
auto sourceNameMapping = tryParseSourceNameMapping();
ret->debugData = make_shared<ObjectDebugData>(ObjectDebugData{sourceNameMapping});
ret->debugData = std::make_shared<ObjectDebugData>(ObjectDebugData{sourceNameMapping});
if (currentToken() != Token::Identifier || currentLiteral() != "object")
fatalParserError(4294_error, "Expected keyword \"object\".");
@ -107,7 +106,7 @@ shared_ptr<Object> ObjectParser::parseObject(Object* _containingObject)
return ret;
}
shared_ptr<Block> ObjectParser::parseCode(optional<SourceNameMap> _sourceNames)
std::shared_ptr<Block> ObjectParser::parseCode(std::optional<SourceNameMap> _sourceNames)
{
if (currentToken() != Token::Identifier || currentLiteral() != "code")
fatalParserError(4846_error, "Expected keyword \"code\".");
@ -116,7 +115,7 @@ shared_ptr<Block> ObjectParser::parseCode(optional<SourceNameMap> _sourceNames)
return parseBlock(std::move(_sourceNames));
}
optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
std::optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
{
// @use-src 0:"abc.sol", 1:"foo.sol", 2:"bar.sol"
//
@ -131,7 +130,7 @@ optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
);
std::smatch sm;
if (!std::regex_search(m_scanner->currentCommentLiteral(), sm, lineRE))
return nullopt;
return std::nullopt;
solAssert(sm.size() == 2, "");
auto text = m_scanner->currentCommentLiteral().substr(static_cast<size_t>(sm.position() + sm.length()));
@ -152,7 +151,7 @@ optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
break;
if (scanner.next() != Token::StringLiteral)
break;
sourceNames[*sourceIndex] = make_shared<string const>(scanner.currentLiteral());
sourceNames[*sourceIndex] = std::make_shared<std::string const>(scanner.currentLiteral());
Token const next = scanner.next();
if (next == Token::EOS)
@ -167,13 +166,13 @@ optional<SourceNameMap> ObjectParser::tryParseSourceNameMapping() const
m_scanner->currentCommentLocation(),
"Error parsing arguments to @use-src. Expected: <number> \":\" \"<filename>\", ..."
);
return nullopt;
return std::nullopt;
}
shared_ptr<Block> ObjectParser::parseBlock(optional<SourceNameMap> _sourceNames)
std::shared_ptr<Block> ObjectParser::parseBlock(std::optional<SourceNameMap> _sourceNames)
{
Parser parser(m_errorReporter, m_dialect, std::move(_sourceNames));
shared_ptr<Block> block = parser.parseInline(m_scanner);
std::shared_ptr<Block> block = parser.parseInline(m_scanner);
yulAssert(block || m_errorReporter.hasErrors(), "Invalid block but no error!");
return block;
}
@ -192,7 +191,7 @@ void ObjectParser::parseData(Object& _containingObject)
expectToken(Token::HexStringLiteral, false);
else
expectToken(Token::StringLiteral, false);
addNamedSubObject(_containingObject, name, make_shared<Data>(name, asBytes(currentLiteral())));
addNamedSubObject(_containingObject, name, std::make_shared<Data>(name, asBytes(currentLiteral())));
advance();
}
@ -210,7 +209,7 @@ YulString ObjectParser::parseUniqueName(Object const* _containingObject)
return name;
}
void ObjectParser::addNamedSubObject(Object& _container, YulString _name, shared_ptr<ObjectNode> _subObject)
void ObjectParser::addNamedSubObject(Object& _container, YulString _name, std::shared_ptr<ObjectNode> _subObject)
{
_container.subIndexByName[_name] = _container.subObjects.size();
_container.subObjects.emplace_back(std::move(_subObject));

View File

@ -21,7 +21,6 @@
#include <libyul/Scope.h>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
@ -53,7 +52,7 @@ Scope::Identifier* Scope::lookup(YulString _name)
auto id = s->identifiers.find(_name);
if (id != s->identifiers.end())
{
if (crossedFunctionBoundary && holds_alternative<Scope::Variable>(id->second))
if (crossedFunctionBoundary && std::holds_alternative<Scope::Variable>(id->second))
return nullptr;
else
return &id->second;
@ -79,7 +78,7 @@ size_t Scope::numberOfVariables() const
{
size_t count = 0;
for (auto const& identifier: identifiers)
if (holds_alternative<Scope::Variable>(identifier.second))
if (std::holds_alternative<Scope::Variable>(identifier.second))
count++;
return count;
}

View File

@ -33,7 +33,6 @@
#include <memory>
#include <functional>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
@ -60,7 +59,7 @@ bool ScopeFiller::operator()(VariableDeclaration const& _varDecl)
bool ScopeFiller::operator()(FunctionDefinition const& _funDef)
{
auto virtualBlock = m_info.virtualBlocks[&_funDef] = make_shared<Block>();
auto virtualBlock = m_info.virtualBlocks[&_funDef] = std::make_shared<Block>();
Scope& varScope = scope(virtualBlock.get());
varScope.superScope = m_currentScope;
m_currentScope = &varScope;
@ -123,7 +122,7 @@ bool ScopeFiller::operator()(Block const& _block)
// First visit all functions to make them create
// an entry in the scope according to their visibility.
for (auto const& s: _block.statements)
if (holds_alternative<FunctionDefinition>(s))
if (std::holds_alternative<FunctionDefinition>(s))
if (!registerFunction(std::get<FunctionDefinition>(s)))
success = false;
for (auto const& s: _block.statements)
@ -151,10 +150,10 @@ bool ScopeFiller::registerVariable(TypedName const& _name, SourceLocation const&
bool ScopeFiller::registerFunction(FunctionDefinition const& _funDef)
{
vector<Scope::YulType> parameters;
std::vector<Scope::YulType> parameters;
for (auto const& parameter: _funDef.parameters)
parameters.emplace_back(parameter.type);
vector<Scope::YulType> returns;
std::vector<Scope::YulType> returns;
for (auto const& returnVariable: _funDef.returnVariables)
returns.emplace_back(returnVariable.type);
if (!m_currentScope->registerFunction(_funDef.name, std::move(parameters), std::move(returns)))
@ -174,6 +173,6 @@ Scope& ScopeFiller::scope(Block const* _block)
{
auto& scope = m_info.scopes[_block];
if (!scope)
scope = make_shared<Scope>();
scope = std::make_shared<Scope>();
return *scope;
}

View File

@ -33,16 +33,15 @@
#include <sstream>
#include <vector>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::util;
string solidity::yul::reindent(string const& _code)
std::string solidity::yul::reindent(std::string const& _code)
{
int constexpr indentationWidth = 4;
auto constexpr static countBraces = [](string const& _s) noexcept -> int
auto constexpr static countBraces = [](std::string const& _s) noexcept -> int
{
auto const i = _s.find("//");
auto const e = i == _s.npos ? end(_s) : next(begin(_s), static_cast<ptrdiff_t>(i));
@ -51,22 +50,22 @@ string solidity::yul::reindent(string const& _code)
return int(opening - closing);
};
vector<string> lines;
std::vector<std::string> lines;
boost::split(lines, _code, boost::is_any_of("\n"));
for (string& line: lines)
for (std::string& line: lines)
boost::trim(line);
// Reduce multiple consecutive empty lines.
lines = fold(lines, vector<string>{}, [](auto&& _lines, auto&& _line) {
lines = fold(lines, std::vector<std::string>{}, [](auto&& _lines, auto&& _line) {
if (!(_line.empty() && !_lines.empty() && _lines.back().empty()))
_lines.emplace_back(std::move(_line));
return std::move(_lines);
});
stringstream out;
std::stringstream out;
int depth = 0;
for (string const& line: lines)
for (std::string const& line: lines)
{
int const diff = countBraces(line);
if (diff < 0)
@ -91,7 +90,7 @@ u256 solidity::yul::valueOfNumberLiteral(Literal const& _literal)
{
yulAssert(_literal.kind == LiteralKind::Number, "Expected number literal!");
static map<YulString, u256> numberCache;
static std::map<YulString, u256> numberCache;
static YulStringRepository::ResetCallback callback{[&] { numberCache.clear(); }};
auto&& [it, isNew] = numberCache.try_emplace(_literal.value, 0);

View File

@ -39,7 +39,6 @@
#include <optional>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::langutil;
@ -63,7 +62,7 @@ Dialect const& languageToDialect(YulStack::Language _language, EVMVersion _versi
}
CharStream const& YulStack::charStream(string const& _sourceName) const
CharStream const& YulStack::charStream(std::string const& _sourceName) const
{
yulAssert(m_charStream, "");
yulAssert(m_charStream->name() == _sourceName, "");
@ -74,8 +73,8 @@ bool YulStack::parseAndAnalyze(std::string const& _sourceName, std::string const
{
m_errors.clear();
m_analysisSuccessful = false;
m_charStream = make_unique<CharStream>(_source, _sourceName);
shared_ptr<Scanner> scanner = make_shared<Scanner>(*m_charStream);
m_charStream = std::make_unique<CharStream>(_source, _sourceName);
std::shared_ptr<Scanner> scanner = std::make_shared<Scanner>(*m_charStream);
m_parserResult = ObjectParser(m_errorReporter, languageToDialect(m_language, m_evmVersion)).parse(scanner, false);
if (!m_errorReporter.errors().empty())
return false;
@ -112,7 +111,7 @@ bool YulStack::analyzeParsed()
bool YulStack::analyzeParsed(Object& _object)
{
yulAssert(_object.code, "");
_object.analysisInfo = make_shared<AsmAnalysisInfo>();
_object.analysisInfo = std::make_shared<AsmAnalysisInfo>();
AsmAnalyzer analyzer(
*_object.analysisInfo,
@ -161,9 +160,9 @@ void YulStack::optimize(Object& _object, bool _isCreation)
}
Dialect const& dialect = languageToDialect(m_language, m_evmVersion);
unique_ptr<GasMeter> meter;
std::unique_ptr<GasMeter> meter;
if (EVMDialect const* evmDialect = dynamic_cast<EVMDialect const*>(&dialect))
meter = make_unique<GasMeter>(*evmDialect, _isCreation, m_optimiserSettings.expectedExecutionsPerDeployment);
meter = std::make_unique<GasMeter>(*evmDialect, _isCreation, m_optimiserSettings.expectedExecutionsPerDeployment);
OptimiserSuite::run(
dialect,
@ -173,7 +172,7 @@ void YulStack::optimize(Object& _object, bool _isCreation)
m_optimiserSettings.runYulOptimiser ? m_optimiserSettings.optimizeStackAllocation : true,
m_optimiserSettings.runYulOptimiser ? m_optimiserSettings.yulOptimiserSteps : "u",
m_optimiserSettings.runYulOptimiser ? m_optimiserSettings.yulOptimiserCleanupSteps : "",
_isCreation ? nullopt : make_optional(m_optimiserSettings.expectedExecutionsPerDeployment),
_isCreation ? std::nullopt : std::make_optional(m_optimiserSettings.expectedExecutionsPerDeployment),
{}
);
}
@ -195,17 +194,17 @@ MachineAssemblyObject YulStack::assemble(Machine _machine) const
}
std::pair<MachineAssemblyObject, MachineAssemblyObject>
YulStack::assembleWithDeployed(optional<string_view> _deployName) const
YulStack::assembleWithDeployed(std::optional<std::string_view> _deployName) const
{
auto [creationAssembly, deployedAssembly] = assembleEVMWithDeployed(_deployName);
yulAssert(creationAssembly, "");
yulAssert(m_charStream, "");
MachineAssemblyObject creationObject;
creationObject.bytecode = make_shared<evmasm::LinkerObject>(creationAssembly->assemble());
creationObject.bytecode = std::make_shared<evmasm::LinkerObject>(creationAssembly->assemble());
yulAssert(creationObject.bytecode->immutableReferences.empty(), "Leftover immutables.");
creationObject.assembly = creationAssembly->assemblyString(m_debugInfoSelection);
creationObject.sourceMappings = make_unique<string>(
creationObject.sourceMappings = std::make_unique<std::string>(
evmasm::AssemblyItem::computeSourceMapping(
creationAssembly->items(),
{{m_charStream->name(), 0}}
@ -215,9 +214,9 @@ YulStack::assembleWithDeployed(optional<string_view> _deployName) const
MachineAssemblyObject deployedObject;
if (deployedAssembly)
{
deployedObject.bytecode = make_shared<evmasm::LinkerObject>(deployedAssembly->assemble());
deployedObject.bytecode = std::make_shared<evmasm::LinkerObject>(deployedAssembly->assemble());
deployedObject.assembly = deployedAssembly->assemblyString(m_debugInfoSelection);
deployedObject.sourceMappings = make_unique<string>(
deployedObject.sourceMappings = std::make_unique<std::string>(
evmasm::AssemblyItem::computeSourceMapping(
deployedAssembly->items(),
{{m_charStream->name(), 0}}
@ -229,7 +228,7 @@ YulStack::assembleWithDeployed(optional<string_view> _deployName) const
}
std::pair<std::shared_ptr<evmasm::Assembly>, std::shared_ptr<evmasm::Assembly>>
YulStack::assembleEVMWithDeployed(optional<string_view> _deployName) const
YulStack::assembleEVMWithDeployed(std::optional<std::string_view> _deployName) const
{
yulAssert(m_analysisSuccessful, "");
yulAssert(m_parserResult, "");
@ -250,7 +249,7 @@ YulStack::assembleEVMWithDeployed(optional<string_view> _deployName) const
assembly.optimise(evmasm::Assembly::OptimiserSettings::translateSettings(m_optimiserSettings, m_evmVersion));
optional<size_t> subIndex;
std::optional<size_t> subIndex;
// Pick matching assembly if name was given
if (_deployName.has_value())
@ -271,13 +270,13 @@ YulStack::assembleEVMWithDeployed(optional<string_view> _deployName) const
if (subIndex.has_value())
{
evmasm::Assembly& runtimeAssembly = assembly.sub(*subIndex);
return {make_shared<evmasm::Assembly>(assembly), make_shared<evmasm::Assembly>(runtimeAssembly)};
return {std::make_shared<evmasm::Assembly>(assembly), std::make_shared<evmasm::Assembly>(runtimeAssembly)};
}
return {make_shared<evmasm::Assembly>(assembly), {}};
return {std::make_shared<evmasm::Assembly>(assembly), {}};
}
string YulStack::print(
std::string YulStack::print(
CharStreamProvider const* _soliditySourceProvider
) const
{
@ -293,7 +292,7 @@ Json::Value YulStack::astJson() const
return m_parserResult->toJson();
}
shared_ptr<Object> YulStack::parserResult() const
std::shared_ptr<Object> YulStack::parserResult() const
{
yulAssert(m_analysisSuccessful, "Analysis was not successful.");
yulAssert(m_parserResult, "");

View File

@ -34,6 +34,7 @@ NAMESPACE_STD_FREE_FILES=(
libsolidity/lsp/*
libsolidity/parsing/*
libsolutil/*
libyul/*
libyul/backends/evm/*
libyul/optimiser/*
solc/*