MCPcopy Create free account
hub / github.com/argotorg/solidity / simplify

Method simplify

libyul/optimiser/ControlFlowSimplifier.cpp:134–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void ControlFlowSimplifier::simplify(std::vector<yul::Statement>& _statements)
135{
136 GenericVisitor visitor{
137 VisitorFallback<OptionalStatements>{},
138 [&](If& _ifStmt) -> OptionalStatements {
139 if (_ifStmt.body.statements.empty() && m_dialect.discardFunctionHandle())
140 {
141 OptionalStatements s = std::vector<Statement>{};
142 s->emplace_back(makeDiscardCall(
143 _ifStmt.debugData,
144 *m_dialect.discardFunctionHandle(),
145 std::move(*_ifStmt.condition)
146 ));
147 return s;
148 }
149 return {};
150 },
151 [&](Switch& _switchStmt) -> OptionalStatements {
152 removeEmptyDefaultFromSwitch(_switchStmt);
153 removeEmptyCasesFromSwitch(_switchStmt);
154
155 if (_switchStmt.cases.empty())
156 return reduceNoCaseSwitch(_switchStmt);
157 else if (_switchStmt.cases.size() == 1)
158 return reduceSingleCaseSwitch(_switchStmt);
159
160 return {};
161 }
162 };
163 iterateReplacing(
164 _statements,
165 [&](Statement& _stmt) -> OptionalStatements
166 {
167 OptionalStatements result = std::visit(visitor, _stmt);
168 if (result)
169 simplify(*result);
170 else
171 visit(_stmt);
172 return result;
173 }
174 );
175}
176
177OptionalStatements ControlFlowSimplifier::reduceNoCaseSwitch(Switch& _switchStmt) const
178{

Callers

nothing calls this directly

Calls 7

makeDiscardCallFunction · 0.85
iterateReplacingFunction · 0.85
emptyMethod · 0.45
discardFunctionHandleMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected