Coverage Report

Created: 2022-08-24 06:55

/src/solidity/libyul/optimiser/Disambiguator.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
 * Optimiser component that makes all identifiers unique.
20
 */
21
22
#pragma once
23
24
#include <libyul/ASTForward.h>
25
#include <libyul/AsmAnalysisInfo.h>
26
#include <libyul/optimiser/ASTCopier.h>
27
#include <libyul/optimiser/NameDispenser.h>
28
29
#include <optional>
30
#include <set>
31
32
namespace solidity::yul
33
{
34
struct Dialect;
35
36
/**
37
 * Creates a copy of a Yul AST replacing all identifiers by unique names.
38
 */
39
class Disambiguator: public ASTCopier
40
{
41
public:
42
  explicit Disambiguator(
43
    Dialect const& _dialect,
44
    AsmAnalysisInfo const& _analysisInfo,
45
    std::set<YulString> const& _externallyUsedIdentifiers = {}
46
  ):
47
    m_info(_analysisInfo),
48
    m_dialect(_dialect),
49
    m_externallyUsedIdentifiers(_externallyUsedIdentifiers),
50
    m_nameDispenser(_dialect, m_externallyUsedIdentifiers)
51
66.8k
  {
52
66.8k
  }
53
54
protected:
55
  void enterScope(Block const& _block) override;
56
  void leaveScope(Block const& _block) override;
57
  void enterFunction(FunctionDefinition const& _function) override;
58
  void leaveFunction(FunctionDefinition const& _function) override;
59
  YulString translateIdentifier(YulString _name) override;
60
61
  void enterScopeInternal(Scope& _scope);
62
  void leaveScopeInternal(Scope& _scope);
63
64
  AsmAnalysisInfo const& m_info;
65
  Dialect const& m_dialect;
66
  std::set<YulString> const& m_externallyUsedIdentifiers;
67
68
  std::vector<Scope*> m_scopes;
69
  std::map<void const*, YulString> m_translations;
70
  NameDispenser m_nameDispenser;
71
};
72
73
}