| 132 | } |
| 133 | |
| 134 | void 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 | |
| 177 | OptionalStatements ControlFlowSimplifier::reduceNoCaseSwitch(Switch& _switchStmt) const |
| 178 | { |
nothing calls this directly
no test coverage detected