From 1a9c503e93547fadc0a7a2dcd6d368f456f47460 Mon Sep 17 00:00:00 2001 From: Ali92hm Date: Mon, 22 May 2017 13:39:38 -0700 Subject: [PATCH 1/3] Added createJson method to make writing json easier --- solc/CommandLineInterface.cpp | 5 +++++ solc/CommandLineInterface.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index e6d8776bf..9367a71c1 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -508,6 +508,11 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + pathName)); } +void CommandLineInterface::createJson(string const& _fileName, Json::Value const& _json) +{ + createFile(boost::filesystem::basename(_fileName) + string(".json"), dev::jsonCompactPrint(_json)); +} + bool CommandLineInterface::parseArguments(int _argc, char** _argv) { // Declare the supported options. diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index bf9400e4c..97cf21832 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -81,6 +81,11 @@ private: /// @arg _data to be written void createFile(std::string const& _fileName, std::string const& _data); + /// Create a json file in the given directory + /// @arg _fileName the name of the file (the extension will be replaced with .json) + /// @arg _json to be written + void createJson(std::string const& _fileName, Json::Value const& _json); + bool m_error = false; ///< If true, some error occurred. bool m_onlyAssemble = false; From 487ade1635699e27cdf9700545257e14ba08cf5e Mon Sep 17 00:00:00 2001 From: Ali92hm Date: Mon, 22 May 2017 13:44:19 -0700 Subject: [PATCH 2/3] Enabling --combined-json to output to file --- solc/CommandLineInterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 9367a71c1..84c88b243 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -910,7 +910,11 @@ void CommandLineInterface::handleCombinedJSON() output[g_strSources][sourceCode.first]["AST"] = converter.toJson(m_compiler->ast(sourceCode.first)); } } - cout << dev::jsonCompactPrint(output) << endl; + + if (m_args.count(g_argOutputDir)) + createJson("combined", output); + else + cout << dev::jsonCompactPrint(output) << endl; } void CommandLineInterface::handleAst(string const& _argStr) From 61dabb2f29362728b0b57a73680c23463e0b73f6 Mon Sep 17 00:00:00 2001 From: Ali92hm Date: Mon, 3 Jul 2017 16:46:30 -0700 Subject: [PATCH 3/3] Added --pretty-json commandline option --- solc/CommandLineInterface.cpp | 13 +++++++++---- solc/CommandLineInterface.h | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 84c88b243..271511d4f 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -112,10 +112,12 @@ static string const g_strSourceList = "sourceList"; static string const g_strSrcMap = "srcmap"; static string const g_strSrcMapRuntime = "srcmap-runtime"; static string const g_strStandardJSON = "standard-json"; +static string const g_strPrettyJson = "pretty-json"; static string const g_strVersion = "version"; static string const g_argAbi = g_strAbi; static string const g_argAddStandard = g_strAddStandard; +static string const g_argPrettyJson = g_strPrettyJson; static string const g_argAllowPaths = g_strAllowPaths; static string const g_argAsm = g_strAsm; static string const g_argAsmJson = g_strAsmJson; @@ -508,9 +510,9 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + pathName)); } -void CommandLineInterface::createJson(string const& _fileName, Json::Value const& _json) +void CommandLineInterface::createJson(string const& _fileName, string const& _json) { - createFile(boost::filesystem::basename(_fileName) + string(".json"), dev::jsonCompactPrint(_json)); + createFile(boost::filesystem::basename(_fileName) + string(".json"), _json); } bool CommandLineInterface::parseArguments(int _argc, char** _argv) @@ -546,6 +548,7 @@ Allowed options)", "Estimated number of contract runs for optimizer tuning." ) (g_argAddStandard.c_str(), "Add standard contracts.") + (g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.") ( g_argLibraries.c_str(), po::value>()->value_name("libs"), @@ -911,10 +914,12 @@ void CommandLineInterface::handleCombinedJSON() } } + string json = m_args.count(g_argPrettyJson) ? dev::jsonPrettyPrint(output) : dev::jsonCompactPrint(output); + if (m_args.count(g_argOutputDir)) - createJson("combined", output); + createJson("combined", json); else - cout << dev::jsonCompactPrint(output) << endl; + cout << json << endl; } void CommandLineInterface::handleAst(string const& _argStr) diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 97cf21832..4768c9d88 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -83,8 +83,8 @@ private: /// Create a json file in the given directory /// @arg _fileName the name of the file (the extension will be replaced with .json) - /// @arg _json to be written - void createJson(std::string const& _fileName, Json::Value const& _json); + /// @arg _json json string to be written + void createJson(std::string const& _fileName, std::string const& _json); bool m_error = false; ///< If true, some error occurred.