Skip to content

Commit 3e7c68d

Browse files
committed
Merge identifier query methods into one
1 parent 9e62f21 commit 3e7c68d

File tree

9 files changed

+43
-48
lines changed

9 files changed

+43
-48
lines changed

libsolidity/interface/CompilerStack.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,46 +1014,31 @@ Json::Value const& CompilerStack::natspecDev(Contract const& _contract) const
10141014
return _contract.devDocumentation.init([&]{ return Natspec::devDocumentation(*_contract.contract); });
10151015
}
10161016

1017-
Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const
1017+
Json::Value CompilerStack::contractIdentifiers(string const& _contractName) const
10181018
{
10191019
if (m_stackState < AnalysisPerformed)
10201020
solThrow(CompilerError, "Analysis was not successful.");
10211021

1022-
Json::Value methodIdentifiers(Json::objectValue);
1023-
for (auto const& it: contractDefinition(_contractName).interfaceFunctions())
1024-
methodIdentifiers[it.second->externalSignature()] = it.first.hex();
1025-
return methodIdentifiers;
1026-
}
1022+
Json::Value contractIdentifiers(Json::objectValue);
1023+
// Always have a methods object
1024+
contractIdentifiers["methods"] = Json::objectValue;
10271025

1028-
Json::Value CompilerStack::errorIdentifiers(string const& _contractName) const
1029-
{
1030-
if (m_stackState < AnalysisPerformed)
1031-
solThrow(CompilerError, "Analysis was not successful.");
1032-
1033-
Json::Value errorIdentifiers(Json::objectValue);
1026+
for (auto const& it: contractDefinition(_contractName).interfaceFunctions())
1027+
contractIdentifiers["methods"][it.second->externalSignature()] = it.first.hex();
10341028
for (ErrorDefinition const* error: contractDefinition(_contractName).interfaceErrors())
10351029
{
10361030
string signature = error->functionType(true)->externalSignature();
1037-
errorIdentifiers[signature] = toHex(toCompactBigEndian(selectorFromSignature32(signature), 4));
1031+
contractIdentifiers["errors"][signature] = toHex(toCompactBigEndian(selectorFromSignature32(signature), 4));
10381032
}
10391033

1040-
return errorIdentifiers;
1041-
}
1042-
1043-
Json::Value CompilerStack::eventIdentifiers(string const& _contractName) const
1044-
{
1045-
if (m_stackState < AnalysisPerformed)
1046-
solThrow(CompilerError, "Analysis was not successful.");
1047-
1048-
Json::Value eventIdentifiers(Json::objectValue);
10491034
for (EventDefinition const* event: contractDefinition(_contractName).interfaceEvents())
10501035
if (!event->isAnonymous())
10511036
{
10521037
string signature = event->functionType(true)->externalSignature();
1053-
eventIdentifiers[signature] = toHex(u256(h256::Arith(keccak256(signature))));
1038+
contractIdentifiers["events"][signature] = toHex(u256(h256::Arith(keccak256(signature))));
10541039
}
10551040

1056-
return eventIdentifiers;
1041+
return contractIdentifiers;
10571042
}
10581043

10591044
bytes CompilerStack::cborMetadata(string const& _contractName, bool _forIR) const

libsolidity/interface/CompilerStack.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,8 @@ class CompilerStack: public langutil::CharStreamProvider
327327
/// Prerequisite: Successful call to parse or compile.
328328
Json::Value const& natspecDev(std::string const& _contractName) const;
329329

330-
/// @returns a JSON representing a map of method identifiers (hashes) to function names.
331-
Json::Value methodIdentifiers(std::string const& _contractName) const;
332-
333-
/// @returns a JSON representing a map of error identifiers (hashes) to error names.
334-
Json::Value errorIdentifiers(std::string const& _contractName) const;
335-
336-
/// @returns a JSON representing a map of event identifiers (hashes) to event names.
337-
Json::Value eventIdentifiers(std::string const& _contractName) const;
330+
/// @returns a JSON object with the three members ``methods``, ``events``, ``errors``. Each is a map, mapping identifiers (hashes) to function names.
331+
Json::Value contractIdentifiers(std::string const& _contractName) const;
338332

339333
/// @returns the Contract Metadata matching the pipeline selected using the viaIR setting.
340334
std::string const& metadata(std::string const& _contractName) const { return metadata(contract(_contractName)); }

libsolidity/interface/StandardCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
12981298
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "evm.legacyAssembly", wildcardMatchesExperimental))
12991299
evmData["legacyAssembly"] = compilerStack.assemblyJSON(contractName);
13001300
if (isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "evm.methodIdentifiers", wildcardMatchesExperimental))
1301-
evmData["methodIdentifiers"] = compilerStack.methodIdentifiers(contractName);
1301+
evmData["methodIdentifiers"] = compilerStack.contractIdentifiers(contractName)["methods"];
13021302
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "evm.gasEstimates", wildcardMatchesExperimental))
13031303
evmData["gasEstimates"] = compilerStack.gasEstimates(contractName);
13041304

solc/CommandLineInterface.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,23 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
270270
if (!m_options.compiler.outputs.signatureHashes)
271271
return;
272272

273-
Json::Value methodIdentifiers = m_compiler->methodIdentifiers(_contract);
273+
Json::Value contractIdentifiers = m_compiler->contractIdentifiers(_contract);
274274
string out = "Function signatures:\n";
275-
for (auto const& name: methodIdentifiers.getMemberNames())
276-
out += methodIdentifiers[name].asString() + ": " + name + "\n";
275+
for (auto const& name: contractIdentifiers["methods"].getMemberNames())
276+
out += contractIdentifiers["methods"][name].asString() + ": " + name + "\n";
277277

278-
Json::Value errorIdentifiers = m_compiler->errorIdentifiers(_contract);
279-
if (!errorIdentifiers.empty())
278+
if (contractIdentifiers.isMember("errors"))
280279
{
281280
out += "\nError signatures:\n";
282-
for (auto const& name: errorIdentifiers.getMemberNames())
283-
out += errorIdentifiers[name].asString() + ": " + name + "\n";
281+
for (auto const& name: contractIdentifiers["errors"].getMemberNames())
282+
out += contractIdentifiers["errors"][name].asString() + ": " + name + "\n";
284283
}
285284

286-
Json::Value eventIdentifiers = m_compiler->eventIdentifiers(_contract);
287-
if (!eventIdentifiers.empty())
285+
if (contractIdentifiers.isMember("events"))
288286
{
289287
out += "\nEvent signatures:\n";
290-
for (auto const& name: eventIdentifiers.getMemberNames())
291-
out += eventIdentifiers[name].asString() + ": " + name + "\n";
288+
for (auto const& name: contractIdentifiers["events"].getMemberNames())
289+
out += contractIdentifiers["events"][name].asString() + ": " + name + "\n";
292290
}
293291

294292
if (!m_options.output.dir.empty())
@@ -838,7 +836,7 @@ void CommandLineInterface::handleCombinedJSON()
838836
m_compiler->runtimeObject(contractName).functionDebugData
839837
);
840838
if (m_options.compiler.combinedJsonRequests->signatureHashes)
841-
contractData[g_strSignatureHashes] = m_compiler->methodIdentifiers(contractName);
839+
contractData[g_strSignatureHashes] = m_compiler->contractIdentifiers(contractName)["methods"];
842840
if (m_options.compiler.combinedJsonRequests->natspecDev)
843841
contractData[g_strNatspecDev] = m_compiler->natspecDev(contractName);
844842
if (m_options.compiler.combinedJsonRequests->natspecUser)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"language": "Solidity",
3+
"sources":
4+
{
5+
"A":
6+
{
7+
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; contract C { }"
8+
}
9+
},
10+
"settings":
11+
{
12+
"outputSelection":
13+
{
14+
"*": { "*": ["evm.methodIdentifiers"] }
15+
}
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"contracts":{"A":{"C":{"evm":{"methodIdentifiers":{}}}}},"sources":{"A":{"id":0}}}

test/libsolidity/SemanticTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ TestCase::TestResult SemanticTest::runTest(
435435
{
436436
soltestAssert(
437437
m_allowNonExistingFunctions ||
438-
m_compiler.methodIdentifiers(m_compiler.lastContractName(m_sources.mainSourceFile)).isMember(test.call().signature),
438+
m_compiler.contractIdentifiers(m_compiler.lastContractName(m_sources.mainSourceFile))["methods"].isMember(test.call().signature),
439439
"The function " + test.call().signature + " is not known to the compiler"
440440
);
441441

test/tools/ossfuzz/SolidityEvmoneInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ optional<CompilerOutput> SolidityCompilationFramework::compileContract()
5858
else
5959
contractName = m_compilerInput.contractName;
6060
evmasm::LinkerObject obj = m_compiler.object(contractName);
61-
Json::Value methodIdentifiers = m_compiler.methodIdentifiers(contractName);
61+
Json::Value methodIdentifiers = m_compiler.contractIdentifiers(contractName)["methods"];
6262
return CompilerOutput{obj.bytecode, methodIdentifiers};
6363
}
6464
}

test/tools/ossfuzz/SolidityEvmoneInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SolidityCompilationFramework
9191
/// @returns method identifiers in contract called @param _contractName.
9292
Json::Value methodIdentifiers(std::string const& _contractName)
9393
{
94-
return m_compiler.methodIdentifiers(_contractName);
94+
return m_compiler.contractIdentifiers(_contractName)["methods"];
9595
}
9696
/// @returns Compilation output comprising EVM bytecode and list of
9797
/// method identifiers in contract if compilation is successful,

0 commit comments

Comments
 (0)