/src/solidity/libsolidity/analysis/ContractLevelChecker.h
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 | | * Component that verifies overloads, abstract contracts, function clashes and others |
20 | | * checks at contract or function level. |
21 | | */ |
22 | | |
23 | | #pragma once |
24 | | |
25 | | #include <libsolidity/ast/ASTForward.h> |
26 | | #include <libsolidity/analysis/OverrideChecker.h> |
27 | | #include <liblangutil/SourceLocation.h> |
28 | | #include <map> |
29 | | #include <functional> |
30 | | #include <set> |
31 | | |
32 | | namespace solidity::langutil |
33 | | { |
34 | | class ErrorReporter; |
35 | | } |
36 | | |
37 | | namespace solidity::frontend |
38 | | { |
39 | | |
40 | | /** |
41 | | * Component that verifies overloads, abstract contracts, function clashes and others |
42 | | * checks at file, contract, or function level. |
43 | | */ |
44 | | class ContractLevelChecker |
45 | | { |
46 | | public: |
47 | | |
48 | | /// @param _errorReporter provides the error logging functionality. |
49 | | explicit ContractLevelChecker(langutil::ErrorReporter& _errorReporter): |
50 | | m_overrideChecker{_errorReporter}, |
51 | | m_errorReporter(_errorReporter) |
52 | 10.5k | {} |
53 | | |
54 | | /// Performs checks on the given source ast. |
55 | | /// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings |
56 | | bool check(SourceUnit const& _sourceUnit); |
57 | | |
58 | | private: |
59 | | /// Performs checks on the given contract. |
60 | | /// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings |
61 | | bool check(ContractDefinition const& _contract); |
62 | | /// Checks that two functions defined in this contract with the same name have different |
63 | | /// arguments and that there is at most one constructor. |
64 | | void checkDuplicateFunctions(ContractDefinition const& _contract); |
65 | | void checkDuplicateEvents(ContractDefinition const& _contract); |
66 | | void checkReceiveFunction(ContractDefinition const& _contract); |
67 | | template <class T> |
68 | | void findDuplicateDefinitions(std::map<std::string, std::vector<T>> const& _definitions); |
69 | | /// Checks for unimplemented functions and modifiers. |
70 | | void checkAbstractDefinitions(ContractDefinition const& _contract); |
71 | | /// Checks that the base constructor arguments are properly provided. |
72 | | /// Fills the list of unimplemented functions in _contract's annotations. |
73 | | void checkBaseConstructorArguments(ContractDefinition const& _contract); |
74 | | void annotateBaseConstructorArguments( |
75 | | ContractDefinition const& _currentContract, |
76 | | FunctionDefinition const* _baseConstructor, |
77 | | ASTNode const* _argumentNode |
78 | | ); |
79 | | /// Checks that different functions with external visibility end up having different |
80 | | /// external argument types (i.e. different signature). |
81 | | void checkExternalTypeClashes(ContractDefinition const& _contract); |
82 | | /// Checks for hash collisions in external function signatures. |
83 | | void checkHashCollisions(ContractDefinition const& _contract); |
84 | | /// Checks that all requirements for a library are fulfilled if this is a library. |
85 | | void checkLibraryRequirements(ContractDefinition const& _contract); |
86 | | /// Checks base contracts for ABI compatibility |
87 | | void checkBaseABICompatibility(ContractDefinition const& _contract); |
88 | | |
89 | | /// Warns if the contract has a payable fallback, but no receive ether function. |
90 | | void checkPayableFallbackWithoutReceive(ContractDefinition const& _contract); |
91 | | /// Error if the contract requires too much storage |
92 | | void checkStorageSize(ContractDefinition const& _contract); |
93 | | |
94 | | OverrideChecker m_overrideChecker; |
95 | | langutil::ErrorReporter& m_errorReporter; |
96 | | }; |
97 | | |
98 | | } |