MCPcopy Create free account
hub / github.com/argotorg/solidity / operator()

Method operator()

libyul/optimiser/VarDeclInitializer.cpp:29–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27using namespace solidity::yul;
28
29void VarDeclInitializer::operator()(Block& _block)
30{
31 ASTModifier::operator()(_block);
32
33 using OptionalStatements = std::optional<std::vector<Statement>>;
34 util::GenericVisitor visitor{
35 util::VisitorFallback<OptionalStatements>{},
36 [this](VariableDeclaration& _varDecl) -> OptionalStatements
37 {
38 if (_varDecl.value)
39 return {};
40
41 if (_varDecl.variables.size() == 1)
42 {
43 _varDecl.value = std::make_unique<Expression>(m_dialect.zeroLiteral());
44 return {};
45 }
46 else
47 {
48 OptionalStatements ret{std::vector<Statement>{}};
49 for (auto& var: _varDecl.variables)
50 {
51 std::unique_ptr<Expression> expr = std::make_unique<Expression>(m_dialect.zeroLiteral());
52 ret->emplace_back(VariableDeclaration{std::move(_varDecl.debugData), {std::move(var)}, std::move(expr)});
53 }
54 return ret;
55 }
56 }
57 };
58
59 util::iterateReplacing(_block.statements, [&](auto&& _statement) { return std::visit(visitor, _statement); });
60}

Callers

nothing calls this directly

Calls 3

iterateReplacingFunction · 0.85
zeroLiteralMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected