Skip to content

Commit

Permalink
iiiiiiiiii
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlt committed Apr 29, 2024
1 parent 92ef48e commit cb2b661
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
47 changes: 21 additions & 26 deletions libsolidity/interface/StandardCompiler.cpp
Expand Up @@ -521,20 +521,16 @@ std::optional<Json> 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,
Expand Down Expand Up @@ -660,19 +656,19 @@ std::variant<StandardCompiler::InputsAndSettings, Json> 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<std::string>();
if (sourceValue.contains("keccak256") && sourceValue["keccak256"].is_string())
hash = sourceValue["keccak256"].get<std::string>();

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>();
std::string content = sourceValue["content"].get<std::string>();
if (!hash.empty() && !hashMatchesContent(hash, content))
ret.errors.emplace_back(formatError(
Error::Type::IOError,
Expand All @@ -682,7 +678,7 @@ std::variant<StandardCompiler::InputsAndSettings, Json> 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(
Expand All @@ -692,7 +688,7 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
std::vector<std::string> 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.");
Expand Down Expand Up @@ -734,25 +730,25 @@ std::variant<StandardCompiler::InputsAndSettings, Json> 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(
Expand Down Expand Up @@ -920,11 +916,11 @@ std::variant<StandardCompiler::InputsAndSettings, Json> 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>();
std::string address = libraryValue.get<std::string>();

if (!boost::starts_with(address, "0x"))
return formatFatalError(
Expand Down Expand Up @@ -1010,12 +1006,11 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
return formatFatalError(Error::Type::JSONError, "settings.modelChecker.contracts is not a JSON object.");

std::map<std::string, std::set<std::string>> 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.");

Expand Down
4 changes: 2 additions & 2 deletions solc/CommandLineInterface.cpp
Expand Up @@ -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<std::string>() + ": " + name + "\n";
for (auto const& [name, value]: interfaceSymbols["methods"].items())
out += value.get<std::string>() + ": " + name + "\n";

if (interfaceSymbols.contains("errors"))
{
Expand Down
12 changes: 6 additions & 6 deletions test/libsolidity/GasTest.cpp
Expand Up @@ -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::string>() << ":" << std::endl;
for (auto& element : group)
_stream << _linePrefix << key << ":" << std::endl;
for (auto& [elementKey, value] : group.items())
{
_stream << _linePrefix << " ";
if (element.get<std::string>().empty())
if (elementKey.empty())
_stream << "fallback";
else
_stream << element.get<std::string>();
_stream << ": " << element.get<std::string>() << std::endl;
_stream << elementKey;
_stream << ": " << value.get<std::string>() << std::endl;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/StandardCompiler.cpp
Expand Up @@ -1221,7 +1221,7 @@ BOOST_AUTO_TEST_CASE(optimizer_settings_details_different)
optimizer["details"]["yulDetails"]["optimizerSteps"].get<std::string>() ==
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<unsigned>() == 600);
}

Expand Down
3 changes: 2 additions & 1 deletion test/solc/CommandLineInterface.cpp
Expand Up @@ -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",
Expand Down

0 comments on commit cb2b661

Please sign in to comment.