/src/solidity/liblangutil/DebugInfoSelection.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 | | * Handles selections of debug info components. |
20 | | */ |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <map> |
25 | | #include <optional> |
26 | | #include <ostream> |
27 | | #include <string> |
28 | | #include <string_view> |
29 | | #include <vector> |
30 | | |
31 | | namespace solidity::langutil |
32 | | { |
33 | | |
34 | | /** |
35 | | * Represents a set of flags corresponding to components of debug info selected for some purpose. |
36 | | * |
37 | | * Provides extra functionality for enumerating the components and serializing/deserializing the |
38 | | * selection to/from a comma-separated string. |
39 | | */ |
40 | | struct DebugInfoSelection |
41 | | { |
42 | | static DebugInfoSelection const All(bool _value = true) noexcept; |
43 | 0 | static DebugInfoSelection const None() noexcept { return All(false); } |
44 | | static DebugInfoSelection const Only(bool DebugInfoSelection::* _member) noexcept; |
45 | 34.5k | static DebugInfoSelection const Default() noexcept { return AllExceptExperimental(); } |
46 | | static DebugInfoSelection const AllExcept(std::vector<bool DebugInfoSelection::*> const& _members) noexcept; |
47 | 101k | static DebugInfoSelection const AllExceptExperimental() noexcept { return AllExcept({&DebugInfoSelection::ethdebug}); } |
48 | | |
49 | | static std::optional<DebugInfoSelection> fromString(std::string_view _input); |
50 | | static std::optional<DebugInfoSelection> fromComponents( |
51 | | std::vector<std::string> const& _componentNames, |
52 | | bool _acceptWildcards = false |
53 | | ); |
54 | | bool enable(std::string const& _component); |
55 | | |
56 | | bool all() const noexcept; |
57 | | bool any() const noexcept; |
58 | 22.2M | bool none() const noexcept { return !any(); } |
59 | 0 | bool only(bool DebugInfoSelection::* _member) const noexcept { return *this == Only(_member); } |
60 | | |
61 | | DebugInfoSelection& operator&=(DebugInfoSelection const& _other); |
62 | | DebugInfoSelection& operator|=(DebugInfoSelection const& _other); |
63 | | DebugInfoSelection operator&(DebugInfoSelection _other) const noexcept; |
64 | | DebugInfoSelection operator|(DebugInfoSelection _other) const noexcept; |
65 | | |
66 | 0 | bool operator!=(DebugInfoSelection const& _other) const noexcept { return !(*this == _other); } |
67 | | bool operator==(DebugInfoSelection const& _other) const noexcept; |
68 | | |
69 | | friend std::ostream& operator<<(std::ostream& _stream, DebugInfoSelection const& _selection); |
70 | | |
71 | | static auto const& componentMap() |
72 | 22.4M | { |
73 | 22.4M | static std::map<std::string, bool DebugInfoSelection::*> const components = { |
74 | 22.4M | {"location", &DebugInfoSelection::location}, |
75 | 22.4M | {"snippet", &DebugInfoSelection::snippet}, |
76 | 22.4M | {"ast-id", &DebugInfoSelection::astID}, |
77 | 22.4M | {"ethdebug", &DebugInfoSelection::ethdebug}, |
78 | 22.4M | }; |
79 | 22.4M | return components; |
80 | 22.4M | } |
81 | | |
82 | | std::vector<std::string> selectedNames() const |
83 | 0 | { |
84 | 0 | std::vector<std::string> result; |
85 | 0 | for (auto const& component: componentMap()) |
86 | 0 | if (this->*(component.second)) |
87 | 0 | result.push_back(component.first); |
88 | 0 | return result; |
89 | 0 | } |
90 | | |
91 | | bool location = false; ///< Include source location. E.g. `@src 3:50:100` |
92 | | bool snippet = false; ///< Include source code snippet next to location. E.g. `@src 3:50:100 "contract C {..."` |
93 | | bool astID = false; ///< Include ID of the Solidity AST node. E.g. `@ast-id 15` |
94 | | bool ethdebug = false; ///< Include ethdebug related debug information. |
95 | | }; |
96 | | |
97 | | std::ostream& operator<<(std::ostream& _stream, DebugInfoSelection const& _selection); |
98 | | |
99 | | } |