Coverage Report

Created: 2025-09-04 07:34

/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
609M
{
34
  // Does not visit _funCall.functionName on purpose
35
609M
  walkVector(_funCall.arguments | ranges::views::reverse);
36
609M
}
37
38
void ASTWalker::operator()(ExpressionStatement const& _statement)
39
239M
{
40
239M
  visit(_statement.expression);
41
239M
}
42
43
void ASTWalker::operator()(Assignment const& _assignment)
44
66.6M
{
45
66.6M
  for (auto const& name: _assignment.variableNames)
46
66.7M
    (*this)(name);
47
66.6M
  visit(*_assignment.value);
48
66.6M
}
49
50
void ASTWalker::operator()(VariableDeclaration const& _varDecl)
51
1.02G
{
52
1.02G
  if (_varDecl.value)
53
1.02G
    visit(*_varDecl.value);
54
1.02G
}
55
56
void ASTWalker::operator()(If const& _if)
57
28.0M
{
58
28.0M
  visit(*_if.condition);
59
28.0M
  (*this)(_if.body);
60
28.0M
}
61
62
void ASTWalker::operator()(Switch const& _switch)
63
9.26M
{
64
9.26M
  visit(*_switch.expression);
65
9.26M
  for (auto const& _case: _switch.cases)
66
25.3M
  {
67
25.3M
    if (_case.value)
68
18.6M
      (*this)(*_case.value);
69
25.3M
    (*this)(_case.body);
70
25.3M
  }
71
9.26M
}
72
73
void ASTWalker::operator()(FunctionDefinition const& _fun)
74
28.6M
{
75
28.6M
  (*this)(_fun.body);
76
28.6M
}
77
78
void ASTWalker::operator()(ForLoop const& _for)
79
26.3M
{
80
26.3M
  (*this)(_for.pre);
81
26.3M
  visit(*_for.condition);
82
26.3M
  (*this)(_for.body);
83
26.3M
  (*this)(_for.post);
84
26.3M
}
85
86
void ASTWalker::operator()(Block const& _block)
87
235M
{
88
235M
  walkVector(_block.statements);
89
235M
}
90
91
void ASTWalker::visit(Statement const& _st)
92
1.52G
{
93
1.52G
  std::visit(*this, _st);
94
1.52G
}
95
96
void ASTWalker::visit(Expression const& _e)
97
3.02G
{
98
3.02G
  std::visit(*this, _e);
99
3.02G
}
100
101
void ASTModifier::operator()(FunctionCall& _funCall)
102
307M
{
103
  // Does not visit _funCall.functionName on purpose
104
307M
  walkVector(_funCall.arguments | ranges::views::reverse);
105
307M
}
106
107
void ASTModifier::operator()(ExpressionStatement& _statement)
108
143M
{
109
143M
  visit(_statement.expression);
110
143M
}
111
112
void ASTModifier::operator()(Assignment& _assignment)
113
27.8M
{
114
27.8M
  for (auto& name: _assignment.variableNames)
115
27.8M
    (*this)(name);
116
27.8M
  visit(*_assignment.value);
117
27.8M
}
118
119
void ASTModifier::operator()(VariableDeclaration& _varDecl)
120
447M
{
121
447M
  if (_varDecl.value)
122
446M
    visit(*_varDecl.value);
123
447M
}
124
125
void ASTModifier::operator()(If& _if)
126
17.6M
{
127
17.6M
  visit(*_if.condition);
128
17.6M
  (*this)(_if.body);
129
17.6M
}
130
131
void ASTModifier::operator()(Switch& _switch)
132
3.09M
{
133
3.09M
  visit(*_switch.expression);
134
3.09M
  for (auto& _case: _switch.cases)
135
9.36M
  {
136
9.36M
    if (_case.value)
137
7.14M
      (*this)(*_case.value);
138
9.36M
    (*this)(_case.body);
139
9.36M
  }
140
3.09M
}
141
142
void ASTModifier::operator()(FunctionDefinition& _fun)
143
24.0M
{
144
24.0M
  (*this)(_fun.body);
145
24.0M
}
146
147
void ASTModifier::operator()(ForLoop& _for)
148
13.3M
{
149
13.3M
  (*this)(_for.pre);
150
13.3M
  visit(*_for.condition);
151
13.3M
  (*this)(_for.post);
152
13.3M
  (*this)(_for.body);
153
13.3M
}
154
155
void ASTModifier::operator()(Break&)
156
6.95M
{
157
6.95M
}
158
159
void ASTModifier::operator()(Continue&)
160
1.06M
{
161
1.06M
}
162
163
void ASTModifier::operator()(Leave&)
164
4.24M
{
165
4.24M
}
166
167
void ASTModifier::operator()(Block& _block)
168
81.9M
{
169
81.9M
  walkVector(_block.statements);
170
81.9M
}
171
172
void ASTModifier::visit(Statement& _st)
173
881M
{
174
881M
  std::visit(*this, _st);
175
881M
}
176
177
void ASTModifier::visit(Expression& _e)
178
1.43G
{
179
1.43G
  std::visit(*this, _e);
180
1.43G
}