Coverage Report

Created: 2022-08-24 06:31

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