[yul] Functions: Remove dependency on AST ID.

This commit is contained in:
Alexander Arlt
2021-06-23 16:15:25 +02:00
committed by chriseth
parent e4cf371358
commit 8accf420ea
6 changed files with 64 additions and 24 deletions
@@ -1575,12 +1575,10 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
define(IRVariable(_memberAccess).part("self"), _memberAccess.expression());
solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static, "");
if (memberFunctionType->kind() == FunctionType::Kind::Internal)
{
auto const& functionDefinition = dynamic_cast<FunctionDefinition const&>(memberFunctionType->declaration());
define(IRVariable(_memberAccess).part("functionIdentifier")) << to_string(functionDefinition.id()) << "\n";
if (!_memberAccess.annotation().calledDirectly)
m_context.addToInternalDispatch(functionDefinition);
}
assignInternalFunctionIDIfNotCalledDirectly(
_memberAccess,
dynamic_cast<FunctionDefinition const&>(memberFunctionType->declaration())
);
else if (
memberFunctionType->kind() == FunctionType::Kind::ArrayPush ||
memberFunctionType->kind() == FunctionType::Kind::ArrayPop
@@ -1918,11 +1916,9 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
*_memberAccess.annotation().referencedDeclaration
).resolveVirtual(m_context.mostDerivedContract(), super);
define(_memberAccess) << to_string(resolvedFunctionDef.id()) << "\n";
solAssert(resolvedFunctionDef.functionType(true), "");
solAssert(resolvedFunctionDef.functionType(true)->kind() == FunctionType::Kind::Internal, "");
if (!_memberAccess.annotation().calledDirectly)
m_context.addToInternalDispatch(resolvedFunctionDef);
assignInternalFunctionIDIfNotCalledDirectly(_memberAccess, resolvedFunctionDef);
}
else if (auto const* variable = dynamic_cast<VariableDeclaration const*>(_memberAccess.annotation().referencedDeclaration))
handleVariableReference(*variable, _memberAccess);
@@ -1934,11 +1930,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
break;
case FunctionType::Kind::Internal:
if (auto const* function = dynamic_cast<FunctionDefinition const*>(_memberAccess.annotation().referencedDeclaration))
{
define(_memberAccess) << to_string(function->id()) << "\n";
if (!_memberAccess.annotation().calledDirectly)
m_context.addToInternalDispatch(*function);
}
assignInternalFunctionIDIfNotCalledDirectly(_memberAccess, *function);
else
solAssert(false, "Function not found in member access");
break;
@@ -2021,10 +2013,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
solAssert(funType->kind() == FunctionType::Kind::Internal, "");
solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static, "");
define(_memberAccess) << to_string(function->id()) << "\n";
if (!_memberAccess.annotation().calledDirectly)
m_context.addToInternalDispatch(*function);
assignInternalFunctionIDIfNotCalledDirectly(_memberAccess, *function);
}
else if (auto const* contract = dynamic_cast<ContractDefinition const*>(_memberAccess.annotation().referencedDeclaration))
{
@@ -2268,12 +2257,10 @@ void IRGeneratorForStatements::endVisit(Identifier const& _identifier)
{
solAssert(*_identifier.annotation().requiredLookup == VirtualLookup::Virtual, "");
FunctionDefinition const& resolvedFunctionDef = functionDef->resolveVirtual(m_context.mostDerivedContract());
define(_identifier) << to_string(resolvedFunctionDef.id()) << "\n";
solAssert(resolvedFunctionDef.functionType(true), "");
solAssert(resolvedFunctionDef.functionType(true)->kind() == FunctionType::Kind::Internal, "");
if (!_identifier.annotation().calledDirectly)
m_context.addToInternalDispatch(resolvedFunctionDef);
assignInternalFunctionIDIfNotCalledDirectly(_identifier, resolvedFunctionDef);
}
else if (VariableDeclaration const* varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
handleVariableReference(*varDecl, _identifier);
@@ -2592,6 +2579,25 @@ void IRGeneratorForStatements::appendBareCall(
appendCode() << templ.render();
}
void IRGeneratorForStatements::assignInternalFunctionIDIfNotCalledDirectly(
Expression const& _expression,
FunctionDefinition const& _referencedFunction
)
{
solAssert(
dynamic_cast<MemberAccess const*>(&_expression) ||
dynamic_cast<Identifier const*>(&_expression),
""
);
if (_expression.annotation().calledDirectly)
return;
define(IRVariable(_expression).part("functionIdentifier")) <<
to_string(m_context.internalFunctionID(_referencedFunction, false)) <<
"\n";
m_context.addToInternalDispatch(_referencedFunction);
}
IRVariable IRGeneratorForStatements::convert(IRVariable const& _from, Type const& _to)
{
if (_from.type() == _to)