/src/solidity/libyul/FunctionReferenceResolver.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 | | #include <libyul/FunctionReferenceResolver.h> |
20 | | |
21 | | #include <libyul/AST.h> |
22 | | #include <libsolutil/CommonData.h> |
23 | | |
24 | | #include <range/v3/view/reverse.hpp> |
25 | | |
26 | | using namespace solidity::yul; |
27 | | using namespace solidity::util; |
28 | | |
29 | | FunctionReferenceResolver::FunctionReferenceResolver(Block const& _ast) |
30 | 1.64M | { |
31 | 1.64M | (*this)(_ast); |
32 | 1.64M | yulAssert(m_scopes.empty()); |
33 | 1.64M | } |
34 | | |
35 | | void FunctionReferenceResolver::operator()(FunctionCall const& _functionCall) |
36 | 66.2M | { |
37 | 66.2M | if (!isBuiltinFunctionCall(_functionCall)) |
38 | 8.76M | for (auto&& scope: m_scopes | ranges::views::reverse) |
39 | 22.8M | { |
40 | 22.8M | yulAssert(std::holds_alternative<Identifier>(_functionCall.functionName)); |
41 | 22.8M | if (FunctionDefinition const** function = util::valueOrNullptr(scope, std::get<Identifier>(_functionCall.functionName).name)) |
42 | 8.76M | { |
43 | 8.76M | m_functionReferences[&_functionCall] = *function; |
44 | 8.76M | break; |
45 | 8.76M | } |
46 | 22.8M | } |
47 | | |
48 | 66.2M | ASTWalker::operator()(_functionCall); |
49 | 66.2M | } |
50 | | |
51 | | void FunctionReferenceResolver::operator()(Block const& _block) |
52 | 25.3M | { |
53 | 25.3M | m_scopes.emplace_back(); |
54 | 25.3M | for (auto const& statement: _block.statements) |
55 | 210M | if (auto const* function = std::get_if<FunctionDefinition>(&statement)) |
56 | 4.77M | m_scopes.back()[function->name] = function; |
57 | | |
58 | 25.3M | ASTWalker::operator()(_block); |
59 | | |
60 | 25.3M | m_scopes.pop_back(); |
61 | 25.3M | } |