/src/solidity/libsolidity/analysis/ControlFlowGraph.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 <libsolidity/analysis/ControlFlowGraph.h> |
20 | | |
21 | | #include <libsolidity/analysis/ControlFlowBuilder.h> |
22 | | |
23 | | using namespace solidity::langutil; |
24 | | using namespace solidity::frontend; |
25 | | |
26 | | bool CFG::constructFlow(ASTNode const& _astRoot) |
27 | 17.3k | { |
28 | 17.3k | _astRoot.accept(*this); |
29 | 17.3k | return !Error::containsErrors(m_errorReporter.errors()); |
30 | 17.3k | } |
31 | | |
32 | | |
33 | | bool CFG::visit(FunctionDefinition const& _function) |
34 | 20.6k | { |
35 | 20.6k | if (_function.isImplemented() && _function.isFree()) |
36 | 952 | m_functionControlFlow[{nullptr, &_function}] = ControlFlowBuilder::createFunctionFlow( |
37 | 952 | m_nodeContainer, |
38 | 952 | _function, |
39 | 952 | nullptr /* _contract */ |
40 | 952 | ); |
41 | 20.6k | return false; |
42 | 20.6k | } |
43 | | |
44 | | bool CFG::visit(ContractDefinition const& _contract) |
45 | 18.4k | { |
46 | 18.4k | for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts) |
47 | 20.4k | for (FunctionDefinition const* function: contract->definedFunctions()) |
48 | 21.4k | if (function->isImplemented()) |
49 | 20.5k | m_functionControlFlow[{&_contract, function}] = |
50 | 20.5k | ControlFlowBuilder::createFunctionFlow(m_nodeContainer, *function, &_contract); |
51 | | |
52 | 18.4k | return true; |
53 | 18.4k | } |
54 | | |
55 | | FunctionFlow const& CFG::functionFlow(FunctionDefinition const& _function, ContractDefinition const* _contract) const |
56 | 43.6k | { |
57 | 43.6k | return *m_functionControlFlow.at({_contract, &_function}); |
58 | 43.6k | } |
59 | | |
60 | | CFGNode* CFG::NodeContainer::newNode() |
61 | 278k | { |
62 | 278k | m_nodes.emplace_back(std::make_unique<CFGNode>()); |
63 | 278k | return m_nodes.back().get(); |
64 | 278k | } |