Coverage Report

Created: 2026-09-14 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
954M
{
34
  // Does not visit _funCall.functionName on purpose
35
954M
  walkVector(_funCall.arguments | ranges::views::reverse);
36
954M
}
37
38
void ASTWalker::operator()(ExpressionStatement const& _statement)
39
329M
{
40
329M
  visit(_statement.expression);
41
329M
}
42
43
void ASTWalker::operator()(Assignment const& _assignment)
44
86.7M
{
45
86.7M
  for (auto const& name: _assignment.variableNames)
46
86.8M
    (*this)(name);
47
86.7M
  visit(*_assignment.value);
48
86.7M
}
49
50
void ASTWalker::operator()(VariableDeclaration const& _varDecl)
51
1.57G
{
52
1.57G
  if (_varDecl.value)
53
1.56G
    visit(*_varDecl.value);
54
1.57G
}
55
56
void ASTWalker::operator()(If const& _if)
57
39.7M
{
58
39.7M
  visit(*_if.condition);
59
39.7M
  (*this)(_if.body);
60
39.7M
}
61
62
void ASTWalker::operator()(Switch const& _switch)
63
15.4M
{
64
15.4M
  visit(*_switch.expression);
65
15.4M
  for (auto const& _case: _switch.cases)
66
41.5M
  {
67
41.5M
    if (_case.value)
68
29.6M
      (*this)(*_case.value);
69
41.5M
    (*this)(_case.body);
70
41.5M
  }
71
15.4M
}
72
73
void ASTWalker::operator()(FunctionDefinition const& _fun)
74
38.2M
{
75
38.2M
  (*this)(_fun.body);
76
38.2M
}
77
78
void ASTWalker::operator()(ForLoop const& _for)
79
38.5M
{
80
38.5M
  (*this)(_for.pre);
81
38.5M
  visit(*_for.condition);
82
38.5M
  (*this)(_for.body);
83
38.5M
  (*this)(_for.post);
84
38.5M
}
85
86
void ASTWalker::operator()(Block const& _block)
87
346M
{
88
346M
  walkVector(_block.statements);
89
346M
}
90
91
void ASTWalker::visit(Statement const& _st)
92
2.28G
{
93
2.28G
  std::visit(*this, _st);
94
2.28G
}
95
96
void ASTWalker::visit(Expression const& _e)
97
4.74G
{
98
4.74G
  std::visit(*this, _e);
99
4.74G
}
100
101
void ASTModifier::operator()(FunctionCall& _funCall)
102
465M
{
103
  // Does not visit _funCall.functionName on purpose
104
465M
  walkVector(_funCall.arguments | ranges::views::reverse);
105
465M
}
106
107
void ASTModifier::operator()(ExpressionStatement& _statement)
108
198M
{
109
198M
  visit(_statement.expression);
110
198M
}
111
112
void ASTModifier::operator()(Assignment& _assignment)
113
34.3M
{
114
34.3M
  for (auto& name: _assignment.variableNames)
115
34.4M
    (*this)(name);
116
34.3M
  visit(*_assignment.value);
117
34.3M
}
118
119
void ASTModifier::operator()(VariableDeclaration& _varDecl)
120
683M
{
121
683M
  if (_varDecl.value)
122
683M
    visit(*_varDecl.value);
123
683M
}
124
125
void ASTModifier::operator()(If& _if)
126
23.2M
{
127
23.2M
  visit(*_if.condition);
128
23.2M
  (*this)(_if.body);
129
23.2M
}
130
131
void ASTModifier::operator()(Switch& _switch)
132
5.30M
{
133
5.30M
  visit(*_switch.expression);
134
5.30M
  for (auto& _case: _switch.cases)
135
15.1M
  {
136
15.1M
    if (_case.value)
137
10.9M
      (*this)(*_case.value);
138
15.1M
    (*this)(_case.body);
139
15.1M
  }
140
5.30M
}
141
142
void ASTModifier::operator()(FunctionDefinition& _fun)
143
31.6M
{
144
31.6M
  (*this)(_fun.body);
145
31.6M
}
146
147
void ASTModifier::operator()(ForLoop& _for)
148
19.0M
{
149
19.0M
  (*this)(_for.pre);
150
19.0M
  visit(*_for.condition);
151
19.0M
  (*this)(_for.post);
152
19.0M
  (*this)(_for.body);
153
19.0M
}
154
155
void ASTModifier::operator()(Break&)
156
12.6M
{
157
12.6M
}
158
159
void ASTModifier::operator()(Continue&)
160
2.30M
{
161
2.30M
}
162
163
void ASTModifier::operator()(Leave&)
164
4.59M
{
165
4.59M
}
166
167
void ASTModifier::operator()(Block& _block)
168
118M
{
169
118M
  walkVector(_block.statements);
170
118M
}
171
172
void ASTModifier::visit(Statement& _st)
173
1.31G
{
174
1.31G
  std::visit(*this, _st);
175
1.31G
}
176
177
void ASTModifier::visit(Expression& _e)
178
2.19G
{
179
2.19G
  std::visit(*this, _e);
180
2.19G
}