diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-15 09:04:00 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-15 23:55:25 +0800 |
commit | 9719cf38e662e428ace8f3ebce9774a5338f0ce5 (patch) | |
tree | 07e441be8419b3161cedf449c2808bee082fe539 /solc | |
parent | 0072160d7772b2f30c2c6af4428728cb31641696 (diff) | |
download | dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.tar.gz dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.tar.zst dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.zip |
Move InterfaceHandler from string to JSON
Diffstat (limited to 'solc')
-rw-r--r-- | solc/CommandLineInterface.cpp | 30 | ||||
-rw-r--r-- | solc/jsonCompiler.cpp | 13 |
2 files changed, 34 insertions, 9 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 83168f86..5509a414 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -107,6 +107,18 @@ 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)) @@ -230,12 +242,18 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co if (m_args.count(argName)) { + std::string output; + if (_type == DocumentationType::ABIInterface) + output = jsonCompactPrint(m_compiler->metadata(_contract, _type)); + else + output = jsonPrettyPrint(m_compiler->metadata(_contract, _type)); + if (m_args.count("output-dir")) - createFile(_contract + suffix, m_compiler->metadata(_contract, _type)); + createFile(_contract + suffix, output); else { cout << title << endl; - cout << m_compiler->metadata(_contract, _type) << endl; + cout << output << endl; } } @@ -651,7 +669,7 @@ void CommandLineInterface::handleCombinedJSON() { Json::Value contractData(Json::objectValue); if (requests.count("abi")) - contractData["abi"] = m_compiler->interface(contractName); + contractData["abi"] = jsonCompactPrint(m_compiler->interface(contractName)); if (requests.count("bin")) contractData["bin"] = m_compiler->object(contractName).toHex(); if (requests.count("bin-runtime")) @@ -676,9 +694,9 @@ void CommandLineInterface::handleCombinedJSON() contractData["srcmap-runtime"] = map ? *map : ""; } if (requests.count("devdoc")) - contractData["devdoc"] = m_compiler->metadata(contractName, DocumentationType::NatspecDev); + contractData["devdoc"] = jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecDev)); if (requests.count("userdoc")) - contractData["userdoc"] = m_compiler->metadata(contractName, DocumentationType::NatspecUser); + contractData["userdoc"] = jsonCompactPrint(m_compiler->metadata(contractName, DocumentationType::NatspecUser)); output["contracts"][contractName] = contractData; } @@ -702,7 +720,7 @@ void CommandLineInterface::handleCombinedJSON() output["sources"][sourceCode.first]["AST"] = converter.json(); } } - cout << Json::FastWriter().write(output) << endl; + cout << jsonCompactPrint(output) << endl; } void CommandLineInterface::handleAst(string const& _argStr) diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index e5be8404..52f796a5 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -125,6 +125,13 @@ 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); @@ -213,7 +220,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback for (string const& contractName: compiler.contractNames()) { Json::Value contractData(Json::objectValue); - contractData["interface"] = compiler.interface(contractName); + contractData["interface"] = jsonCompactPrint(compiler.interface(contractName)); contractData["bytecode"] = compiler.object(contractName).toHex(); contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex(); contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode); @@ -274,7 +281,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback try { - return Json::FastWriter().write(output); + return jsonCompactPrint(output); } catch (...) { @@ -292,7 +299,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 Json::FastWriter().write(output); + return jsonCompactPrint(output); } else { |