/src/solidity/libsolidity/analysis/ReferencesResolver.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 | | * @author Christian <c@ethdev.com> |
20 | | * @date 2014 |
21 | | * Component that resolves type names to types and annotates the AST accordingly. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include <libsolidity/ast/ASTVisitor.h> |
27 | | #include <libsolidity/ast/ASTAnnotations.h> |
28 | | #include <liblangutil/EVMVersion.h> |
29 | | #include <libyul/optimiser/ASTWalker.h> |
30 | | |
31 | | #include <list> |
32 | | #include <map> |
33 | | |
34 | | namespace solidity::langutil |
35 | | { |
36 | | class ErrorReporter; |
37 | | struct SourceLocation; |
38 | | } |
39 | | |
40 | | namespace solidity::frontend |
41 | | { |
42 | | |
43 | | class NameAndTypeResolver; |
44 | | |
45 | | /** |
46 | | * Resolves references to declarations (of variables and types) and also establishes the link |
47 | | * between a return statement and the return parameter list. |
48 | | */ |
49 | | class ReferencesResolver: private ASTConstVisitor, private yul::ASTWalker |
50 | | { |
51 | | public: |
52 | | ReferencesResolver( |
53 | | langutil::ErrorReporter& _errorReporter, |
54 | | NameAndTypeResolver& _resolver, |
55 | | langutil::EVMVersion _evmVersion, |
56 | | bool _resolveInsideCode = false |
57 | | ): |
58 | | m_errorReporter(_errorReporter), |
59 | | m_resolver(_resolver), |
60 | | m_evmVersion(_evmVersion), |
61 | | m_resolveInsideCode(_resolveInsideCode) |
62 | 0 | {} |
63 | | |
64 | | /// @returns true if no errors during resolving and throws exceptions on fatal errors. |
65 | | bool resolve(ASTNode const& _root); |
66 | | |
67 | | private: |
68 | | using yul::ASTWalker::visit; |
69 | | using yul::ASTWalker::operator(); |
70 | | |
71 | | bool visit(Block const& _block) override; |
72 | | void endVisit(Block const& _block) override; |
73 | | bool visit(TryCatchClause const& _tryCatchClause) override; |
74 | | void endVisit(TryCatchClause const& _tryCatchClause) override; |
75 | | bool visit(ForStatement const& _for) override; |
76 | | void endVisit(ForStatement const& _for) override; |
77 | | void endVisit(VariableDeclarationStatement const& _varDeclStatement) override; |
78 | | bool visit(VariableDeclaration const& _varDecl) override; |
79 | | bool visit(Identifier const& _identifier) override; |
80 | | bool visit(FunctionDefinition const& _functionDefinition) override; |
81 | | void endVisit(FunctionDefinition const& _functionDefinition) override; |
82 | | bool visit(ModifierDefinition const& _modifierDefinition) override; |
83 | | void endVisit(ModifierDefinition const& _modifierDefinition) override; |
84 | | void endVisit(IdentifierPath const& _path) override; |
85 | | bool visit(InlineAssembly const& _inlineAssembly) override; |
86 | | bool visit(Return const& _return) override; |
87 | | |
88 | | void operator()(yul::FunctionDefinition const& _function) override; |
89 | | void operator()(yul::Identifier const& _identifier) override; |
90 | | void operator()(yul::VariableDeclaration const& _varDecl) override; |
91 | | |
92 | | void resolveInheritDoc(StructuredDocumentation const& _documentation, StructurallyDocumentedAnnotation& _annotation); |
93 | | |
94 | | /// Checks if the name contains a '.'. |
95 | | void validateYulIdentifierName(yul::YulString _name, langutil::SourceLocation const& _location); |
96 | | |
97 | | langutil::ErrorReporter& m_errorReporter; |
98 | | NameAndTypeResolver& m_resolver; |
99 | | langutil::EVMVersion m_evmVersion; |
100 | | /// Stack of return parameters. |
101 | | std::vector<ParameterList const*> m_returnParameters; |
102 | | bool const m_resolveInsideCode; |
103 | | |
104 | | InlineAssemblyAnnotation* m_yulAnnotation = nullptr; |
105 | | bool m_yulInsideFunction = false; |
106 | | }; |
107 | | |
108 | | } |