Coverage Report

Created: 2025-09-08 08:10

/src/solidity/libsolidity/codegen/MultiUseYulFunctionCollector.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
 * Container of (unparsed) Yul functions identified by name which are meant to be generated
20
 * only once.
21
 */
22
23
#pragma once
24
25
#include <functional>
26
#include <map>
27
#include <string>
28
#include <set>
29
30
namespace solidity::frontend
31
{
32
33
/**
34
 * Container of (unparsed) Yul functions identified by name which are meant to be generated
35
 * only once.
36
 */
37
class MultiUseYulFunctionCollector
38
{
39
public:
40
  /// Helper function that uses @a _creator to create a function and add it to
41
  /// @a m_requestedFunctions if it has not been created yet and returns @a _name in both
42
  /// cases.
43
  std::string createFunction(std::string const& _name, std::function<std::string()> const& _creator);
44
45
  std::string createFunction(
46
    std::string const& _name,
47
    std::function<std::string(std::vector<std::string>&, std::vector<std::string>&)> const& _creator
48
  );
49
50
  /// @returns concatenation of all generated functions in the order in which they were
51
  /// generated.
52
  /// Clears the internal list, i.e. calling it again will result in an
53
  /// empty return value.
54
  std::string requestedFunctions();
55
56
  /// @returns true IFF a function with the specified name has already been collected.
57
4.01k
  bool contains(std::string const& _name) const { return m_requestedFunctions.count(_name) > 0; }
58
59
private:
60
  std::set<std::string> m_requestedFunctions;
61
  std::string m_code;
62
};
63
64
}