From cb2b661fc26502fe3a2463dcd31e6f421433ed2b Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Mon, 29 Apr 2024 22:22:26 +0200 Subject: [PATCH] iiiiiiiiii --- libsolidity/interface/StandardCompiler.cpp | 47 ++++++++++------------ solc/CommandLineInterface.cpp | 4 +- test/libsolidity/GasTest.cpp | 12 +++--- test/libsolidity/StandardCompiler.cpp | 2 +- test/solc/CommandLineInterface.cpp | 3 +- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 63e948cc433e..09c52f0100a0 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -521,20 +521,16 @@ std::optional checkOutputSelection(Json const& _outputSelection) if (!_outputSelection.empty() && !_outputSelection.is_object()) return formatFatalError(Error::Type::JSONError, "\"settings.outputSelection\" must be an object"); - for (auto const& [sourceName, _]: _outputSelection.items()) + for (auto const& [sourceName, sourceVal]: _outputSelection.items()) { - auto const& sourceVal = _outputSelection[sourceName]; - if (!sourceVal.is_object()) return formatFatalError( Error::Type::JSONError, "\"settings.outputSelection." + sourceName + "\" must be an object" ); - for (auto const& [contractName, _]: sourceVal.items()) + for (auto const& [contractName, contractVal]: sourceVal.items()) { - auto const& contractVal = sourceVal[contractName]; - if (!contractVal.is_array()) return formatFatalError( Error::Type::JSONError, @@ -660,19 +656,19 @@ std::variant StandardCompiler::parseI if (ret.language == "Solidity" || ret.language == "Yul") { - for (auto const& [sourceName, _]: sources.items()) + for (auto const& [sourceName, sourceValue]: sources.items()) { std::string hash; - if (auto result = checkSourceKeys(sources[sourceName], sourceName)) + if (auto result = checkSourceKeys(sourceValue, sourceName)) return *result; - if (sources[sourceName].contains("keccak256") && sources[sourceName]["keccak256"].is_string()) - hash = sources[sourceName]["keccak256"].get(); + if (sourceValue.contains("keccak256") && sourceValue["keccak256"].is_string()) + hash = sourceValue["keccak256"].get(); - if (sources[sourceName].contains("content") && sources[sourceName]["content"].is_string()) + if (sourceValue.contains("content") && sourceValue["content"].is_string()) { - std::string content = sources[sourceName]["content"].get(); + std::string content = sourceValue["content"].get(); if (!hash.empty() && !hashMatchesContent(hash, content)) ret.errors.emplace_back(formatError( Error::Type::IOError, @@ -682,7 +678,7 @@ std::variant StandardCompiler::parseI else ret.sources[sourceName] = content; } - else if (sources[sourceName]["urls"].is_array()) + else if (sourceValue["urls"].is_array()) { if (!m_readFile) return formatFatalError( @@ -692,7 +688,7 @@ std::variant StandardCompiler::parseI std::vector failures; bool found = false; - for (auto const& url: sources[sourceName]["urls"]) + for (auto const& url: sourceValue["urls"]) { if (!url.is_string()) return formatFatalError(Error::Type::JSONError, "URL must be a string."); @@ -734,25 +730,25 @@ std::variant StandardCompiler::parseI } else if (ret.language == "SolidityAST") { - for (auto const& [sourceName, _]: sources.items()) - ret.sources[sourceName] = util::jsonCompactPrint(sources[sourceName]); + for (auto const& [sourceName, sourceValue]: sources.items()) + ret.sources[sourceName] = util::jsonCompactPrint(sourceValue); } else if (ret.language == "EVMAssembly") { - for (auto const& [sourceName, _]: sources.items()) + for (auto const& [sourceName, sourceValue]: sources.items()) { solAssert(sources.contains(sourceName)); if ( - !sources[sourceName].contains("assemblyJson") || - !sources[sourceName]["assemblyJson"].is_object() || - sources[sourceName].size() != 1 + !sourceValue.contains("assemblyJson") || + !sourceValue["assemblyJson"].is_object() || + sourceValue.size() != 1 ) return formatFatalError( Error::Type::JSONError, "Invalid input source specified. Expected exactly one object, named 'assemblyJson', inside $.sources." + sourceName ); - ret.jsonSources[sourceName] = sources[sourceName]["assemblyJson"]; + ret.jsonSources[sourceName] = sourceValue["assemblyJson"]; } if (ret.jsonSources.size() != 1) return formatFatalError( @@ -920,11 +916,11 @@ std::variant StandardCompiler::parseI { if (!jsonSourceName.is_object()) return formatFatalError(Error::Type::JSONError, "Library entry is not a JSON object."); - for (auto const& [library, _]: jsonSourceName.items()) + for (auto const& [library, libraryValue]: jsonSourceName.items()) { - if (!jsonSourceName[library].is_string()) + if (!libraryValue.is_string()) return formatFatalError(Error::Type::JSONError, "Library address must be a string."); - std::string address = jsonSourceName[library].get(); + std::string address = libraryValue.get(); if (!boost::starts_with(address, "0x")) return formatFatalError( @@ -1010,12 +1006,11 @@ std::variant StandardCompiler::parseI return formatFatalError(Error::Type::JSONError, "settings.modelChecker.contracts is not a JSON object."); std::map> sourceContracts; - for (auto const& [source, _]: sources.items()) + for (auto const& [source, contracts]: sources.items()) { if (source.empty()) return formatFatalError(Error::Type::JSONError, "Source name cannot be empty."); - auto const& contracts = sources[source]; if (!contracts.is_array()) return formatFatalError(Error::Type::JSONError, "Source contracts must be an array."); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index db21c3c49268..514f84c209df 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -355,8 +355,8 @@ void CommandLineInterface::handleSignatureHashes(std::string const& _contract) Json interfaceSymbols = m_compiler->interfaceSymbols(_contract); std::string out = "Function signatures:\n"; - for (auto const& [name, _]: interfaceSymbols["methods"].items()) - out += interfaceSymbols["methods"][name].get() + ": " + name + "\n"; + for (auto const& [name, value]: interfaceSymbols["methods"].items()) + out += value.get() + ": " + name + "\n"; if (interfaceSymbols.contains("errors")) { diff --git a/test/libsolidity/GasTest.cpp b/test/libsolidity/GasTest.cpp index 9bb3d26f95e1..14722535e446 100644 --- a/test/libsolidity/GasTest.cpp +++ b/test/libsolidity/GasTest.cpp @@ -83,17 +83,17 @@ void GasTest::parseExpectations(std::istream& _stream) void GasTest::printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const { Json estimates = compiler().gasEstimates(compiler().lastContractName()); - for (auto& group : estimates) + for (auto& [key, group] : estimates.items()) { - _stream << _linePrefix << group.get() << ":" << std::endl; - for (auto& element : group) + _stream << _linePrefix << key << ":" << std::endl; + for (auto& [elementKey, value] : group.items()) { _stream << _linePrefix << " "; - if (element.get().empty()) + if (elementKey.empty()) _stream << "fallback"; else - _stream << element.get(); - _stream << ": " << element.get() << std::endl; + _stream << elementKey; + _stream << ": " << value.get() << std::endl; } } } diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 690d8d645082..cdb6c5bd2d9d 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -1221,7 +1221,7 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_different) optimizer["details"]["yulDetails"]["optimizerSteps"].get() == OptimiserSettings::DefaultYulOptimiserSteps + ":"s + OptimiserSettings::DefaultYulOptimiserCleanupSteps ); -// BOOST_CHECK_EQUAL(optimizer["details"].getMemberNames().size(), 10); + BOOST_CHECK_EQUAL(optimizer["details"].size(), 10); BOOST_CHECK(optimizer["runs"].get() == 600); } diff --git a/test/solc/CommandLineInterface.cpp b/test/solc/CommandLineInterface.cpp index 77785b392c1b..b3b93cb3aa11 100644 --- a/test/solc/CommandLineInterface.cpp +++ b/test/solc/CommandLineInterface.cpp @@ -1110,12 +1110,13 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths) TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME); TemporaryWorkingDirectory tempWorkDir(tempDir); - std::string mainContractSource = withPreamble( + std::string const mainContractSource = withPreamble( "import 'contract_via_callback.sol';\n" "import 'include_via_callback.sol';\n" "import 'nested_via_callback.sol';\n" "import 'lib_via_callback.sol';\n" ); + std::string const standardJsonInput = R"( { "language": "Solidity",