Coverage Report

Created: 2022-08-24 06:40

/src/solidity/libyul/Utilities.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
 * Small useful snippets for the optimiser.
20
 */
21
22
#pragma once
23
24
#include <libsolutil/Common.h>
25
#include <libsolutil/Numeric.h>
26
#include <libyul/ASTForward.h>
27
28
namespace solidity::yul
29
{
30
31
std::string reindent(std::string const& _code);
32
33
u256 valueOfNumberLiteral(Literal const& _literal);
34
u256 valueOfStringLiteral(Literal const& _literal);
35
u256 valueOfBoolLiteral(Literal const& _literal);
36
u256 valueOfLiteral(Literal const& _literal);
37
38
/**
39
 * Linear order on Yul AST nodes.
40
 *
41
 * Defines a linear order on Yul AST nodes to be used in maps and sets.
42
 * Note: the order is total and deterministic, but independent of the semantics, e.g.
43
 * it is not guaranteed that the false Literal is "less" than the true Literal.
44
 */
45
template<typename T>
46
struct Less
47
{
48
  bool operator()(T const& _lhs, T const& _rhs) const;
49
};
50
51
template<typename T>
52
struct Less<T*>
53
{
54
  bool operator()(T const* _lhs, T const* _rhs) const
55
227k
  {
56
227k
    if (_lhs && _rhs)
57
201k
      return Less<T>{}(*_lhs, *_rhs);
58
25.5k
    else
59
25.5k
      return _lhs < _rhs;
60
227k
  }
61
};
62
63
template<> bool Less<Literal>::operator()(Literal const& _lhs, Literal const& _rhs) const;
64
extern template struct Less<Literal>;
65
66
// This can only be used for cases within one switch statement and
67
// relies on the fact that there are no duplicate cases.
68
struct SwitchCaseCompareByLiteralValue
69
{
70
  bool operator()(Case const* _lhsCase, Case const* _rhsCase) const;
71
};
72
73
}