Coverage Report

Created: 2022-08-24 06:38

/src/solidity/libyul/optimiser/NameSimplifier.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
#pragma once
20
21
#include <libyul/ASTForward.h>
22
#include <libyul/optimiser/ASTWalker.h>
23
#include <libyul/YulString.h>
24
#include <libyul/optimiser/OptimiserStep.h>
25
26
#include <map>
27
#include <set>
28
#include <string>
29
30
namespace solidity::yul
31
{
32
33
struct Dialect;
34
35
/**
36
 * Pass to "simplify" all identifier names.
37
 *
38
 * The purpose of this is to make generated code more readable, but also
39
 * to remove AST identifiers that could lead to a different sorting order
40
 * and thus influence e.g. the order of function inlining.
41
 *
42
 * Prerequisites: Disambiguator, FunctionHoister, FunctionGrouper
43
 */
44
class NameSimplifier: public ASTModifier
45
{
46
public:
47
  static constexpr char const* name{"NameSimplifier"};
48
  static void run(OptimiserStepContext& _context, Block& _ast)
49
27.4k
  {
50
27.4k
    NameSimplifier{_context, _ast}(_ast);
51
27.4k
  }
52
53
  using ASTModifier::operator();
54
  void operator()(VariableDeclaration& _varDecl) override;
55
  void operator()(Identifier& _identifier) override;
56
  void operator()(FunctionCall& _funCall) override;
57
  void operator()(FunctionDefinition& _funDef) override;
58
59
private:
60
  NameSimplifier(OptimiserStepContext& _context, Block const& _ast);
61
62
  /// Tries to rename a list of variables.
63
  void renameVariables(std::vector<TypedName>& _variables);
64
65
  void findSimplification(YulString const& _name);
66
  void translate(YulString& _name);
67
68
  OptimiserStepContext& m_context;
69
  std::map<YulString, YulString> m_translations;
70
};
71
72
}