aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-11-16 01:33:28 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2016-11-16 01:38:18 +0800
commit81c50143f2bff6f589ab1237d68c8820107f18b9 (patch)
tree749c4e932d32aebee20f54065d9962a7ee526582
parent9205662de9416ab160db7327a6022ea8b1fba3e1 (diff)
downloaddexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar.gz
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar.bz2
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar.lz
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar.xz
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.tar.zst
dexon-solidity-81c50143f2bff6f589ab1237d68c8820107f18b9.zip
Move JSON helpers to libdevcore/json
-rw-r--r--libdevcore/JSON.h44
-rw-r--r--solc/CommandLineInterface.cpp25
-rw-r--r--solc/jsonCompiler.cpp14
-rw-r--r--test/libsolidity/SolidityNatspecJSON.cpp3
4 files changed, 57 insertions, 29 deletions
diff --git a/libdevcore/JSON.h b/libdevcore/JSON.h
new file mode 100644
index 00000000..7876dfb2
--- /dev/null
+++ b/libdevcore/JSON.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
+*/
+/** @file JSON.h
+ * @date 2016
+ *
+ * JSON related helpers
+ */
+
+#pragma once
+
+#include <json/json.h>
+
+namespace dev
+{
+
+/// Serialise the JSON object (@a _input) with identation
+std::string jsonPrettyPrint(Json::Value const& _input)
+{
+ return Json::StyledWriter().write(_input);
+}
+
+/// Serialise theJ SON object (@a _input) without identation
+std::string jsonCompactPrint(Json::Value const& _input)
+{
+ Json::FastWriter writer;
+ writer.omitEndingLineFeed();
+ return writer.write(_input);
+}
+
+}
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 5509a414..7b23f886 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -41,6 +41,7 @@
#include <libdevcore/Common.h>
#include <libdevcore/CommonData.h>
#include <libdevcore/CommonIO.h>
+#include <libdevcore/JSON.h>
#include <libevmasm/Instruction.h>
#include <libevmasm/GasMeter.h>
#include <libsolidity/interface/Version.h>
@@ -107,18 +108,6 @@ static void version()
exit(0);
}
-string jsonPrettyPrint(Json::Value const& input)
-{
- return Json::StyledWriter().write(input);
-}
-
-string jsonCompactPrint(Json::Value const& input)
-{
- Json::FastWriter writer;
- writer.omitEndingLineFeed();
- return writer.write(input);
-}
-
static bool needsHumanTargetedStdout(po::variables_map const& _args)
{
if (_args.count(g_argGas))
@@ -244,9 +233,9 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
{
std::string output;
if (_type == DocumentationType::ABIInterface)
- output = jsonCompactPrint(m_compiler->metadata(_contract, _type));
+ output = dev::jsonCompactPrint(m_compiler->metadata(_contract, _type));
else
- output = jsonPrettyPrint(m_compiler->metadata(_contract, _type));
+ output = dev::jsonPrettyPrint(m_compiler->metadata(_contract, _type));
if (m_args.count("output-dir"))
createFile(_contract + suffix, output);
@@ -669,7 +658,7 @@ void CommandLineInterface::handleCombinedJSON()
{
Json::Value contractData(Json::objectValue);
if (requests.count("abi"))
- contractData["abi"] = jsonCompactPrint(m_compiler->interface(contractName));
+ contractData["abi"] = dev::jsonCompactPrint(m_compiler->interface(contractName));
if (requests.count("bin"))
contractData["bin"] = m_compiler->object(contractName).toHex();
if (requests.count("bin-runtime"))
@@ -694,9 +683,9 @@ void CommandLineInterface::handleCombinedJSON()
contractData["srcmap-runtime"] = map ? *map : "";
}
if (requests.count("devdoc"))
- contractData["devdoc"] = jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecDev));
+ contractData["devdoc"] = dev::jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecDev));
if (requests.count("userdoc"))
- contractData["userdoc"] = jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecUser));
+ contractData["userdoc"] = dev::jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecUser));
output["contracts"][contractName] = contractData;
}
@@ -720,7 +709,7 @@ void CommandLineInterface::handleCombinedJSON()
output["sources"][sourceCode.first]["AST"] = converter.json();
}
}
- cout << jsonCompactPrint(output) << endl;
+ cout << dev::jsonCompactPrint(output) << endl;
}
void CommandLineInterface::handleAst(string const& _argStr)
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp
index 52f796a5..771f0df8 100644
--- a/solc/jsonCompiler.cpp
+++ b/solc/jsonCompiler.cpp
@@ -27,6 +27,7 @@
#include <libdevcore/Common.h>
#include <libdevcore/CommonData.h>
#include <libdevcore/CommonIO.h>
+#include <libdevcore/JSON.h>
#include <libevmasm/Instruction.h>
#include <libevmasm/GasMeter.h>
#include <libsolidity/parsing/Scanner.h>
@@ -125,13 +126,6 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
return gasEstimates;
}
-string jsonCompactPrint(Json::Value const& input)
-{
- Json::FastWriter writer;
- writer.omitEndingLineFeed();
- return writer.write(input);
-}
-
string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback _readCallback)
{
Json::Value output(Json::objectValue);
@@ -220,7 +214,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
for (string const& contractName: compiler.contractNames())
{
Json::Value contractData(Json::objectValue);
- contractData["interface"] = jsonCompactPrint(compiler.interface(contractName));
+ contractData["interface"] = dev::jsonCompactPrint(compiler.interface(contractName));
contractData["bytecode"] = compiler.object(contractName).toHex();
contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
@@ -281,7 +275,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
try
{
- return jsonCompactPrint(output);
+ return dev::jsonCompactPrint(output);
}
catch (...)
{
@@ -299,7 +293,7 @@ string compileMulti(string const& _input, bool _optimize, CStyleReadFileCallback
errors.append("Error parsing input JSON: " + reader.getFormattedErrorMessages());
Json::Value output(Json::objectValue);
output["errors"] = errors;
- return jsonCompactPrint(output);
+ return dev::jsonCompactPrint(output);
}
else
{
diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp
index facfcda7..f05542b1 100644
--- a/test/libsolidity/SolidityNatspecJSON.cpp
+++ b/test/libsolidity/SolidityNatspecJSON.cpp
@@ -26,6 +26,7 @@
#include <libsolidity/interface/CompilerStack.h>
#include <libsolidity/interface/Exceptions.h>
#include <libdevcore/Exceptions.h>
+#include <libdevcore/JSON.h>
namespace dev
{
@@ -57,7 +58,7 @@ public:
BOOST_CHECK_MESSAGE(
expectedDocumentation == generatedDocumentation,
"Expected " << _expectedDocumentationString <<
- "\n but got:\n" << Json::StyledWriter().write(generatedDocumentation)
+ "\n but got:\n" << dev::jsonPrettyPrint(generatedDocumentation)
);
}