Coverage Report

Created: 2026-10-26 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.6k
{
28
17.6k
  _astRoot.accept(*this);
29
17.6k
  return !Error::containsErrors(m_errorReporter.errors());
30
17.6k
}
31
32
33
bool CFG::visit(FunctionDefinition const& _function)
34
21.7k
{
35
21.7k
  if (_function.isImplemented() && _function.isFree())
36
967
    m_functionControlFlow[{nullptr, &_function}] = ControlFlowBuilder::createFunctionFlow(
37
967
      m_nodeContainer,
38
967
      _function,
39
967
      nullptr /* _contract */
40
967
    );
41
21.7k
  return false;
42
21.7k
}
43
44
bool CFG::visit(ContractDefinition const& _contract)
45
19.1k
{
46
19.1k
  for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts)
47
21.1k
    for (FunctionDefinition const* function: contract->definedFunctions())
48
22.6k
      if (function->isImplemented())
49
21.7k
        m_functionControlFlow[{&_contract, function}] =
50
21.7k
          ControlFlowBuilder::createFunctionFlow(m_nodeContainer, *function, &_contract);
51
52
19.1k
  return true;
53
19.1k
}
54
55
FunctionFlow const& CFG::functionFlow(FunctionDefinition const& _function, ContractDefinition const* _contract) const
56
46.0k
{
57
46.0k
  return *m_functionControlFlow.at({_contract, &_function});
58
46.0k
}
59
60
CFGNode* CFG::NodeContainer::newNode()
61
389k
{
62
389k
  m_nodes.emplace_back(std::make_unique<CFGNode>());
63
389k
  return m_nodes.back().get();
64
389k
}