/src/solidity/libyul/optimiser/ForLoopInitRewriter.cpp
Line | Count | Source |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | #include <libyul/optimiser/ForLoopInitRewriter.h> |
19 | | #include <libyul/AST.h> |
20 | | |
21 | | #include <libsolutil/CommonData.h> |
22 | | |
23 | | #include <functional> |
24 | | |
25 | | using namespace solidity; |
26 | | using namespace solidity::yul; |
27 | | |
28 | | void ForLoopInitRewriter::operator()(Block& _block) |
29 | 1.17M | { |
30 | 1.17M | util::iterateReplacing( |
31 | 1.17M | _block.statements, |
32 | 1.17M | [&](Statement& _stmt) -> std::optional<std::vector<Statement>> |
33 | 2.79M | { |
34 | 2.79M | if (std::holds_alternative<ForLoop>(_stmt)) |
35 | 65.7k | { |
36 | 65.7k | auto& forLoop = std::get<ForLoop>(_stmt); |
37 | 65.7k | (*this)(forLoop.pre); |
38 | 65.7k | (*this)(forLoop.body); |
39 | 65.7k | (*this)(forLoop.post); |
40 | 65.7k | std::vector<Statement> rewrite; |
41 | 65.7k | swap(rewrite, forLoop.pre.statements); |
42 | 65.7k | rewrite.emplace_back(std::move(forLoop)); |
43 | 65.7k | return { std::move(rewrite) }; |
44 | 65.7k | } |
45 | 2.72M | else |
46 | 2.72M | { |
47 | 2.72M | visit(_stmt); |
48 | 2.72M | return {}; |
49 | 2.72M | } |
50 | 2.79M | } |
51 | 1.17M | ); |
52 | 1.17M | } |