/src/solidity/libyul/optimiser/ASTWalker.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 | | /** |
19 | | * Generic AST walker. |
20 | | */ |
21 | | |
22 | | #include <libyul/optimiser/ASTWalker.h> |
23 | | |
24 | | #include <libyul/AST.h> |
25 | | |
26 | | #include <range/v3/view/reverse.hpp> |
27 | | |
28 | | using namespace solidity; |
29 | | using namespace solidity::yul; |
30 | | using namespace solidity::util; |
31 | | |
32 | | void ASTWalker::operator()(FunctionCall const& _funCall) |
33 | 670M | { |
34 | | // Does not visit _funCall.functionName on purpose |
35 | 670M | walkVector(_funCall.arguments | ranges::views::reverse); |
36 | 670M | } |
37 | | |
38 | | void ASTWalker::operator()(ExpressionStatement const& _statement) |
39 | 280M | { |
40 | 280M | visit(_statement.expression); |
41 | 280M | } |
42 | | |
43 | | void ASTWalker::operator()(Assignment const& _assignment) |
44 | 75.8M | { |
45 | 75.8M | for (auto const& name: _assignment.variableNames) |
46 | 75.8M | (*this)(name); |
47 | 75.8M | visit(*_assignment.value); |
48 | 75.8M | } |
49 | | |
50 | | void ASTWalker::operator()(VariableDeclaration const& _varDecl) |
51 | 1.15G | { |
52 | 1.15G | if (_varDecl.value) |
53 | 1.15G | visit(*_varDecl.value); |
54 | 1.15G | } |
55 | | |
56 | | void ASTWalker::operator()(If const& _if) |
57 | 31.0M | { |
58 | 31.0M | visit(*_if.condition); |
59 | 31.0M | (*this)(_if.body); |
60 | 31.0M | } |
61 | | |
62 | | void ASTWalker::operator()(Switch const& _switch) |
63 | 9.12M | { |
64 | 9.12M | visit(*_switch.expression); |
65 | 9.12M | for (auto const& _case: _switch.cases) |
66 | 25.4M | { |
67 | 25.4M | if (_case.value) |
68 | 18.7M | (*this)(*_case.value); |
69 | 25.4M | (*this)(_case.body); |
70 | 25.4M | } |
71 | 9.12M | } |
72 | | |
73 | | void ASTWalker::operator()(FunctionDefinition const& _fun) |
74 | 32.7M | { |
75 | 32.7M | (*this)(_fun.body); |
76 | 32.7M | } |
77 | | |
78 | | void ASTWalker::operator()(ForLoop const& _for) |
79 | 33.2M | { |
80 | 33.2M | (*this)(_for.pre); |
81 | 33.2M | visit(*_for.condition); |
82 | 33.2M | (*this)(_for.body); |
83 | 33.2M | (*this)(_for.post); |
84 | 33.2M | } |
85 | | |
86 | | void ASTWalker::operator()(Block const& _block) |
87 | 277M | { |
88 | 277M | walkVector(_block.statements); |
89 | 277M | } |
90 | | |
91 | | void ASTWalker::visit(Statement const& _st) |
92 | 1.74G | { |
93 | 1.74G | std::visit(*this, _st); |
94 | 1.74G | } |
95 | | |
96 | | void ASTWalker::visit(Expression const& _e) |
97 | 3.35G | { |
98 | 3.35G | std::visit(*this, _e); |
99 | 3.35G | } |
100 | | |
101 | | void ASTModifier::operator()(FunctionCall& _funCall) |
102 | 352M | { |
103 | | // Does not visit _funCall.functionName on purpose |
104 | 352M | walkVector(_funCall.arguments | ranges::views::reverse); |
105 | 352M | } |
106 | | |
107 | | void ASTModifier::operator()(ExpressionStatement& _statement) |
108 | 170M | { |
109 | 170M | visit(_statement.expression); |
110 | 170M | } |
111 | | |
112 | | void ASTModifier::operator()(Assignment& _assignment) |
113 | 31.7M | { |
114 | 31.7M | for (auto& name: _assignment.variableNames) |
115 | 31.8M | (*this)(name); |
116 | 31.7M | visit(*_assignment.value); |
117 | 31.7M | } |
118 | | |
119 | | void ASTModifier::operator()(VariableDeclaration& _varDecl) |
120 | 514M | { |
121 | 514M | if (_varDecl.value) |
122 | 514M | visit(*_varDecl.value); |
123 | 514M | } |
124 | | |
125 | | void ASTModifier::operator()(If& _if) |
126 | 19.3M | { |
127 | 19.3M | visit(*_if.condition); |
128 | 19.3M | (*this)(_if.body); |
129 | 19.3M | } |
130 | | |
131 | | void ASTModifier::operator()(Switch& _switch) |
132 | 3.26M | { |
133 | 3.26M | visit(*_switch.expression); |
134 | 3.26M | for (auto& _case: _switch.cases) |
135 | 9.92M | { |
136 | 9.92M | if (_case.value) |
137 | 7.51M | (*this)(*_case.value); |
138 | 9.92M | (*this)(_case.body); |
139 | 9.92M | } |
140 | 3.26M | } |
141 | | |
142 | | void ASTModifier::operator()(FunctionDefinition& _fun) |
143 | 27.3M | { |
144 | 27.3M | (*this)(_fun.body); |
145 | 27.3M | } |
146 | | |
147 | | void ASTModifier::operator()(ForLoop& _for) |
148 | 16.8M | { |
149 | 16.8M | (*this)(_for.pre); |
150 | 16.8M | visit(*_for.condition); |
151 | 16.8M | (*this)(_for.post); |
152 | 16.8M | (*this)(_for.body); |
153 | 16.8M | } |
154 | | |
155 | | void ASTModifier::operator()(Break&) |
156 | 8.51M | { |
157 | 8.51M | } |
158 | | |
159 | | void ASTModifier::operator()(Continue&) |
160 | 1.32M | { |
161 | 1.32M | } |
162 | | |
163 | | void ASTModifier::operator()(Leave&) |
164 | 4.42M | { |
165 | 4.42M | } |
166 | | |
167 | | void ASTModifier::operator()(Block& _block) |
168 | 96.8M | { |
169 | 96.8M | walkVector(_block.statements); |
170 | 96.8M | } |
171 | | |
172 | | void ASTModifier::visit(Statement& _st) |
173 | 1.01G | { |
174 | 1.01G | std::visit(*this, _st); |
175 | 1.01G | } |
176 | | |
177 | | void ASTModifier::visit(Expression& _e) |
178 | 1.64G | { |
179 | 1.64G | std::visit(*this, _e); |
180 | 1.64G | } |