/src/solidity/libyul/optimiser/FunctionHoister.h
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 | | /** |
19 | | * Optimiser component that changes the code so that all function definitions are at the top |
20 | | * level block. |
21 | | */ |
22 | | |
23 | | #pragma once |
24 | | |
25 | | #include <libyul/ASTForward.h> |
26 | | #include <libyul/optimiser/ASTWalker.h> |
27 | | |
28 | | namespace solidity::yul |
29 | | { |
30 | | struct OptimiserStepContext; |
31 | | |
32 | | /** |
33 | | * Moves all functions to the top-level scope. |
34 | | * Applying this transformation to source code that has ambiguous identifiers might |
35 | | * lead to invalid code. |
36 | | * |
37 | | * Prerequisites: Disambiguator |
38 | | */ |
39 | | class FunctionHoister: public ASTModifier |
40 | | { |
41 | | public: |
42 | | static constexpr char const* name{"FunctionHoister"}; |
43 | 138k | static void run(OptimiserStepContext&, Block& _ast) { FunctionHoister{}(_ast); } |
44 | | |
45 | | using ASTModifier::operator(); |
46 | | void operator()(Block& _block) override; |
47 | | |
48 | | private: |
49 | | FunctionHoister(); |
50 | | ~FunctionHoister() override; |
51 | | |
52 | | bool m_isTopLevel = true; |
53 | | std::vector<Statement> m_functions; |
54 | | }; |
55 | | |
56 | | } |