Skip to content

Commit 925bfeb

Browse files
authored
Merge pull request ethereum#14513 from junaire/yul-backend-namespace-std
Purge using namespace std from libyul/backends
2 parents 37e1861 + 1ebdab4 commit 925bfeb

12 files changed

+152
-161
lines changed

libyul/backends/evm/AsmCodeGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include <libsolutil/StackTooDeepString.h>
3030

31-
using namespace std;
3231
using namespace solidity;
3332
using namespace solidity::yul;
3433
using namespace solidity::util;

libyul/backends/evm/ConstantOptimiser.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include <variant>
3232

33-
using namespace std;
3433
using namespace solidity;
3534
using namespace solidity::yul;
3635
using namespace solidity::util;
@@ -48,9 +47,9 @@ struct MiniEVMInterpreter
4847
return std::visit(*this, _expr);
4948
}
5049

51-
u256 eval(evmasm::Instruction _instr, vector<Expression> const& _arguments)
50+
u256 eval(evmasm::Instruction _instr, std::vector<Expression> const& _arguments)
5251
{
53-
vector<u256> args;
52+
std::vector<u256> args;
5453
for (auto const& arg: _arguments)
5554
args.emplace_back(eval(arg));
5655
switch (_instr)
@@ -92,7 +91,7 @@ struct MiniEVMInterpreter
9291

9392
void ConstantOptimiser::visit(Expression& _e)
9493
{
95-
if (holds_alternative<Literal>(_e))
94+
if (std::holds_alternative<Literal>(_e))
9695
{
9796
Literal const& literal = std::get<Literal>(_e);
9897
if (literal.kind != LiteralKind::Number)
@@ -115,7 +114,7 @@ Expression const* RepresentationFinder::tryFindRepresentation(u256 const& _value
115114
return nullptr;
116115

117116
Representation const& repr = findRepresentation(_value);
118-
if (holds_alternative<Literal>(*repr.expression))
117+
if (std::holds_alternative<Literal>(*repr.expression))
119118
return nullptr;
120119
else
121120
return repr.expression.get();
@@ -180,7 +179,7 @@ Representation const& RepresentationFinder::findRepresentation(u256 const& _valu
180179
Representation RepresentationFinder::represent(u256 const& _value) const
181180
{
182181
Representation repr;
183-
repr.expression = make_unique<Expression>(Literal{m_debugData, LiteralKind::Number, YulString{formatNumber(_value)}, {}});
182+
repr.expression = std::make_unique<Expression>(Literal{m_debugData, LiteralKind::Number, YulString{formatNumber(_value)}, {}});
184183
repr.cost = m_meter.costs(*repr.expression);
185184
return repr;
186185
}
@@ -191,7 +190,7 @@ Representation RepresentationFinder::represent(
191190
) const
192191
{
193192
Representation repr;
194-
repr.expression = make_unique<Expression>(FunctionCall{
193+
repr.expression = std::make_unique<Expression>(FunctionCall{
195194
m_debugData,
196195
Identifier{m_debugData, _instruction},
197196
{ASTCopier{}.translate(*_argument.expression)}
@@ -207,7 +206,7 @@ Representation RepresentationFinder::represent(
207206
) const
208207
{
209208
Representation repr;
210-
repr.expression = make_unique<Expression>(FunctionCall{
209+
repr.expression = std::make_unique<Expression>(FunctionCall{
211210
m_debugData,
212211
Identifier{m_debugData, _instruction},
213212
{ASTCopier{}.translate(*_arg1.expression), ASTCopier{}.translate(*_arg2.expression)}

libyul/backends/evm/ControlFlowGraphBuilder.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
using namespace solidity;
4747
using namespace solidity::yul;
48-
using namespace std;
4948

5049
namespace
5150
{
@@ -82,15 +81,15 @@ void cleanUnreachable(CFG& _cfg)
8281
/// Sets the ``recursive`` member to ``true`` for all recursive function calls.
8382
void markRecursiveCalls(CFG& _cfg)
8483
{
85-
map<CFG::BasicBlock*, vector<CFG::FunctionCall*>> callsPerBlock;
84+
std::map<CFG::BasicBlock*, std::vector<CFG::FunctionCall*>> callsPerBlock;
8685
auto const& findCalls = [&](CFG::BasicBlock* _block)
8786
{
8887
if (auto* calls = util::valueOrNullptr(callsPerBlock, _block))
8988
return *calls;
90-
vector<CFG::FunctionCall*>& calls = callsPerBlock[_block];
89+
std::vector<CFG::FunctionCall*>& calls = callsPerBlock[_block];
9190
util::BreadthFirstSearch<CFG::BasicBlock*>{{_block}}.run([&](CFG::BasicBlock* _block, auto _addChild) {
9291
for (auto& operation: _block->operations)
93-
if (auto* functionCall = get_if<CFG::FunctionCall>(&operation.operation))
92+
if (auto* functionCall = std::get_if<CFG::FunctionCall>(&operation.operation))
9493
calls.emplace_back(functionCall);
9594
std::visit(util::GenericVisitor{
9695
[&](CFG::BasicBlock::MainExit const&) {},
@@ -131,7 +130,7 @@ void markRecursiveCalls(CFG& _cfg)
131130
/// Entering such a block means that control flow will never return to a previously visited block.
132131
void markStartsOfSubGraphs(CFG& _cfg)
133132
{
134-
vector<CFG::BasicBlock*> entries;
133+
std::vector<CFG::BasicBlock*> entries;
135134
entries.emplace_back(_cfg.entry);
136135
for (auto&& functionInfo: _cfg.functionInfo | ranges::views::values)
137136
entries.emplace_back(functionInfo.entry);
@@ -141,17 +140,17 @@ void markStartsOfSubGraphs(CFG& _cfg)
141140
* Detect bridges following Algorithm 1 in https://arxiv.org/pdf/2108.07346.pdf
142141
* and mark the bridge targets as starts of sub-graphs.
143142
*/
144-
set<CFG::BasicBlock*> visited;
145-
map<CFG::BasicBlock*, size_t> disc;
146-
map<CFG::BasicBlock*, size_t> low;
147-
map<CFG::BasicBlock*, CFG::BasicBlock*> parent;
143+
std::set<CFG::BasicBlock*> visited;
144+
std::map<CFG::BasicBlock*, size_t> disc;
145+
std::map<CFG::BasicBlock*, size_t> low;
146+
std::map<CFG::BasicBlock*, CFG::BasicBlock*> parent;
148147
size_t time = 0;
149148
auto dfs = [&](CFG::BasicBlock* _u, auto _recurse) -> void {
150149
visited.insert(_u);
151150
disc[_u] = low[_u] = time;
152151
time++;
153152

154-
vector<CFG::BasicBlock*> children = _u->entries;
153+
std::vector<CFG::BasicBlock*> children = _u->entries;
155154
visit(util::GenericVisitor{
156155
[&](CFG::BasicBlock::Jump const& _jump) {
157156
children.emplace_back(_jump.target);
@@ -171,7 +170,7 @@ void markStartsOfSubGraphs(CFG& _cfg)
171170
{
172171
parent[v] = _u;
173172
_recurse(v, _recurse);
174-
low[_u] = min(low[_u], low[v]);
173+
low[_u] = std::min(low[_u], low[v]);
175174
if (low[v] > disc[_u])
176175
{
177176
// _u <-> v is a cut edge in the undirected graph
@@ -186,7 +185,7 @@ void markStartsOfSubGraphs(CFG& _cfg)
186185
}
187186
}
188187
else if (v != parent[_u])
189-
low[_u] = min(low[_u], disc[v]);
188+
low[_u] = std::min(low[_u], disc[v]);
190189
};
191190
dfs(entry, dfs);
192191
}
@@ -234,7 +233,7 @@ std::unique_ptr<CFG> ControlFlowGraphBuilder::build(
234233
ControlFlowGraphBuilder::ControlFlowGraphBuilder(
235234
CFG& _graph,
236235
AsmAnalysisInfo const& _analysisInfo,
237-
map<FunctionDefinition const*, ControlFlowSideEffects> const& _functionSideEffects,
236+
std::map<FunctionDefinition const*, ControlFlowSideEffects> const& _functionSideEffects,
238237
Dialect const& _dialect
239238
):
240239
m_graph(_graph),
@@ -271,7 +270,7 @@ void ControlFlowGraphBuilder::operator()(VariableDeclaration const& _varDecl)
271270
yulAssert(m_currentBlock, "");
272271
auto declaredVariables = _varDecl.variables | ranges::views::transform([&](TypedName const& _var) {
273272
return VariableSlot{lookupVariable(_var.name), _var.debugData};
274-
}) | ranges::to<vector<VariableSlot>>;
273+
}) | ranges::to<std::vector<VariableSlot>>;
275274
Stack input;
276275
if (_varDecl.value)
277276
input = visitAssignmentRightHandSide(*_varDecl.value, declaredVariables.size());
@@ -287,7 +286,7 @@ void ControlFlowGraphBuilder::operator()(Assignment const& _assignment)
287286
{
288287
auto assignedVariables = _assignment.variableNames | ranges::views::transform([&](Identifier const& _var) {
289288
return VariableSlot{lookupVariable(_var.name), _var.debugData};
290-
}) | ranges::to<vector<VariableSlot>>;
289+
}) | ranges::to<std::vector<VariableSlot>>;
291290

292291
Stack input = visitAssignmentRightHandSide(*_assignment.value, assignedVariables.size());
293292
yulAssert(m_currentBlock);
@@ -314,7 +313,7 @@ void ControlFlowGraphBuilder::operator()(Block const& _block)
314313
{
315314
ScopedSaveAndRestore saveScope(m_scope, m_info.scopes.at(&_block).get());
316315
for (auto const& statement: _block.statements)
317-
if (auto const* function = get_if<FunctionDefinition>(&statement))
316+
if (auto const* function = std::get_if<FunctionDefinition>(&statement))
318317
registerFunction(*function);
319318
for (auto const& statement: _block.statements)
320319
std::visit(*this, statement);
@@ -334,10 +333,10 @@ void ControlFlowGraphBuilder::operator()(If const& _if)
334333
void ControlFlowGraphBuilder::operator()(Switch const& _switch)
335334
{
336335
yulAssert(m_currentBlock, "");
337-
shared_ptr<DebugData const> preSwitchDebugData = debugDataOf(_switch);
336+
std::shared_ptr<DebugData const> preSwitchDebugData = debugDataOf(_switch);
338337

339338
auto ghostVariableId = m_graph.ghostVariables.size();
340-
YulString ghostVariableName("GHOST[" + to_string(ghostVariableId) + "]");
339+
YulString ghostVariableName("GHOST[" + std::to_string(ghostVariableId) + "]");
341340
auto& ghostVar = m_graph.ghostVariables.emplace_back(Scope::Variable{""_yulstring, ghostVariableName});
342341

343342
// Artificially generate:
@@ -394,12 +393,12 @@ void ControlFlowGraphBuilder::operator()(Switch const& _switch)
394393

395394
void ControlFlowGraphBuilder::operator()(ForLoop const& _loop)
396395
{
397-
shared_ptr<DebugData const> preLoopDebugData = debugDataOf(_loop);
396+
std::shared_ptr<DebugData const> preLoopDebugData = debugDataOf(_loop);
398397
ScopedSaveAndRestore scopeRestore(m_scope, m_info.scopes.at(&_loop.pre).get());
399398
(*this)(_loop.pre);
400399

401400
std::optional<bool> constantCondition;
402-
if (auto const* literalCondition = get_if<yul::Literal>(_loop.condition.get()))
401+
if (auto const* literalCondition = std::get_if<yul::Literal>(_loop.condition.get()))
403402
constantCondition = valueOfLiteral(*literalCondition) != 0;
404403

405404
CFG::BasicBlock& loopCondition = m_graph.makeBlock(debugDataOf(*_loop.condition));
@@ -497,13 +496,13 @@ void ControlFlowGraphBuilder::registerFunction(FunctionDefinition const& _functi
497496
std::get<Scope::Variable>(virtualFunctionScope->identifiers.at(_param.name)),
498497
_param.debugData
499498
};
500-
}) | ranges::to<vector>,
499+
}) | ranges::to<std::vector>,
501500
_functionDefinition.returnVariables | ranges::views::transform([&](auto const& _retVar) {
502501
return VariableSlot{
503502
std::get<Scope::Variable>(virtualFunctionScope->identifiers.at(_retVar.name)),
504503
_retVar.debugData
505504
};
506-
}) | ranges::to<vector>,
505+
}) | ranges::to<std::vector>,
507506
{},
508507
m_functionSideEffects.at(&_functionDefinition).canContinue
509508
})).second;
@@ -609,7 +608,7 @@ Scope::Variable const& ControlFlowGraphBuilder::lookupVariable(YulString _name)
609608
}
610609

611610
void ControlFlowGraphBuilder::makeConditionalJump(
612-
shared_ptr<DebugData const> _debugData,
611+
std::shared_ptr<DebugData const> _debugData,
613612
StackSlot _condition,
614613
CFG::BasicBlock& _nonZero,
615614
CFG::BasicBlock& _zero
@@ -628,7 +627,7 @@ void ControlFlowGraphBuilder::makeConditionalJump(
628627
}
629628

630629
void ControlFlowGraphBuilder::jump(
631-
shared_ptr<DebugData const> _debugData,
630+
std::shared_ptr<DebugData const> _debugData,
632631
CFG::BasicBlock& _target,
633632
bool backwards
634633
)

0 commit comments

Comments
 (0)