Coverage Report

Created: 2026-10-26 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/liblangutil/DebugInfoSelection.cpp
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
#include <liblangutil/DebugInfoSelection.h>
20
21
#include <liblangutil/Exceptions.h>
22
23
#include <libsolutil/StringUtils.h>
24
25
#include <boost/algorithm/string/trim.hpp>
26
27
#include <range/v3/range/conversion.hpp>
28
#include <range/v3/view/map.hpp>
29
#include <range/v3/view/split.hpp>
30
31
#include <vector>
32
33
using namespace solidity;
34
using namespace solidity::langutil;
35
using namespace solidity::util;
36
37
DebugInfoSelection const DebugInfoSelection::All(bool _value) noexcept
38
245k
{
39
245k
  DebugInfoSelection result;
40
245k
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
41
980k
    result.*member = _value;
42
245k
  return result;
43
245k
}
44
45
DebugInfoSelection const DebugInfoSelection::Only(bool DebugInfoSelection::* _member) noexcept
46
0
{
47
0
  DebugInfoSelection result{};
48
0
  result.*_member = true;
49
0
  return result;
50
0
}
51
52
DebugInfoSelection const DebugInfoSelection::AllExcept(std::vector<bool DebugInfoSelection::*> const& _members) noexcept
53
103k
{
54
103k
  DebugInfoSelection result = All();
55
103k
  for (bool DebugInfoSelection::* member: _members)
56
103k
    result.*member = false;
57
103k
  return result;
58
103k
}
59
60
std::optional<DebugInfoSelection> DebugInfoSelection::fromString(std::string_view _input)
61
0
{
62
  // TODO: Make more stuff constexpr and make it a static_assert().
63
0
  solAssert(componentMap().count("all") == 0, "");
64
0
  solAssert(componentMap().count("none") == 0, "");
65
66
0
  if (_input == "all")
67
0
    return AllExceptExperimental();
68
0
  if (_input == "none")
69
0
    return None();
70
71
0
  return fromComponents(_input | ranges::views::split(',') | ranges::to<std::vector<std::string>>);
72
0
}
73
74
std::optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
75
  std::vector<std::string> const& _componentNames,
76
  bool _acceptWildcards
77
)
78
0
{
79
0
  solAssert(componentMap().count("*") == 0, "");
80
81
0
  DebugInfoSelection selection;
82
0
  for (auto const& component: _componentNames)
83
0
  {
84
0
    if (component == "*")
85
0
      return (_acceptWildcards ? std::make_optional(AllExceptExperimental()) : std::nullopt);
86
87
0
    if (!selection.enable(component))
88
0
      return std::nullopt;
89
0
  }
90
91
0
  return selection;
92
0
}
93
94
bool DebugInfoSelection::enable(std::string const& _component)
95
0
{
96
0
  auto memberIt = componentMap().find(boost::trim_copy(_component));
97
0
  if (memberIt == componentMap().end())
98
0
    return false;
99
100
0
  this->*(memberIt->second) = true;
101
0
  return true;
102
0
}
103
104
bool DebugInfoSelection::any() const noexcept
105
24.5M
{
106
24.5M
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
107
24.5M
    if (this->*member)
108
24.5M
      return true;
109
110
0
  return false;
111
24.5M
}
112
113
bool DebugInfoSelection::all() const noexcept
114
0
{
115
0
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
116
0
    if (!(this->*member))
117
0
      return false;
118
119
0
  return true;
120
0
}
121
122
DebugInfoSelection& DebugInfoSelection::operator&=(DebugInfoSelection const& _other)
123
0
{
124
0
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
125
0
    this->*member &= _other.*member;
126
0
  return *this;
127
0
}
128
129
DebugInfoSelection& DebugInfoSelection::operator|=(DebugInfoSelection const& _other)
130
0
{
131
0
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
132
0
    this->*member |= _other.*member;
133
0
  return *this;
134
0
}
135
136
DebugInfoSelection DebugInfoSelection::operator&(DebugInfoSelection _other) const noexcept
137
0
{
138
0
  _other &= *this;
139
0
  return _other;
140
0
}
141
142
DebugInfoSelection DebugInfoSelection::operator|(DebugInfoSelection _other) const noexcept
143
0
{
144
0
  _other |= *this;
145
0
  return _other;
146
0
}
147
148
bool DebugInfoSelection::operator==(DebugInfoSelection const& _other) const noexcept
149
0
{
150
0
  for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
151
0
    if (this->*member != _other.*member)
152
0
      return false;
153
0
  return true;
154
0
}
155
156
std::ostream& langutil::operator<<(std::ostream& _stream, DebugInfoSelection const& _selection)
157
0
{
158
0
  std::vector<std::string> selectedComponentNames;
159
0
  for (auto const& [name, member]: _selection.componentMap())
160
0
    if (_selection.*member)
161
0
      selectedComponentNames.push_back(name);
162
163
0
  return _stream << joinHumanReadable(selectedComponentNames, ",");
164
0
}