diff --git a/Changelog.md b/Changelog.md index 8f666eac1..203081823 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ Language Features: Compiler Features: * Peephole Optimizer: Remove operations without side effects before simple terminations. * Assembly-Json: Export: Include source list in `sourceList` field. + * Commandline Interface: option ``--pretty-json`` works also with the following options: ``--abi``, ``--asm-json``, ``--ast-compact-json``, ``--devdoc``, ``--storage-layout``, ``--userdoc``. Bugfixes: diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 4338cc64f..f75f5bc15 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -190,9 +190,9 @@ Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair #include +#include #include #include @@ -58,7 +59,7 @@ public: std::map _sourceIndices = std::map() ); /// Output the json representation of the AST to _stream. - void print(std::ostream& _stream, ASTNode const& _node); + void print(std::ostream& _stream, ASTNode const& _node, util::JsonFormat const& _format); Json::Value toJson(ASTNode const& _node); template Json::Value toJson(std::vector> const& _nodes) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 55b703392..8cf3a8ebc 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -317,7 +317,7 @@ void CommandLineInterface::handleABI(string const& _contract) if (!m_options.compiler.outputs.abi) return; - string data = jsonCompactPrint(removeNullMembers(m_compiler->contractABI(_contract))); + string data = jsonPrint(removeNullMembers(m_compiler->contractABI(_contract)), m_options.formatting.json); if (!m_options.output.dir.empty()) createFile(m_compiler->filesystemFriendlyName(_contract) + ".abi", data); else @@ -331,7 +331,7 @@ void CommandLineInterface::handleStorageLayout(string const& _contract) if (!m_options.compiler.outputs.storageLayout) return; - string data = jsonCompactPrint(removeNullMembers(m_compiler->storageLayout(_contract))); + string data = jsonPrint(removeNullMembers(m_compiler->storageLayout(_contract)), m_options.formatting.json); if (!m_options.output.dir.empty()) createFile(m_compiler->filesystemFriendlyName(_contract) + "_storage.json", data); else @@ -361,12 +361,13 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra if (enabled) { - std::string output = jsonPrettyPrint( + std::string output = jsonPrint( removeNullMembers( _natspecDev ? m_compiler->natspecDev(_contract) : m_compiler->natspecUser(_contract) - ) + ), + m_options.formatting.json ); if (!m_options.output.dir.empty()) @@ -892,7 +893,7 @@ void CommandLineInterface::handleAst() { stringstream data; string postfix = ""; - ASTJsonConverter(m_compiler->state(), m_compiler->sourceIndices()).print(data, m_compiler->ast(sourceCode.first)); + ASTJsonConverter(m_compiler->state(), m_compiler->sourceIndices()).print(data, m_compiler->ast(sourceCode.first), m_options.formatting.json); postfix += "_json"; boost::filesystem::path path(sourceCode.first); createFile(path.filename().string() + postfix + ".ast", data.str()); @@ -904,7 +905,7 @@ void CommandLineInterface::handleAst() for (auto const& sourceCode: m_fileReader.sourceUnits()) { sout() << endl << "======= " << sourceCode.first << " =======" << endl; - ASTJsonConverter(m_compiler->state(), m_compiler->sourceIndices()).print(sout(), m_compiler->ast(sourceCode.first)); + ASTJsonConverter(m_compiler->state(), m_compiler->sourceIndices()).print(sout(), m_compiler->ast(sourceCode.first), m_options.formatting.json); } } } @@ -1146,7 +1147,7 @@ void CommandLineInterface::outputCompilationResults() { string ret; if (m_options.compiler.outputs.asmJson) - ret = jsonPrettyPrint(removeNullMembers(m_compiler->assemblyJSON(contract))); + ret = util::jsonPrint(removeNullMembers(m_compiler->assemblyJSON(contract)), m_options.formatting.json); else ret = m_compiler->assemblyString(contract, m_fileReader.sourceUnits()); diff --git a/test/cmdlineTests/asm_json/args b/test/cmdlineTests/asm_json/args index 8f4713692..dd9e77b16 100644 --- a/test/cmdlineTests/asm_json/args +++ b/test/cmdlineTests/asm_json/args @@ -1 +1 @@ ---asm-json +--asm-json --pretty-json diff --git a/test/cmdlineTests/asm_json_no_pretty_print/args b/test/cmdlineTests/asm_json_no_pretty_print/args new file mode 100644 index 000000000..8f4713692 --- /dev/null +++ b/test/cmdlineTests/asm_json_no_pretty_print/args @@ -0,0 +1 @@ +--asm-json diff --git a/test/cmdlineTests/asm_json_no_pretty_print/input.sol b/test/cmdlineTests/asm_json_no_pretty_print/input.sol new file mode 100644 index 000000000..da3a08d7f --- /dev/null +++ b/test/cmdlineTests/asm_json_no_pretty_print/input.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C { + function f(uint x) public pure { + x += 42; + require(x > 100); + } +} diff --git a/test/cmdlineTests/asm_json_no_pretty_print/output b/test/cmdlineTests/asm_json_no_pretty_print/output new file mode 100644 index 000000000..232d0bdea --- /dev/null +++ b/test/cmdlineTests/asm_json_no_pretty_print/output @@ -0,0 +1,4 @@ + +======= asm_json_no_pretty_print/input.sol:C ======= +EVM assembly: +{".code":[{"begin":60,"end":160,"name":"PUSH","source":0,"value":"80"},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"40"},{"begin":60,"end":160,"name":"MSTORE","source":0},{"begin":60,"end":160,"name":"CALLVALUE","source":0},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"ISZERO","source":0},{"begin":60,"end":160,"name":"PUSH [tag]","source":0,"value":"1"},{"begin":60,"end":160,"name":"JUMPI","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"REVERT","source":0},{"begin":60,"end":160,"name":"tag","source":0,"value":"1"},{"begin":60,"end":160,"name":"JUMPDEST","source":0},{"begin":60,"end":160,"name":"POP","source":0},{"begin":60,"end":160,"name":"PUSH #[$]","source":0,"value":"0000000000000000000000000000000000000000000000000000000000000000"},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"PUSH [$]","source":0,"value":"0000000000000000000000000000000000000000000000000000000000000000"},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"CODECOPY","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"RETURN","source":0}],".data":{"0":{".auxdata":"",".code":[{"begin":60,"end":160,"name":"PUSH","source":0,"value":"80"},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"40"},{"begin":60,"end":160,"name":"MSTORE","source":0},{"begin":60,"end":160,"name":"CALLVALUE","source":0},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"ISZERO","source":0},{"begin":60,"end":160,"name":"PUSH [tag]","source":0,"value":"1"},{"begin":60,"end":160,"name":"JUMPI","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"REVERT","source":0},{"begin":60,"end":160,"name":"tag","source":0,"value":"1"},{"begin":60,"end":160,"name":"JUMPDEST","source":0},{"begin":60,"end":160,"name":"POP","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"4"},{"begin":60,"end":160,"name":"CALLDATASIZE","source":0},{"begin":60,"end":160,"name":"LT","source":0},{"begin":60,"end":160,"name":"PUSH [tag]","source":0,"value":"2"},{"begin":60,"end":160,"name":"JUMPI","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"CALLDATALOAD","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"E0"},{"begin":60,"end":160,"name":"SHR","source":0},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"B3DE648B"},{"begin":60,"end":160,"name":"EQ","source":0},{"begin":60,"end":160,"name":"PUSH [tag]","source":0,"value":"3"},{"begin":60,"end":160,"name":"JUMPI","source":0},{"begin":60,"end":160,"name":"tag","source":0,"value":"2"},{"begin":60,"end":160,"name":"JUMPDEST","source":0},{"begin":60,"end":160,"name":"PUSH","source":0,"value":"0"},{"begin":60,"end":160,"name":"DUP1","source":0},{"begin":60,"end":160,"name":"REVERT","source":0},{"begin":77,"end":158,"name":"tag","source":0,"value":"3"},{"begin":77,"end":158,"name":"JUMPDEST","source":0},{"begin":77,"end":158,"name":"PUSH [tag]","source":0,"value":"4"},{"begin":77,"end":158,"name":"PUSH","source":0,"value":"4"},{"begin":77,"end":158,"name":"DUP1","source":0},{"begin":77,"end":158,"name":"CALLDATASIZE","source":0},{"begin":77,"end":158,"name":"SUB","source":0},{"begin":77,"end":158,"name":"DUP2","source":0},{"begin":77,"end":158,"name":"ADD","source":0},{"begin":77,"end":158,"name":"SWAP1","source":0},{"begin":77,"end":158,"name":"PUSH [tag]","source":0,"value":"5"},{"begin":77,"end":158,"name":"SWAP2","source":0},{"begin":77,"end":158,"name":"SWAP1","source":0},{"begin":77,"end":158,"name":"PUSH [tag]","source":0,"value":"6"},{"begin":77,"end":158,"jumpType":"[in]","name":"JUMP","source":0},{"begin":77,"end":158,"name":"tag","source":0,"value":"5"},{"begin":77,"end":158,"name":"JUMPDEST","source":0},{"begin":77,"end":158,"name":"PUSH [tag]","source":0,"value":"7"},{"begin":77,"end":158,"jumpType":"[in]","name":"JUMP","source":0},{"begin":77,"end":158,"name":"tag","source":0,"value":"4"},{"begin":77,"end":158,"name":"JUMPDEST","source":0},{"begin":77,"end":158,"name":"STOP","source":0},{"begin":77,"end":158,"name":"tag","source":0,"value":"7"},{"begin":77,"end":158,"name":"JUMPDEST","source":0},{"begin":123,"end":125,"name":"PUSH","source":0,"value":"2A"},{"begin":118,"end":125,"name":"DUP2","source":0},{"begin":118,"end":125,"name":"PUSH [tag]","source":0,"value":"9"},{"begin":118,"end":125,"name":"SWAP2","source":0},{"begin":118,"end":125,"name":"SWAP1","source":0},{"begin":118,"end":125,"name":"PUSH [tag]","source":0,"value":"10"},{"begin":118,"end":125,"jumpType":"[in]","name":"JUMP","source":0},{"begin":118,"end":125,"name":"tag","source":0,"value":"9"},{"begin":118,"end":125,"name":"JUMPDEST","source":0},{"begin":118,"end":125,"name":"SWAP1","source":0},{"begin":118,"end":125,"name":"POP","source":0},{"begin":147,"end":150,"name":"PUSH","source":0,"value":"64"},{"begin":143,"end":144,"name":"DUP2","source":0},{"begin":143,"end":150,"name":"GT","source":0},{"begin":135,"end":151,"name":"PUSH [tag]","source":0,"value":"11"},{"begin":135,"end":151,"name":"JUMPI","source":0},{"begin":135,"end":151,"name":"PUSH","source":0,"value":"0"},{"begin":135,"end":151,"name":"DUP1","source":0},{"begin":135,"end":151,"name":"REVERT","source":0},{"begin":135,"end":151,"name":"tag","source":0,"value":"11"},{"begin":135,"end":151,"name":"JUMPDEST","source":0},{"begin":77,"end":158,"name":"POP","source":0},{"begin":77,"end":158,"jumpType":"[out]","name":"JUMP","source":0},{"begin":88,"end":205,"name":"tag","source":1,"value":"13"},{"begin":88,"end":205,"name":"JUMPDEST","source":1},{"begin":197,"end":198,"name":"PUSH","source":1,"value":"0"},{"begin":194,"end":195,"name":"DUP1","source":1},{"begin":187,"end":199,"name":"REVERT","source":1},{"begin":334,"end":411,"name":"tag","source":1,"value":"15"},{"begin":334,"end":411,"name":"JUMPDEST","source":1},{"begin":371,"end":378,"name":"PUSH","source":1,"value":"0"},{"begin":400,"end":405,"name":"DUP2","source":1},{"begin":389,"end":405,"name":"SWAP1","source":1},{"begin":389,"end":405,"name":"POP","source":1},{"begin":334,"end":411,"name":"SWAP2","source":1},{"begin":334,"end":411,"name":"SWAP1","source":1},{"begin":334,"end":411,"name":"POP","source":1},{"begin":334,"end":411,"jumpType":"[out]","name":"JUMP","source":1},{"begin":417,"end":539,"name":"tag","source":1,"value":"16"},{"begin":417,"end":539,"name":"JUMPDEST","source":1},{"begin":490,"end":514,"name":"PUSH [tag]","source":1,"value":"25"},{"begin":508,"end":513,"name":"DUP2","source":1},{"begin":490,"end":514,"name":"PUSH [tag]","source":1,"value":"15"},{"begin":490,"end":514,"jumpType":"[in]","name":"JUMP","source":1},{"begin":490,"end":514,"name":"tag","source":1,"value":"25"},{"begin":490,"end":514,"name":"JUMPDEST","source":1},{"begin":483,"end":488,"name":"DUP2","source":1},{"begin":480,"end":515,"name":"EQ","source":1},{"begin":470,"end":533,"name":"PUSH [tag]","source":1,"value":"26"},{"begin":470,"end":533,"name":"JUMPI","source":1},{"begin":529,"end":530,"name":"PUSH","source":1,"value":"0"},{"begin":526,"end":527,"name":"DUP1","source":1},{"begin":519,"end":531,"name":"REVERT","source":1},{"begin":470,"end":533,"name":"tag","source":1,"value":"26"},{"begin":470,"end":533,"name":"JUMPDEST","source":1},{"begin":417,"end":539,"name":"POP","source":1},{"begin":417,"end":539,"jumpType":"[out]","name":"JUMP","source":1},{"begin":545,"end":684,"name":"tag","source":1,"value":"17"},{"begin":545,"end":684,"name":"JUMPDEST","source":1},{"begin":591,"end":596,"name":"PUSH","source":1,"value":"0"},{"begin":629,"end":635,"name":"DUP2","source":1},{"begin":616,"end":636,"name":"CALLDATALOAD","source":1},{"begin":607,"end":636,"name":"SWAP1","source":1},{"begin":607,"end":636,"name":"POP","source":1},{"begin":645,"end":678,"name":"PUSH [tag]","source":1,"value":"28"},{"begin":672,"end":677,"name":"DUP2","source":1},{"begin":645,"end":678,"name":"PUSH [tag]","source":1,"value":"16"},{"begin":645,"end":678,"jumpType":"[in]","name":"JUMP","source":1},{"begin":645,"end":678,"name":"tag","source":1,"value":"28"},{"begin":645,"end":678,"name":"JUMPDEST","source":1},{"begin":545,"end":684,"name":"SWAP3","source":1},{"begin":545,"end":684,"name":"SWAP2","source":1},{"begin":545,"end":684,"name":"POP","source":1},{"begin":545,"end":684,"name":"POP","source":1},{"begin":545,"end":684,"jumpType":"[out]","name":"JUMP","source":1},{"begin":690,"end":1019,"name":"tag","source":1,"value":"6"},{"begin":690,"end":1019,"name":"JUMPDEST","source":1},{"begin":749,"end":755,"name":"PUSH","source":1,"value":"0"},{"begin":798,"end":800,"name":"PUSH","source":1,"value":"20"},{"begin":786,"end":795,"name":"DUP3","source":1},{"begin":777,"end":784,"name":"DUP5","source":1},{"begin":773,"end":796,"name":"SUB","source":1},{"begin":769,"end":801,"name":"SLT","source":1},{"begin":766,"end":885,"name":"ISZERO","source":1},{"begin":766,"end":885,"name":"PUSH [tag]","source":1,"value":"30"},{"begin":766,"end":885,"name":"JUMPI","source":1},{"begin":804,"end":883,"name":"PUSH [tag]","source":1,"value":"31"},{"begin":804,"end":883,"name":"PUSH [tag]","source":1,"value":"13"},{"begin":804,"end":883,"jumpType":"[in]","name":"JUMP","source":1},{"begin":804,"end":883,"name":"tag","source":1,"value":"31"},{"begin":804,"end":883,"name":"JUMPDEST","source":1},{"begin":766,"end":885,"name":"tag","source":1,"value":"30"},{"begin":766,"end":885,"name":"JUMPDEST","source":1},{"begin":924,"end":925,"name":"PUSH","source":1,"value":"0"},{"begin":949,"end":1002,"name":"PUSH [tag]","source":1,"value":"32"},{"begin":994,"end":1001,"name":"DUP5","source":1},{"begin":985,"end":991,"name":"DUP3","source":1},{"begin":974,"end":983,"name":"DUP6","source":1},{"begin":970,"end":992,"name":"ADD","source":1},{"begin":949,"end":1002,"name":"PUSH [tag]","source":1,"value":"17"},{"begin":949,"end":1002,"jumpType":"[in]","name":"JUMP","source":1},{"begin":949,"end":1002,"name":"tag","source":1,"value":"32"},{"begin":949,"end":1002,"name":"JUMPDEST","source":1},{"begin":939,"end":1002,"name":"SWAP2","source":1},{"begin":939,"end":1002,"name":"POP","source":1},{"begin":895,"end":1012,"name":"POP","source":1},{"begin":690,"end":1019,"name":"SWAP3","source":1},{"begin":690,"end":1019,"name":"SWAP2","source":1},{"begin":690,"end":1019,"name":"POP","source":1},{"begin":690,"end":1019,"name":"POP","source":1},{"begin":690,"end":1019,"jumpType":"[out]","name":"JUMP","source":1},{"begin":1025,"end":1205,"name":"tag","source":1,"value":"18"},{"begin":1025,"end":1205,"name":"JUMPDEST","source":1},{"begin":1073,"end":1150,"name":"PUSH","source":1,"value":"4E487B7100000000000000000000000000000000000000000000000000000000"},{"begin":1070,"end":1071,"name":"PUSH","source":1,"value":"0"},{"begin":1063,"end":1151,"name":"MSTORE","source":1},{"begin":1170,"end":1174,"name":"PUSH","source":1,"value":"11"},{"begin":1167,"end":1168,"name":"PUSH","source":1,"value":"4"},{"begin":1160,"end":1175,"name":"MSTORE","source":1},{"begin":1194,"end":1198,"name":"PUSH","source":1,"value":"24"},{"begin":1191,"end":1192,"name":"PUSH","source":1,"value":"0"},{"begin":1184,"end":1199,"name":"REVERT","source":1},{"begin":1211,"end":1516,"name":"tag","source":1,"value":"10"},{"begin":1211,"end":1516,"name":"JUMPDEST","source":1},{"begin":1251,"end":1254,"name":"PUSH","source":1,"value":"0"},{"begin":1270,"end":1290,"name":"PUSH [tag]","source":1,"value":"35"},{"begin":1288,"end":1289,"name":"DUP3","source":1},{"begin":1270,"end":1290,"name":"PUSH [tag]","source":1,"value":"15"},{"begin":1270,"end":1290,"jumpType":"[in]","name":"JUMP","source":1},{"begin":1270,"end":1290,"name":"tag","source":1,"value":"35"},{"begin":1270,"end":1290,"name":"JUMPDEST","source":1},{"begin":1265,"end":1290,"name":"SWAP2","source":1},{"begin":1265,"end":1290,"name":"POP","source":1},{"begin":1304,"end":1324,"name":"PUSH [tag]","source":1,"value":"36"},{"begin":1322,"end":1323,"name":"DUP4","source":1},{"begin":1304,"end":1324,"name":"PUSH [tag]","source":1,"value":"15"},{"begin":1304,"end":1324,"jumpType":"[in]","name":"JUMP","source":1},{"begin":1304,"end":1324,"name":"tag","source":1,"value":"36"},{"begin":1304,"end":1324,"name":"JUMPDEST","source":1},{"begin":1299,"end":1324,"name":"SWAP3","source":1},{"begin":1299,"end":1324,"name":"POP","source":1},{"begin":1458,"end":1459,"name":"DUP3","source":1},{"begin":1390,"end":1456,"name":"PUSH","source":1,"value":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"},{"begin":1386,"end":1460,"name":"SUB","source":1},{"begin":1383,"end":1384,"name":"DUP3","source":1},{"begin":1380,"end":1461,"name":"GT","source":1},{"begin":1377,"end":1484,"name":"ISZERO","source":1},{"begin":1377,"end":1484,"name":"PUSH [tag]","source":1,"value":"37"},{"begin":1377,"end":1484,"name":"JUMPI","source":1},{"begin":1464,"end":1482,"name":"PUSH [tag]","source":1,"value":"38"},{"begin":1464,"end":1482,"name":"PUSH [tag]","source":1,"value":"18"},{"begin":1464,"end":1482,"jumpType":"[in]","name":"JUMP","source":1},{"begin":1464,"end":1482,"name":"tag","source":1,"value":"38"},{"begin":1464,"end":1482,"name":"JUMPDEST","source":1},{"begin":1377,"end":1484,"name":"tag","source":1,"value":"37"},{"begin":1377,"end":1484,"name":"JUMPDEST","source":1},{"begin":1508,"end":1509,"name":"DUP3","source":1},{"begin":1505,"end":1506,"name":"DUP3","source":1},{"begin":1501,"end":1510,"name":"ADD","source":1},{"begin":1494,"end":1510,"name":"SWAP1","source":1},{"begin":1494,"end":1510,"name":"POP","source":1},{"begin":1211,"end":1516,"name":"SWAP3","source":1},{"begin":1211,"end":1516,"name":"SWAP2","source":1},{"begin":1211,"end":1516,"name":"POP","source":1},{"begin":1211,"end":1516,"name":"POP","source":1},{"begin":1211,"end":1516,"jumpType":"[out]","name":"JUMP","source":1}]}},"sourceList":["asm_json_no_pretty_print/input.sol","#utility.yul"]} diff --git a/test/cmdlineTests/ast_compact_json_no_pretty_json/args b/test/cmdlineTests/ast_compact_json_no_pretty_json/args new file mode 100644 index 000000000..f60d99b44 --- /dev/null +++ b/test/cmdlineTests/ast_compact_json_no_pretty_json/args @@ -0,0 +1 @@ +--ast-compact-json --allow-paths . diff --git a/test/cmdlineTests/ast_compact_json_no_pretty_json/input.sol b/test/cmdlineTests/ast_compact_json_no_pretty_json/input.sol new file mode 100644 index 000000000..f123f6c8b --- /dev/null +++ b/test/cmdlineTests/ast_compact_json_no_pretty_json/input.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C {} diff --git a/test/cmdlineTests/ast_compact_json_no_pretty_json/output b/test/cmdlineTests/ast_compact_json_no_pretty_json/output new file mode 100644 index 000000000..abdc17125 --- /dev/null +++ b/test/cmdlineTests/ast_compact_json_no_pretty_json/output @@ -0,0 +1,5 @@ +JSON AST (compact format): + + +======= ast_compact_json_no_pretty_json/input.sol ======= +{"absolutePath":"ast_compact_json_no_pretty_json/input.sol","exportedSymbols":{"C":[2]},"id":3,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"canonicalName":"C","contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":2,"linearizedBaseContracts":[2],"name":"C","nameLocation":"69:1:0","nodeType":"ContractDefinition","nodes":[],"scope":3,"src":"60:13:0","usedErrors":[]}],"src":"36:38:0"} diff --git a/test/cmdlineTests/ast_compact_json_with_base_path/args b/test/cmdlineTests/ast_compact_json_with_base_path/args index 103ae311a..a30ef24c0 100644 --- a/test/cmdlineTests/ast_compact_json_with_base_path/args +++ b/test/cmdlineTests/ast_compact_json_with_base_path/args @@ -1 +1 @@ ---ast-compact-json --base-path . --allow-paths . +--ast-compact-json --pretty-json --base-path . --allow-paths . diff --git a/test/cmdlineTests/pretty_json_combined/args b/test/cmdlineTests/combined_json_abi/args similarity index 100% rename from test/cmdlineTests/pretty_json_combined/args rename to test/cmdlineTests/combined_json_abi/args diff --git a/test/cmdlineTests/pretty_json_combined/input.sol b/test/cmdlineTests/combined_json_abi/input.sol similarity index 100% rename from test/cmdlineTests/pretty_json_combined/input.sol rename to test/cmdlineTests/combined_json_abi/input.sol diff --git a/test/cmdlineTests/pretty_json_combined/output b/test/cmdlineTests/combined_json_abi/output similarity index 70% rename from test/cmdlineTests/pretty_json_combined/output rename to test/cmdlineTests/combined_json_abi/output index 6bed3b94d..c775c6d72 100644 --- a/test/cmdlineTests/pretty_json_combined/output +++ b/test/cmdlineTests/combined_json_abi/output @@ -1,7 +1,7 @@ { "contracts": { - "pretty_json_combined/input.sol:C": + "combined_json_abi/input.sol:C": { "abi": [] } diff --git a/test/cmdlineTests/combined_json_no_pretty_print/args b/test/cmdlineTests/combined_json_no_pretty_print/args new file mode 100644 index 000000000..92b156465 --- /dev/null +++ b/test/cmdlineTests/combined_json_no_pretty_print/args @@ -0,0 +1 @@ +--combined-json abi diff --git a/test/cmdlineTests/combined_json_no_pretty_print/input.sol b/test/cmdlineTests/combined_json_no_pretty_print/input.sol new file mode 100644 index 000000000..625af5682 --- /dev/null +++ b/test/cmdlineTests/combined_json_no_pretty_print/input.sol @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; +contract C {} diff --git a/test/cmdlineTests/combined_json_no_pretty_print/output b/test/cmdlineTests/combined_json_no_pretty_print/output new file mode 100644 index 000000000..081dc4fa4 --- /dev/null +++ b/test/cmdlineTests/combined_json_no_pretty_print/output @@ -0,0 +1 @@ +{"contracts":{"combined_json_no_pretty_print/input.sol:C":{"abi":[]}},"version": ""} diff --git a/test/cmdlineTests/combined_json_with_base_path/args b/test/cmdlineTests/combined_json_with_base_path/args index 0dec582ba..4e1f48462 100644 --- a/test/cmdlineTests/combined_json_with_base_path/args +++ b/test/cmdlineTests/combined_json_with_base_path/args @@ -1 +1 @@ ---combined-json ast --base-path . --allow-paths . +--combined-json ast --pretty-json --base-path . --allow-paths . diff --git a/test/cmdlineTests/combined_json_with_base_path/output b/test/cmdlineTests/combined_json_with_base_path/output index fe00b71a0..9acdea553 100644 --- a/test/cmdlineTests/combined_json_with_base_path/output +++ b/test/cmdlineTests/combined_json_with_base_path/output @@ -1 +1,111 @@ -{"contracts":{"combined_json_with_base_path/c.sol:C":{}},"sourceList":["combined_json_with_base_path/c.sol","combined_json_with_base_path/input.sol"],"sources":{"combined_json_with_base_path/c.sol":{"AST":{"absolutePath":"combined_json_with_base_path/c.sol","exportedSymbols":{"C":[5]},"id":6,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":4,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"canonicalName":"C","contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":5,"linearizedBaseContracts":[5],"name":"C","nameLocation":"69:1:0","nodeType":"ContractDefinition","nodes":[],"scope":6,"src":"60:13:0","usedErrors":[]}],"src":"36:38:0"}},"combined_json_with_base_path/input.sol":{"AST":{"absolutePath":"combined_json_with_base_path/input.sol","exportedSymbols":{"C":[5]},"id":3,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:1"},{"absolutePath":"combined_json_with_base_path/c.sol","file":"./c.sol","id":2,"nameLocation":"-1:-1:-1","nodeType":"ImportDirective","scope":3,"sourceUnit":6,"src":"60:17:1","symbolAliases":[],"unitAlias":""}],"src":"36:42:1"}}},"version": ""} +{ + "contracts": + { + "combined_json_with_base_path/c.sol:C": {} + }, + "sourceList": + [ + "combined_json_with_base_path/c.sol", + "combined_json_with_base_path/input.sol" + ], + "sources": + { + "combined_json_with_base_path/c.sol": + { + "AST": + { + "absolutePath": "combined_json_with_base_path/c.sol", + "exportedSymbols": + { + "C": + [ + 5 + ] + }, + "id": 6, + "license": "GPL-3.0", + "nodeType": "SourceUnit", + "nodes": + [ + { + "id": 4, + "literals": + [ + "solidity", + ">=", + "0.0" + ], + "nodeType": "PragmaDirective", + "src": "36:22:0" + }, + { + "abstract": false, + "baseContracts": [], + "canonicalName": "C", + "contractDependencies": [], + "contractKind": "contract", + "fullyImplemented": true, + "id": 5, + "linearizedBaseContracts": + [ + 5 + ], + "name": "C", + "nameLocation": "69:1:0", + "nodeType": "ContractDefinition", + "nodes": [], + "scope": 6, + "src": "60:13:0", + "usedErrors": [] + } + ], + "src": "36:38:0" + } + }, + "combined_json_with_base_path/input.sol": + { + "AST": + { + "absolutePath": "combined_json_with_base_path/input.sol", + "exportedSymbols": + { + "C": + [ + 5 + ] + }, + "id": 3, + "license": "GPL-3.0", + "nodeType": "SourceUnit", + "nodes": + [ + { + "id": 1, + "literals": + [ + "solidity", + ">=", + "0.0" + ], + "nodeType": "PragmaDirective", + "src": "36:22:1" + }, + { + "absolutePath": "combined_json_with_base_path/c.sol", + "file": "./c.sol", + "id": 2, + "nameLocation": "-1:-1:-1", + "nodeType": "ImportDirective", + "scope": 3, + "sourceUnit": 6, + "src": "60:17:1", + "symbolAliases": [], + "unitAlias": "" + } + ], + "src": "36:42:1" + } + } + }, + "version": "" +} diff --git a/test/cmdlineTests/combined_json_with_devdoc/args b/test/cmdlineTests/combined_json_with_devdoc/args new file mode 100644 index 000000000..dc55cdec7 --- /dev/null +++ b/test/cmdlineTests/combined_json_with_devdoc/args @@ -0,0 +1 @@ +--combined-json devdoc --pretty-json --allow-paths . diff --git a/test/cmdlineTests/combined_json_with_devdoc/input.sol b/test/cmdlineTests/combined_json_with_devdoc/input.sol new file mode 100644 index 000000000..6787b59b1 --- /dev/null +++ b/test/cmdlineTests/combined_json_with_devdoc/input.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +/// @dev This is devdoc. +contract C {} + +/// And this is a notice. +contract D {} diff --git a/test/cmdlineTests/combined_json_with_devdoc/output b/test/cmdlineTests/combined_json_with_devdoc/output new file mode 100644 index 000000000..d3df44a90 --- /dev/null +++ b/test/cmdlineTests/combined_json_with_devdoc/output @@ -0,0 +1,25 @@ +{ + "contracts": + { + "combined_json_with_devdoc/input.sol:C": + { + "devdoc": + { + "details": "This is devdoc.", + "kind": "dev", + "methods": {}, + "version": 1 + } + }, + "combined_json_with_devdoc/input.sol:D": + { + "devdoc": + { + "kind": "dev", + "methods": {}, + "version": 1 + } + } + }, + "version": "" +} diff --git a/test/cmdlineTests/combined_json_with_userdoc/args b/test/cmdlineTests/combined_json_with_userdoc/args new file mode 100644 index 000000000..b7c2697aa --- /dev/null +++ b/test/cmdlineTests/combined_json_with_userdoc/args @@ -0,0 +1 @@ +--combined-json userdoc --pretty-json --allow-paths . diff --git a/test/cmdlineTests/combined_json_with_userdoc/input.sol b/test/cmdlineTests/combined_json_with_userdoc/input.sol new file mode 100644 index 000000000..c6d37c8d4 --- /dev/null +++ b/test/cmdlineTests/combined_json_with_userdoc/input.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +/// @notice Description for users. +contract C {} + +/// @dev Description for developers. +contract D {} diff --git a/test/cmdlineTests/combined_json_with_userdoc/output b/test/cmdlineTests/combined_json_with_userdoc/output new file mode 100644 index 000000000..650981d67 --- /dev/null +++ b/test/cmdlineTests/combined_json_with_userdoc/output @@ -0,0 +1,25 @@ +{ + "contracts": + { + "combined_json_with_userdoc/input.sol:C": + { + "userdoc": + { + "kind": "user", + "methods": {}, + "notice": "Description for users.", + "version": 1 + } + }, + "combined_json_with_userdoc/input.sol:D": + { + "userdoc": + { + "kind": "user", + "methods": {}, + "version": 1 + } + } + }, + "version": "" +} diff --git a/test/cmdlineTests/recovery_ast_constructor/args b/test/cmdlineTests/recovery_ast_constructor/args index c7bde9942..8b7c575db 100644 --- a/test/cmdlineTests/recovery_ast_constructor/args +++ b/test/cmdlineTests/recovery_ast_constructor/args @@ -1 +1 @@ ---error-recovery --ast-compact-json --hashes +--error-recovery --ast-compact-json --pretty-json --hashes diff --git a/test/cmdlineTests/standard_json_no_pretty_print/args b/test/cmdlineTests/standard_json_no_pretty_print/args new file mode 100644 index 000000000..e69de29bb diff --git a/test/cmdlineTests/standard_json_no_pretty_print/input.json b/test/cmdlineTests/standard_json_no_pretty_print/input.json new file mode 100644 index 000000000..e9dc4cf38 --- /dev/null +++ b/test/cmdlineTests/standard_json_no_pretty_print/input.json @@ -0,0 +1,10 @@ +{ + "language": "Solidity", + "sources": + { + "A": + { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; contract C {}" + } + } +} diff --git a/test/cmdlineTests/standard_json_no_pretty_print/output.json b/test/cmdlineTests/standard_json_no_pretty_print/output.json new file mode 100644 index 000000000..59b90c8cc --- /dev/null +++ b/test/cmdlineTests/standard_json_no_pretty_print/output.json @@ -0,0 +1 @@ +{"sources":{"A":{"id":0}}} diff --git a/test/cmdlineTests/storage_layout_user_defined/args b/test/cmdlineTests/storage_layout_user_defined/args index f69ac4e39..0538465fe 100644 --- a/test/cmdlineTests/storage_layout_user_defined/args +++ b/test/cmdlineTests/storage_layout_user_defined/args @@ -1 +1 @@ ---storage-layout +--storage-layout --pretty-json diff --git a/test/cmdlineTests/storage_layout_user_defined/output b/test/cmdlineTests/storage_layout_user_defined/output index 0f6890dae..f79b8413e 100644 --- a/test/cmdlineTests/storage_layout_user_defined/output +++ b/test/cmdlineTests/storage_layout_user_defined/output @@ -1,4 +1,87 @@ ======= storage_layout_user_defined/input.sol:C ======= Contract Storage Layout: -{"storage":[{"astId":7,"contract":"storage_layout_user_defined/input.sol:C","label":"a","offset":0,"slot":"0","type":"t_userDefinedValueType(MyInt128)2"},{"astId":10,"contract":"storage_layout_user_defined/input.sol:C","label":"b","offset":16,"slot":"0","type":"t_userDefinedValueType(MyInt128)2"},{"astId":13,"contract":"storage_layout_user_defined/input.sol:C","label":"c","offset":0,"slot":"1","type":"t_userDefinedValueType(MyInt128)2"},{"astId":16,"contract":"storage_layout_user_defined/input.sol:C","label":"d","offset":16,"slot":"1","type":"t_userDefinedValueType(MyInt8)4"},{"astId":19,"contract":"storage_layout_user_defined/input.sol:C","label":"e","offset":17,"slot":"1","type":"t_userDefinedValueType(MyInt8)4"},{"astId":22,"contract":"storage_layout_user_defined/input.sol:C","label":"f","offset":18,"slot":"1","type":"t_userDefinedValueType(MyInt8)4"},{"astId":25,"contract":"storage_layout_user_defined/input.sol:C","label":"g","offset":19,"slot":"1","type":"t_userDefinedValueType(MyInt8)4"},{"astId":28,"contract":"storage_layout_user_defined/input.sol:C","label":"h","offset":20,"slot":"1","type":"t_userDefinedValueType(MyInt8)4"}],"types":{"t_userDefinedValueType(MyInt128)2":{"encoding":"inplace","label":"MyInt128","numberOfBytes":"16"},"t_userDefinedValueType(MyInt8)4":{"encoding":"inplace","label":"MyInt8","numberOfBytes":"1"}}} +{ + "storage": + [ + { + "astId": 7, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "a", + "offset": 0, + "slot": "0", + "type": "t_userDefinedValueType(MyInt128)2" + }, + { + "astId": 10, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "b", + "offset": 16, + "slot": "0", + "type": "t_userDefinedValueType(MyInt128)2" + }, + { + "astId": 13, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "c", + "offset": 0, + "slot": "1", + "type": "t_userDefinedValueType(MyInt128)2" + }, + { + "astId": 16, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "d", + "offset": 16, + "slot": "1", + "type": "t_userDefinedValueType(MyInt8)4" + }, + { + "astId": 19, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "e", + "offset": 17, + "slot": "1", + "type": "t_userDefinedValueType(MyInt8)4" + }, + { + "astId": 22, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "f", + "offset": 18, + "slot": "1", + "type": "t_userDefinedValueType(MyInt8)4" + }, + { + "astId": 25, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "g", + "offset": 19, + "slot": "1", + "type": "t_userDefinedValueType(MyInt8)4" + }, + { + "astId": 28, + "contract": "storage_layout_user_defined/input.sol:C", + "label": "h", + "offset": 20, + "slot": "1", + "type": "t_userDefinedValueType(MyInt8)4" + } + ], + "types": + { + "t_userDefinedValueType(MyInt128)2": + { + "encoding": "inplace", + "label": "MyInt128", + "numberOfBytes": "16" + }, + "t_userDefinedValueType(MyInt8)4": + { + "encoding": "inplace", + "label": "MyInt8", + "numberOfBytes": "1" + } + } +} diff --git a/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/args b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/args new file mode 100644 index 000000000..f69ac4e39 --- /dev/null +++ b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/args @@ -0,0 +1 @@ +--storage-layout diff --git a/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/input.sol b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/input.sol new file mode 100644 index 000000000..c80f7c736 --- /dev/null +++ b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/input.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL v3 +pragma solidity >=0.0; + +contract C {} diff --git a/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/output b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/output new file mode 100644 index 000000000..1be4da0b6 --- /dev/null +++ b/test/cmdlineTests/storage_layout_user_defined_no_pretty_print/output @@ -0,0 +1,4 @@ + +======= storage_layout_user_defined_no_pretty_print/input.sol:C ======= +Contract Storage Layout: +{"storage":[]} diff --git a/test/libsolidity/ASTJSONTest.cpp b/test/libsolidity/ASTJSONTest.cpp index 14e2c2a8a..a509adde6 100644 --- a/test/libsolidity/ASTJSONTest.cpp +++ b/test/libsolidity/ASTJSONTest.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -248,7 +249,7 @@ bool ASTJSONTest::runTest( for (size_t i = 0; i < m_sources.size(); i++) { ostringstream result; - ASTJsonConverter(_compiler.state(), _sourceIndices).print(result, _compiler.ast(m_sources[i].first)); + ASTJsonConverter(_compiler.state(), _sourceIndices).print(result, _compiler.ast(m_sources[i].first), JsonFormat{ JsonFormat::Pretty }); _variant.result += result.str(); if (i != m_sources.size() - 1) _variant.result += ",";