Coverage Report

Created: 2022-08-24 06:52

/src/solidity/libyul/optimiser/InlinableExpressionFunctionFinder.h
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
 * Optimiser component that identifies functions to be inlined.
20
 */
21
22
#pragma once
23
24
#include <libyul/ASTForward.h>
25
#include <libyul/optimiser/ASTWalker.h>
26
27
#include <set>
28
29
namespace solidity::yul
30
{
31
32
/**
33
 * Optimiser component that finds functions that can be
34
 * inlined inside functional expressions, i.e. functions that
35
 *  - have a single return parameter r
36
 *  - have a body like r := <functional expression>
37
 *  - neither reference themselves nor r in the right hand side
38
 *
39
 * This component can only be used on sources with unique names.
40
 */
41
class InlinableExpressionFunctionFinder: public ASTWalker
42
{
43
public:
44
45
  std::map<YulString, FunctionDefinition const*> const& inlinableFunctions() const
46
0
  {
47
0
    return m_inlinableFunctions;
48
0
  }
49
50
  using ASTWalker::operator();
51
  void operator()(Identifier const& _identifier) override;
52
  void operator()(FunctionCall const& _funCall) override;
53
  void operator()(FunctionDefinition const& _function) override;
54
55
private:
56
  void checkAllowed(YulString _name)
57
0
  {
58
0
    if (m_disallowedIdentifiers.count(_name))
59
0
      m_foundDisallowedIdentifier = true;
60
0
  }
61
62
  bool m_foundDisallowedIdentifier = false;
63
  std::set<YulString> m_disallowedIdentifiers;
64
  std::map<YulString, FunctionDefinition const*> m_inlinableFunctions;
65
};
66
67
}