/src/solidity/libyul/optimiser/BlockFlattener.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
19 | | #include <libyul/optimiser/BlockFlattener.h> |
20 | | #include <libyul/AST.h> |
21 | | |
22 | | #include <libsolutil/CommonData.h> |
23 | | |
24 | | #include <functional> |
25 | | |
26 | | using namespace std; |
27 | | using namespace solidity; |
28 | | using namespace solidity::yul; |
29 | | using namespace solidity::util; |
30 | | |
31 | | void BlockFlattener::operator()(Block& _block) |
32 | 0 | { |
33 | 0 | ASTModifier::operator()(_block); |
34 | |
|
35 | 0 | iterateReplacing( |
36 | 0 | _block.statements, |
37 | 0 | [](Statement& _s) -> std::optional<vector<Statement>> |
38 | 0 | { |
39 | 0 | if (holds_alternative<Block>(_s)) |
40 | 0 | return std::move(std::get<Block>(_s).statements); |
41 | 0 | else |
42 | 0 | return {}; |
43 | 0 | } |
44 | 0 | ); |
45 | 0 | } |
46 | | |
47 | | void BlockFlattener::run(OptimiserStepContext&, Block& _ast) |
48 | 0 | { |
49 | 0 | BlockFlattener flattener; |
50 | 0 | for (auto& statement: _ast.statements) |
51 | 0 | if (auto* block = get_if<Block>(&statement)) |
52 | 0 | flattener(*block); |
53 | 0 | else if (auto* function = get_if<FunctionDefinition>(&statement)) |
54 | 0 | flattener(function->body); |
55 | 0 | else |
56 | 0 | yulAssert(false, "BlockFlattener requires the FunctionGrouper."); |
57 | 0 | } |