Skip to content

Commit 6d5edf8

Browse files
aarltaxic
andcommitted
Basic nlohmann-json integration.
Co-authored-by: Alex Beregszaszi <[email protected]>
1 parent b7baf7b commit 6d5edf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1428
-1498
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ include(EthCcache)
4040

4141
# Let's find our dependencies
4242
include(EthDependencies)
43-
include(jsoncpp)
43+
include(nlohmann-json)
4444
include(range-v3)
45-
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
4645

4746
find_package(Threads)
4847

cmake/jsoncpp.cmake

Lines changed: 0 additions & 70 deletions
This file was deleted.

cmake/nlohmann-json.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include(ExternalProject)
2+
3+
ExternalProject_Add(nlohmann-json
4+
DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/deps/nlohmann/json"
5+
DOWNLOAD_NAME json.hpp
6+
DOWNLOAD_NO_EXTRACT 1
7+
URL https://github.com/nlohmann/json/releases/download/v3.10.2/json.hpp
8+
URL_HASH SHA256=059743e48b37e41579ee3a92e82e984bfa0d2a9a2b20b175d04db8089f46f047
9+
CMAKE_COMMAND true
10+
BUILD_COMMAND true
11+
INSTALL_COMMAND true
12+
)
13+
14+
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/deps/nlohmann)

cmake/templates/license.h.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ libkeccak-tiny:
99
A single-file implementation of SHA-3 and SHAKE implemented by David Leon Gil
1010
License: CC0, attribution kindly requested. Blame taken too, but not liability.
1111

12+
nlohmann-json:
13+
__ _____ _____ _____
14+
__| | __| | | | JSON for Modern C++
15+
| | |__ | | | | | | version 3.10.2
16+
|_____|_____|_____|_|___| https://github.com/nlohmann/json
17+
18+
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
19+
SPDX-License-Identifier: MIT
20+
Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy
23+
of this software and associated documentation files (the "Software"), to deal
24+
in the Software without restriction, including without limitation the rights
25+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
copies of the Software, and to permit persons to whom the Software is
27+
furnished to do so, subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
SOFTWARE.
39+
1240
jsoncpp:
1341
The JsonCpp library's source code, including accompanying documentation,
1442
tests and demonstration applications, are licensed under the following

libevmasm/Assembly.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include <liblangutil/CharStream.h>
3535
#include <liblangutil/Exceptions.h>
3636

37-
#include <json/json.h>
38-
3937
#include <fstream>
4038
#include <range/v3/algorithm/any_of.hpp>
4139

@@ -198,9 +196,9 @@ string Assembly::assemblyString(StringMap const& _sourceCodes) const
198196
return tmp.str();
199197
}
200198

201-
Json::Value Assembly::createJsonValue(string _name, int _source, int _begin, int _end, string _value, string _jumpType)
199+
Json Assembly::createJsonValue(string _name, int _source, int _begin, int _end, string _value, string _jumpType)
202200
{
203-
Json::Value value;
201+
Json value = Json::object();
204202
value["name"] = _name;
205203
value["source"] = _source;
206204
value["begin"] = _begin;
@@ -219,11 +217,12 @@ string Assembly::toStringInHex(u256 _value)
219217
return hexStr.str();
220218
}
221219

222-
Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices) const
220+
Json Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices) const
223221
{
224-
Json::Value root;
222+
Json root = Json::object();
223+
root[".code"] = Json::array();
225224

226-
Json::Value& collection = root[".code"] = Json::arrayValue;
225+
Json& collection = root[".code"];
227226
for (AssemblyItem const& i: m_items)
228227
{
229228
int sourceIndex = -1;
@@ -237,7 +236,7 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
237236
switch (i.type())
238237
{
239238
case Operation:
240-
collection.append(
239+
collection.emplace_back(
241240
createJsonValue(
242241
instructionInfo(i.instruction()).name,
243242
sourceIndex,
@@ -247,41 +246,41 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
247246
);
248247
break;
249248
case Push:
250-
collection.append(
249+
collection.emplace_back(
251250
createJsonValue("PUSH", sourceIndex, i.location().start, i.location().end, toStringInHex(i.data()), i.getJumpTypeAsString()));
252251
break;
253252
case PushTag:
254253
if (i.data() == 0)
255-
collection.append(
254+
collection.emplace_back(
256255
createJsonValue("PUSH [ErrorTag]", sourceIndex, i.location().start, i.location().end, ""));
257256
else
258-
collection.append(
257+
collection.emplace_back(
259258
createJsonValue("PUSH [tag]", sourceIndex, i.location().start, i.location().end, toString(i.data())));
260259
break;
261260
case PushSub:
262-
collection.append(
261+
collection.emplace_back(
263262
createJsonValue("PUSH [$]", sourceIndex, i.location().start, i.location().end, toString(h256(i.data()))));
264263
break;
265264
case PushSubSize:
266-
collection.append(
265+
collection.emplace_back(
267266
createJsonValue("PUSH #[$]", sourceIndex, i.location().start, i.location().end, toString(h256(i.data()))));
268267
break;
269268
case PushProgramSize:
270-
collection.append(
269+
collection.emplace_back(
271270
createJsonValue("PUSHSIZE", sourceIndex, i.location().start, i.location().end));
272271
break;
273272
case PushLibraryAddress:
274-
collection.append(
273+
collection.emplace_back(
275274
createJsonValue("PUSHLIB", sourceIndex, i.location().start, i.location().end, m_libraries.at(h256(i.data())))
276275
);
277276
break;
278277
case PushDeployTimeAddress:
279-
collection.append(
278+
collection.emplace_back(
280279
createJsonValue("PUSHDEPLOYADDRESS", sourceIndex, i.location().start, i.location().end)
281280
);
282281
break;
283282
case PushImmutable:
284-
collection.append(createJsonValue(
283+
collection.emplace_back(createJsonValue(
285284
"PUSHIMMUTABLE",
286285
sourceIndex,
287286
i.location().start,
@@ -290,7 +289,7 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
290289
));
291290
break;
292291
case AssignImmutable:
293-
collection.append(createJsonValue(
292+
collection.emplace_back(createJsonValue(
294293
"ASSIGNIMMUTABLE",
295294
sourceIndex,
296295
i.location().start,
@@ -299,16 +298,16 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
299298
));
300299
break;
301300
case Tag:
302-
collection.append(
301+
collection.emplace_back(
303302
createJsonValue("tag", sourceIndex, i.location().start, i.location().end, toString(i.data())));
304-
collection.append(
303+
collection.emplace_back(
305304
createJsonValue("JUMPDEST", sourceIndex, i.location().start, i.location().end));
306305
break;
307306
case PushData:
308-
collection.append(createJsonValue("PUSH data", sourceIndex, i.location().start, i.location().end, toStringInHex(i.data())));
307+
collection.emplace_back(createJsonValue("PUSH data", sourceIndex, i.location().start, i.location().end, toStringInHex(i.data())));
309308
break;
310309
case VerbatimBytecode:
311-
collection.append(createJsonValue("VERBATIM", sourceIndex, i.location().start, i.location().end, toHex(i.verbatimData())));
310+
collection.emplace_back(createJsonValue("VERBATIM", sourceIndex, i.location().start, i.location().end, toHex(i.verbatimData())));
312311
break;
313312
default:
314313
assertThrow(false, InvalidOpcode, "");
@@ -317,7 +316,8 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
317316

318317
if (!m_data.empty() || !m_subs.empty())
319318
{
320-
Json::Value& data = root[".data"] = Json::objectValue;
319+
root[".data"] = Json::object();
320+
Json& data = root[".data"];
321321
for (auto const& i: m_data)
322322
if (u256(i.first) >= m_subs.size())
323323
data[toStringInHex((u256)i.first)] = toHex(i.second);

libevmasm/Assembly.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828

2929
#include <libsolutil/Common.h>
3030
#include <libsolutil/Assertions.h>
31+
#include <libsolutil/JSON.h>
3132
#include <libsolutil/Keccak256.h>
3233

3334
#include <libsolidity/interface/OptimiserSettings.h>
3435

35-
#include <json/json.h>
36-
3736
#include <iostream>
3837
#include <sstream>
3938
#include <memory>
@@ -151,7 +150,7 @@ class Assembly
151150
) const;
152151

153152
/// Create a JSON representation of the assembly.
154-
Json::Value assemblyJSON(
153+
Json assemblyJSON(
155154
std::map<std::string, unsigned> const& _sourceIndices = std::map<std::string, unsigned>()
156155
) const;
157156

@@ -170,7 +169,7 @@ class Assembly
170169
unsigned bytesRequired(unsigned subTagSize) const;
171170

172171
private:
173-
static Json::Value createJsonValue(
172+
static Json createJsonValue(
174173
std::string _name,
175174
int _source,
176175
int _begin,

libsolidity/ast/AST.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
#include <liblangutil/SourceLocation.h>
3333
#include <libevmasm/Instruction.h>
3434
#include <libsolutil/FixedHash.h>
35+
#include <libsolutil/JSON.h>
3536
#include <libsolutil/LazyInit.h>
3637

37-
#include <json/json.h>
38-
3938
#include <range/v3/view/subrange.hpp>
4039
#include <range/v3/view/map.hpp>
4140

0 commit comments

Comments
 (0)