Coverage Report

Created: 2025-06-24 07:59

/src/solidity/libsolidity/analysis/Scoper.cpp
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
#include <libsolidity/analysis/Scoper.h>
20
21
#include <libsolidity/ast/AST.h>
22
23
using namespace solidity;
24
using namespace solidity::frontend;
25
26
void Scoper::assignScopes(ASTNode const& _astRoot)
27
27.4k
{
28
27.4k
  Scoper scoper;
29
27.4k
  _astRoot.accept(scoper);
30
27.4k
}
31
32
bool Scoper::visit(ContractDefinition const& _contract)
33
27.8k
{
34
27.8k
  solAssert(m_contract == nullptr, "");
35
27.8k
  m_contract = &_contract;
36
27.8k
  return ASTConstVisitor::visit(_contract);
37
27.8k
}
38
39
void Scoper::endVisit(ContractDefinition const& _contract)
40
27.8k
{
41
27.8k
  solAssert(m_contract == &_contract, "");
42
27.8k
  m_contract = nullptr;
43
27.8k
  ASTConstVisitor::endVisit(_contract);
44
27.8k
}
45
46
bool Scoper::visitNode(ASTNode const& _node)
47
1.90M
{
48
1.90M
  if (auto const* scopable = dynamic_cast<Scopable const*>(&_node))
49
211k
  {
50
211k
    scopable->annotation().scope = m_scopes.empty() ? nullptr : m_scopes.back();
51
211k
    scopable->annotation().contract = m_contract;
52
211k
  }
53
1.90M
  if (dynamic_cast<ScopeOpener const*>(&_node))
54
139k
    m_scopes.push_back(&_node);
55
1.90M
  return true;
56
1.90M
}
57
58
void Scoper::endVisitNode(ASTNode const& _node)
59
1.90M
{
60
1.90M
  if (dynamic_cast<ScopeOpener const*>(&_node))
61
139k
    m_scopes.pop_back();
62
1.90M
}