mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Annotate function ID of functions that may be called via the internal dispatch.
Co-authored-by: Daniel <daniel@ekpyron.org>
This commit is contained in:
co-authored by
Daniel
parent
e7ec40b1af
commit
a0e62bbd3d
@@ -526,6 +526,7 @@ bool CompilerStack::analyze()
|
||||
if (noErrors)
|
||||
{
|
||||
createAndAssignCallGraphs();
|
||||
annotateInternalFunctionIDs();
|
||||
findAndReportCyclicContractDependencies();
|
||||
}
|
||||
|
||||
@@ -1245,6 +1246,34 @@ void CompilerStack::storeContractDefinitions()
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerStack::annotateInternalFunctionIDs()
|
||||
{
|
||||
uint64_t internalFunctionID = 1;
|
||||
for (Source const* source: m_sourceOrder)
|
||||
{
|
||||
if (!source->ast)
|
||||
continue;
|
||||
|
||||
for (ContractDefinition const* contract: ASTNode::filteredNodes<ContractDefinition>(source->ast->nodes()))
|
||||
{
|
||||
ContractDefinitionAnnotation& annotation = contract->annotation();
|
||||
|
||||
if (auto const* deployTimeInternalDispatch = util::valueOrNullptr((*annotation.deployedCallGraph)->edges, CallGraph::SpecialNode::InternalDispatch))
|
||||
for (auto const& node: *deployTimeInternalDispatch)
|
||||
if (auto const* callable = get_if<CallableDeclaration const*>(&node))
|
||||
if (auto const* function = dynamic_cast<FunctionDefinition const*>(*callable))
|
||||
if (!function->annotation().internalFunctionID.set())
|
||||
function->annotation().internalFunctionID = internalFunctionID++;
|
||||
if (auto const* creationTimeInternalDispatch = util::valueOrNullptr((*annotation.creationCallGraph)->edges, CallGraph::SpecialNode::InternalDispatch))
|
||||
for (auto const& node: *creationTimeInternalDispatch)
|
||||
if (auto const* callable = get_if<CallableDeclaration const*>(&node))
|
||||
if (auto const* function = dynamic_cast<FunctionDefinition const*>(*callable))
|
||||
// Make sure the function already got an ID since it also occurs in the deploy-time internal dispatch.
|
||||
solAssert(function->annotation().internalFunctionID.set());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool onlySafeExperimentalFeaturesActivated(set<ExperimentalFeature> const& features)
|
||||
|
||||
@@ -415,6 +415,9 @@ private:
|
||||
/// Store the contract definitions in m_contracts.
|
||||
void storeContractDefinitions();
|
||||
|
||||
/// Annotate internal dispatch function Ids
|
||||
void annotateInternalFunctionIDs();
|
||||
|
||||
/// @returns true if the source is requested to be compiled.
|
||||
bool isRequestedSource(std::string const& _sourceName) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user