Coverage Report

Created: 2026-09-14 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libevmasm/SubAssemblyID.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 <libsolutil/Numeric.h>
22
23
#include <liblangutil/Exceptions.h>
24
25
#include <compare>
26
#include <cstddef>
27
#include <cstdint>
28
#include <limits>
29
30
namespace solidity::evmasm
31
{
32
33
/// Sub assembly ID representing class. Based on fixed-size 64-bit unsigned int.
34
/// An empty / root state is reflected by a value that is set to max and can be queried via the `empty()` member
35
/// function.
36
struct SubAssemblyID
37
{
38
  using ValueType = uint64_t;
39
5.74M
  SubAssemblyID() = default;
40
29.4M
  SubAssemblyID(ValueType const _value): value(_value) {}
41
  explicit SubAssemblyID(u256 const& _data)
42
63.0k
  {
43
63.0k
    solAssert(_data <= std::numeric_limits<ValueType>::max());
44
63.0k
    value = static_cast<ValueType>(_data);
45
63.0k
  }
46
47
  size_t asIndex() const
48
73.1k
  {
49
    if constexpr(sizeof(ValueType) > sizeof(size_t))
50
    {
51
      solAssert(value < std::numeric_limits<size_t>::max());
52
      return static_cast<size_t>(value);
53
    }
54
73.1k
    return value;
55
73.1k
  }
56
21.9M
  bool empty() const { return value == std::numeric_limits<ValueType>::max(); }
57
38.0k
  auto operator<=>(SubAssemblyID const&) const = default;
58
59
  ValueType value = std::numeric_limits<ValueType>::max();
60
};
61
62
}