libyul: changing some AST members from shared_ptr<> to unique_ptr<>

* Some spaces look a little more verbose now, but that shouln't be a problem as it also should raise readability, too.
* This makes some use of return-value-optimizations also.
This commit is contained in:
Christian Parpart
2019-01-16 14:58:59 +01:00
parent 778b14de26
commit 065c3c87af
11 changed files with 68 additions and 50 deletions
+18 -8
View File
@@ -51,7 +51,11 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
GenericFallbackReturnsVisitor<OptionalStatements, If, Switch, ForLoop> const visitor(
[&](If& _ifStmt) -> OptionalStatements {
if (_ifStmt.body.statements.empty())
return {{makePopExpressionStatement(_ifStmt.location, std::move(*_ifStmt.condition))}};
{
OptionalStatements s = vector<Statement>{};
s->emplace_back(makePopExpressionStatement(_ifStmt.location, std::move(*_ifStmt.condition)));
return s;
}
if (expressionAlwaysTrue(*_ifStmt.condition))
return {std::move(_ifStmt.body.statements)};
else if (expressionAlwaysFalse(*_ifStmt.condition))
@@ -64,18 +68,24 @@ void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
auto& switchCase = _switchStmt.cases.front();
auto loc = locationOf(*_switchStmt.expression);
if (switchCase.value)
return {{If{
{
OptionalStatements s = vector<Statement>{};
s->emplace_back(If{
std::move(_switchStmt.location),
make_shared<Expression>(FunctionalInstruction{
make_unique<Expression>(FunctionalInstruction{
std::move(loc),
solidity::Instruction::EQ,
{std::move(*switchCase.value), std::move(*_switchStmt.expression)}
}), std::move(switchCase.body)}}};
}), std::move(switchCase.body)});
return s;
}
else
return {{
makePopExpressionStatement(loc, std::move(*_switchStmt.expression)),
std::move(switchCase.body)
}};
{
OptionalStatements s = vector<Statement>{};
s->emplace_back(makePopExpressionStatement(loc, std::move(*_switchStmt.expression)));
s->emplace_back(std::move(switchCase.body));
return s;
}
}
else
return {};