@@ -1575,12 +1575,10 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
1575
1575
define (IRVariable (_memberAccess).part (" self" ), _memberAccess.expression ());
1576
1576
solAssert (*_memberAccess.annotation ().requiredLookup == VirtualLookup::Static, " " );
1577
1577
if (memberFunctionType->kind () == FunctionType::Kind::Internal)
1578
- {
1579
- auto const & functionDefinition = dynamic_cast <FunctionDefinition const &>(memberFunctionType->declaration ());
1580
- define (IRVariable (_memberAccess).part (" functionIdentifier" )) << to_string (functionDefinition.id ()) << " \n " ;
1581
- if (!_memberAccess.annotation ().calledDirectly )
1582
- m_context.addToInternalDispatch (functionDefinition);
1583
- }
1578
+ assignInternalFunctionIDIfNotCalledDirectly (
1579
+ _memberAccess,
1580
+ dynamic_cast <FunctionDefinition const &>(memberFunctionType->declaration ())
1581
+ );
1584
1582
else if (
1585
1583
memberFunctionType->kind () == FunctionType::Kind::ArrayPush ||
1586
1584
memberFunctionType->kind () == FunctionType::Kind::ArrayPop
@@ -1918,11 +1916,9 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
1918
1916
*_memberAccess.annotation ().referencedDeclaration
1919
1917
).resolveVirtual (m_context.mostDerivedContract (), super);
1920
1918
1921
- define (_memberAccess) << to_string (resolvedFunctionDef.id ()) << " \n " ;
1922
1919
solAssert (resolvedFunctionDef.functionType (true ), " " );
1923
1920
solAssert (resolvedFunctionDef.functionType (true )->kind () == FunctionType::Kind::Internal, " " );
1924
- if (!_memberAccess.annotation ().calledDirectly )
1925
- m_context.addToInternalDispatch (resolvedFunctionDef);
1921
+ assignInternalFunctionIDIfNotCalledDirectly (_memberAccess, resolvedFunctionDef);
1926
1922
}
1927
1923
else if (auto const * variable = dynamic_cast <VariableDeclaration const *>(_memberAccess.annotation ().referencedDeclaration ))
1928
1924
handleVariableReference (*variable, _memberAccess);
@@ -1934,11 +1930,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
1934
1930
break ;
1935
1931
case FunctionType::Kind::Internal:
1936
1932
if (auto const * function = dynamic_cast <FunctionDefinition const *>(_memberAccess.annotation ().referencedDeclaration ))
1937
- {
1938
- define (_memberAccess) << to_string (function->id ()) << " \n " ;
1939
- if (!_memberAccess.annotation ().calledDirectly )
1940
- m_context.addToInternalDispatch (*function);
1941
- }
1933
+ assignInternalFunctionIDIfNotCalledDirectly (_memberAccess, *function);
1942
1934
else
1943
1935
solAssert (false , " Function not found in member access" );
1944
1936
break ;
@@ -2021,10 +2013,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
2021
2013
solAssert (funType->kind () == FunctionType::Kind::Internal, " " );
2022
2014
solAssert (*_memberAccess.annotation ().requiredLookup == VirtualLookup::Static, " " );
2023
2015
2024
- define (_memberAccess) << to_string (function->id ()) << " \n " ;
2025
-
2026
- if (!_memberAccess.annotation ().calledDirectly )
2027
- m_context.addToInternalDispatch (*function);
2016
+ assignInternalFunctionIDIfNotCalledDirectly (_memberAccess, *function);
2028
2017
}
2029
2018
else if (auto const * contract = dynamic_cast <ContractDefinition const *>(_memberAccess.annotation ().referencedDeclaration ))
2030
2019
{
@@ -2268,12 +2257,10 @@ void IRGeneratorForStatements::endVisit(Identifier const& _identifier)
2268
2257
{
2269
2258
solAssert (*_identifier.annotation ().requiredLookup == VirtualLookup::Virtual, " " );
2270
2259
FunctionDefinition const & resolvedFunctionDef = functionDef->resolveVirtual (m_context.mostDerivedContract ());
2271
- define (_identifier) << to_string (resolvedFunctionDef.id ()) << " \n " ;
2272
2260
2273
2261
solAssert (resolvedFunctionDef.functionType (true ), " " );
2274
2262
solAssert (resolvedFunctionDef.functionType (true )->kind () == FunctionType::Kind::Internal, " " );
2275
- if (!_identifier.annotation ().calledDirectly )
2276
- m_context.addToInternalDispatch (resolvedFunctionDef);
2263
+ assignInternalFunctionIDIfNotCalledDirectly (_identifier, resolvedFunctionDef);
2277
2264
}
2278
2265
else if (VariableDeclaration const * varDecl = dynamic_cast <VariableDeclaration const *>(declaration))
2279
2266
handleVariableReference (*varDecl, _identifier);
@@ -2592,6 +2579,25 @@ void IRGeneratorForStatements::appendBareCall(
2592
2579
appendCode () << templ.render ();
2593
2580
}
2594
2581
2582
+ void IRGeneratorForStatements::assignInternalFunctionIDIfNotCalledDirectly (
2583
+ Expression const & _expression,
2584
+ FunctionDefinition const & _referencedFunction
2585
+ )
2586
+ {
2587
+ solAssert (
2588
+ dynamic_cast <MemberAccess const *>(&_expression) ||
2589
+ dynamic_cast <Identifier const *>(&_expression),
2590
+ " "
2591
+ );
2592
+ if (_expression.annotation ().calledDirectly )
2593
+ return ;
2594
+
2595
+ define (IRVariable (_expression).part (" functionIdentifier" )) <<
2596
+ to_string (m_context.internalFunctionID (_referencedFunction, false )) <<
2597
+ " \n " ;
2598
+ m_context.addToInternalDispatch (_referencedFunction);
2599
+ }
2600
+
2595
2601
IRVariable IRGeneratorForStatements::convert (IRVariable const & _from, Type const & _to)
2596
2602
{
2597
2603
if (_from.type () == _to)
0 commit comments