Adding vardecl optimization for boolean types

This commit is contained in:
Djordje Mijovic
2020-02-24 15:05:19 +01:00
committed by chriseth
parent e75cace78d
commit a52c9af5b9
7 changed files with 52 additions and 7 deletions
+8 -4
View File
@@ -20,6 +20,7 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/Visitor.h>
#include <libyul/Dialect.h>
using namespace std;
using namespace solidity;
@@ -32,14 +33,14 @@ void VarDeclInitializer::operator()(Block& _block)
using OptionalStatements = std::optional<vector<Statement>>;
util::GenericVisitor visitor{
util::VisitorFallback<OptionalStatements>{},
[](VariableDeclaration& _varDecl) -> OptionalStatements
[this](VariableDeclaration& _varDecl) -> OptionalStatements
{
if (_varDecl.value)
return {};
Literal zero{{}, LiteralKind::Number, YulString{"0"}, {}};
if (_varDecl.variables.size() == 1)
{
_varDecl.value = make_unique<Expression>(std::move(zero));
_varDecl.value = make_unique<Expression>(m_dialect.zeroLiteralForType(_varDecl.variables.front().type));
return {};
}
else
@@ -47,7 +48,10 @@ void VarDeclInitializer::operator()(Block& _block)
OptionalStatements ret{vector<Statement>{}};
langutil::SourceLocation loc{std::move(_varDecl.location)};
for (auto& var: _varDecl.variables)
ret->emplace_back(VariableDeclaration{loc, {std::move(var)}, make_unique<Expression>(zero)});
{
unique_ptr<Expression> expr = make_unique<Expression >(m_dialect.zeroLiteralForType(var.type));
ret->emplace_back(VariableDeclaration{loc, {std::move(var)}, std::move(expr)});
}
return ret;
}
}