Coverage Report

Created: 2026-06-30 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libevmasm/EthdebugSchema.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 <libevmasm/EthdebugSchema.h>
20
21
#include <libsolutil/Numeric.h>
22
#include <libsolutil/Visitor.h>
23
24
using namespace solidity;
25
using namespace solidity::evmasm::ethdebug;
26
27
void schema::data::to_json(Json& _json, HexValue const& _hexValue)
28
983k
{
29
983k
  _json = util::toHex(_hexValue.value, util::HexPrefix::Add);
30
983k
}
31
32
void schema::data::to_json(Json& _json, Unsigned const& _unsigned)
33
8.00M
{
34
8.00M
  std::visit(util::GenericVisitor{
35
8.00M
    [&](HexValue const& _hexValue) { _json = _hexValue; },
36
8.00M
    [&](std::uint64_t const _value) { _json = _value; }
37
8.00M
  }, _unsigned.value);
38
8.00M
}
39
40
void schema::materials::to_json(Json& _json, ID const& _id)
41
2.15M
{
42
2.15M
  std::visit(util::GenericVisitor{
43
2.15M
    [&](std::string const& _hexValue) { _json = _hexValue; },
44
2.15M
    [&](std::uint64_t const _value) { _json = _value; }
45
2.15M
  }, _id.value);
46
2.15M
}
47
48
void schema::materials::to_json(Json& _json, Reference const& _source)
49
2.15M
{
50
2.15M
  _json["id"] = _source.id;
51
2.15M
  if (_source.type)
52
0
    _json["type"] = *_source.type == Reference::Type::Compilation ? "compilation" : "source";
53
2.15M
}
54
55
void schema::materials::to_json(Json& _json, SourceRange::Range const& _range)
56
2.13M
{
57
2.13M
  _json["length"] = _range.length;
58
2.13M
  _json["offset"] = _range.offset;
59
2.13M
}
60
61
62
void schema::materials::to_json(Json& _json, SourceRange const& _sourceRange)
63
2.15M
{
64
2.15M
  _json["source"] = _sourceRange.source;
65
2.15M
  if (_sourceRange.range)
66
2.13M
    _json["range"] = *_sourceRange.range;
67
2.15M
}
68
69
void schema::materials::to_json(Json& _json, Source const& _source)
70
0
{
71
0
  _json["id"] = _source.id;
72
0
  _json["path"] = _source.path;
73
0
  _json["contents"] = _source.contents;
74
0
  if (_source.encoding)
75
0
    _json["encoding"] = *_source.encoding;
76
0
  _json["language"] = _source.language;
77
0
}
78
79
void schema::materials::to_json(Json& _json, Compilation::Compiler const& _compiler)
80
0
{
81
0
  _json["name"] = _compiler.name;
82
0
  _json["version"] = _compiler.version;
83
0
}
84
85
void schema::materials::to_json(Json& _json, Compilation const& _compilation)
86
0
{
87
0
  _json["id"] = _compilation.id;
88
0
  _json["compiler"] = _compilation.compiler;
89
0
  if (_compilation.settings)
90
0
    _json["settings"] = *_compilation.settings;
91
0
  _json["sources"] = _compilation.sources;
92
0
}
93
94
void schema::to_json(Json& _json, Program::Contract const& _contract)
95
16.2k
{
96
16.2k
  if (_contract.name)
97
16.2k
    _json["name"] = *_contract.name;
98
16.2k
  _json["definition"] = _contract.definition;
99
16.2k
}
100
101
void schema::program::to_json(Json& _json, Context::Variable const& _contextVariable)
102
0
{
103
0
  auto const numProperties =
104
0
    _contextVariable.identifier.has_value() +
105
0
    _contextVariable.declaration.has_value();
106
0
  solRequire(numProperties >= 1, EthdebugException, "Context variable has no properties.");
107
0
  if (_contextVariable.identifier)
108
0
  {
109
0
    solRequire(!_contextVariable.identifier->empty(), EthdebugException, "Variable identifier must not be empty.");
110
0
    _json["identifier"] = *_contextVariable.identifier;
111
0
  }
112
0
  if (_contextVariable.declaration)
113
0
    _json["declaration"] = *_contextVariable.declaration;
114
0
}
115
116
void schema::program::to_json(Json& _json, Context const& _context)
117
2.13M
{
118
2.13M
  solRequire(_context.code.has_value() + _context.remark.has_value() + _context.variables.has_value() >= 1, EthdebugException, "Context needs >=1 properties.");
119
2.13M
  if (_context.code)
120
2.13M
    _json["code"] = *_context.code;
121
2.13M
  if (_context.variables)
122
0
  {
123
0
    solRequire(!_context.variables->empty(), EthdebugException, "Context variables must not be empty if provided.");
124
0
    _json["variables"] = *_context.variables;
125
0
  }
126
2.13M
  if (_context.remark)
127
0
    _json["remark"] = *_context.remark;
128
2.13M
}
129
130
void schema::program::to_json(Json& _json, Instruction::Operation const& _operation)
131
2.74M
{
132
2.74M
  _json = { {"mnemonic", _operation.mnemonic} };
133
2.74M
  if (!_operation.arguments.empty())
134
983k
    _json["arguments"] = _operation.arguments;
135
2.74M
}
136
137
void schema::program::to_json(Json& _json, Instruction const& _instruction)
138
2.74M
{
139
2.74M
  _json["offset"] = _instruction.offset;
140
2.74M
  if (_instruction.operation)
141
2.74M
    _json["operation"] = *_instruction.operation;
142
2.74M
  if (_instruction.context)
143
2.13M
    _json["context"] = *_instruction.context;
144
2.74M
}
145
146
void schema::to_json(Json& _json, Program const& _program)
147
16.2k
{
148
16.2k
  if (_program.compilation)
149
0
    _json["compilation"] = *_program.compilation;
150
16.2k
  _json["contract"] = _program.contract;
151
16.2k
  _json["environment"] = _program.environment;
152
16.2k
  if (_program.context)
153
0
    _json["context"] = *_program.context;
154
16.2k
  _json["instructions"] = _program.instructions;
155
16.2k
}
156
157
void schema::to_json(Json& _json, Program::Environment const& _environment)
158
16.2k
{
159
16.2k
  switch (_environment)
160
16.2k
  {
161
0
  case Program::Environment::CALL:
162
0
    _json = "call";
163
0
    break;
164
16.2k
  case Program::Environment::CREATE:
165
16.2k
    _json = "create";
166
16.2k
    break;
167
16.2k
  }
168
16.2k
}
169
170
void schema::info::to_json(Json& _json, Resources const& _resources)
171
0
{
172
0
  _json["compilation"] = _resources.compilation;
173
0
  _json["types"] = _resources.types;
174
0
  _json["pointers"] = _resources.pointers;
175
0
}