mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move AST annotation of internal function dispatch IDs to ContractDefinition
Co-authored-by: Daniel <daniel@ekpyron.org> Co-authored-by: Nikola Matić <nikola.matic@ethereum.org>
This commit is contained in:
co-authored by
Daniel
Nikola Matić
parent
41742c5410
commit
a29f77369a
@@ -168,6 +168,9 @@ struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, StructurallyDocu
|
||||
/// List of contracts whose bytecode is referenced by this contract, e.g. through "new".
|
||||
/// The Value represents the ast node that referenced the contract.
|
||||
std::map<ContractDefinition const*, ASTNode const*, ASTCompareByID<ContractDefinition>> contractDependencies;
|
||||
|
||||
// Per-contract map from function AST IDs to internal dispatch function IDs.
|
||||
std::map<FunctionDefinition const*, uint64_t> internalFunctionIDs;
|
||||
};
|
||||
|
||||
struct CallableDeclarationAnnotation: DeclarationAnnotation
|
||||
@@ -178,7 +181,6 @@ struct CallableDeclarationAnnotation: DeclarationAnnotation
|
||||
|
||||
struct FunctionDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
||||
{
|
||||
util::SetOnce<uint64_t> internalFunctionID;
|
||||
};
|
||||
|
||||
struct EventDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
||||
|
||||
@@ -299,6 +299,14 @@ bool ASTJsonExporter::visit(ContractDefinition const& _node)
|
||||
if (!_node.annotation().linearizedBaseContracts.empty())
|
||||
attributes.emplace_back("linearizedBaseContracts", getContainerIds(_node.annotation().linearizedBaseContracts));
|
||||
|
||||
if (!_node.annotation().internalFunctionIDs.empty())
|
||||
{
|
||||
Json::Value internalFunctionIDs(Json::objectValue);
|
||||
for (auto const& [functionDefinition, internalFunctionID]: _node.annotation().internalFunctionIDs)
|
||||
internalFunctionIDs[to_string(functionDefinition->id())] = internalFunctionID;
|
||||
attributes.emplace_back("internalFunctionIDs", std::move(internalFunctionIDs));
|
||||
}
|
||||
|
||||
setJsonNode(_node, "ContractDefinition", std::move(attributes));
|
||||
return false;
|
||||
}
|
||||
@@ -473,9 +481,6 @@ bool ASTJsonExporter::visit(FunctionDefinition const& _node)
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
||||
|
||||
if (_node.annotation().internalFunctionID.set())
|
||||
attributes.emplace_back("internalFunctionID", *_node.annotation().internalFunctionID);
|
||||
|
||||
setJsonNode(_node, "FunctionDefinition", std::move(attributes));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ InternalDispatchMap IRGenerator::generateInternalDispatchFunctions(ContractDefin
|
||||
solAssert(m_context.functionCollector().contains(IRNames::function(*function)), "");
|
||||
|
||||
cases.emplace_back(map<string, string>{
|
||||
{"funID", to_string(*function->annotation().internalFunctionID)},
|
||||
{"funID", to_string(m_context.mostDerivedContract().annotation().internalFunctionIDs.at(function))},
|
||||
{"name", IRNames::function(*function)}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2807,7 +2807,7 @@ void IRGeneratorForStatements::assignInternalFunctionIDIfNotCalledDirectly(
|
||||
return;
|
||||
|
||||
define(IRVariable(_expression).part("functionIdentifier")) <<
|
||||
to_string(*_referencedFunction.annotation().internalFunctionID) <<
|
||||
to_string(m_context.mostDerivedContract().annotation().internalFunctionIDs.at(&_referencedFunction)) <<
|
||||
"\n";
|
||||
m_context.addToInternalDispatch(_referencedFunction);
|
||||
}
|
||||
|
||||
@@ -1246,7 +1246,6 @@ void CompilerStack::storeContractDefinitions()
|
||||
|
||||
void CompilerStack::annotateInternalFunctionIDs()
|
||||
{
|
||||
uint64_t internalFunctionID = 1;
|
||||
for (Source const* source: m_sourceOrder)
|
||||
{
|
||||
if (!source->ast)
|
||||
@@ -1254,20 +1253,23 @@ void CompilerStack::annotateInternalFunctionIDs()
|
||||
|
||||
for (ContractDefinition const* contract: ASTNode::filteredNodes<ContractDefinition>(source->ast->nodes()))
|
||||
{
|
||||
uint64_t internalFunctionID = 1;
|
||||
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++;
|
||||
{
|
||||
solAssert(contract->annotation().internalFunctionIDs.count(function) == 0);
|
||||
contract->annotation().internalFunctionIDs[function] = 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());
|
||||
solAssert(contract->annotation().internalFunctionIDs.count(function) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user