| 91 | } |
| 92 | |
| 93 | void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements) |
| 94 | { |
| 95 | util::GenericVisitor visitor{ |
| 96 | util::VisitorFallback<OptionalStatements>{}, |
| 97 | [&](If& _ifStmt) -> OptionalStatements { |
| 98 | if (expressionAlwaysTrue(*_ifStmt.condition)) |
| 99 | return {std::move(_ifStmt.body.statements)}; |
| 100 | else if (expressionAlwaysFalse(*_ifStmt.condition)) |
| 101 | return {std::vector<Statement>{}}; |
| 102 | return {}; |
| 103 | }, |
| 104 | [&](Switch& _switchStmt) -> OptionalStatements { |
| 105 | if (std::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression)) |
| 106 | return replaceConstArgSwitch(_switchStmt, constExprVal.value()); |
| 107 | return {}; |
| 108 | }, |
| 109 | [&](ForLoop& _forLoop) -> OptionalStatements { |
| 110 | if (expressionAlwaysFalse(*_forLoop.condition)) |
| 111 | return {std::move(_forLoop.pre.statements)}; |
| 112 | return {}; |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | util::iterateReplacing( |
| 117 | _statements, |
| 118 | [&](Statement& _stmt) -> OptionalStatements |
| 119 | { |
| 120 | OptionalStatements result = std::visit(visitor, _stmt); |
| 121 | if (result) |
| 122 | simplify(*result); |
| 123 | else |
| 124 | visit(_stmt); |
| 125 | return result; |
| 126 | } |
| 127 | ); |
| 128 | } |
nothing calls this directly
no test coverage detected