Coverage Report

Created: 2022-08-24 06:31

/src/solidity/libyul/ScopeFiller.h
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
 * Module responsible for registering identifiers inside their scopes.
20
 */
21
22
#pragma once
23
24
#include <libyul/ASTForward.h>
25
26
#include <functional>
27
#include <memory>
28
29
namespace solidity::langutil
30
{
31
class ErrorReporter;
32
struct SourceLocation;
33
}
34
35
namespace solidity::yul
36
{
37
38
struct TypedName;
39
struct Scope;
40
struct AsmAnalysisInfo;
41
42
/**
43
 * Fills scopes with identifiers and checks for name clashes.
44
 * Does not resolve references.
45
 */
46
class ScopeFiller
47
{
48
public:
49
  ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter);
50
51
0
  bool operator()(Literal const&) { return true; }
52
0
  bool operator()(Identifier const&) { return true; }
53
  bool operator()(ExpressionStatement const& _expr);
54
0
  bool operator()(Assignment const&) { return true; }
55
  bool operator()(VariableDeclaration const& _variableDeclaration);
56
  bool operator()(FunctionDefinition const& _functionDefinition);
57
0
  bool operator()(FunctionCall const&) { return true; }
58
  bool operator()(If const& _if);
59
  bool operator()(Switch const& _switch);
60
  bool operator()(ForLoop const& _forLoop);
61
0
  bool operator()(Break const&) { return true; }
62
0
  bool operator()(Continue const&) { return true; }
63
0
  bool operator()(Leave const&) { return true; }
64
  bool operator()(Block const& _block);
65
66
private:
67
  bool registerVariable(
68
    TypedName const& _name,
69
    langutil::SourceLocation const& _location,
70
    Scope& _scope
71
  );
72
  bool registerFunction(FunctionDefinition const& _funDef);
73
74
  Scope& scope(Block const* _block);
75
76
  Scope* m_currentScope = nullptr;
77
  AsmAnalysisInfo& m_info;
78
  langutil::ErrorReporter& m_errorReporter;
79
};
80
81
}