IRGeneratorForStatements: Small refactor in endVisit(IndexAccess) for readability

This commit is contained in:
Kamil Śliwak 2023-07-13 11:07:40 +02:00
parent 16220db759
commit 5b70830a64

View File

@ -2295,14 +2295,13 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
} }
case DataLocation::Memory: case DataLocation::Memory:
{ {
string indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType); string const indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType);
string const memAddress = string const baseRef = IRVariable(_indexAccess.baseExpression()).part("mpos").name();
indexAccessFunction + string const indexExpression = expressionAsType(
"(" + *_indexAccess.indexExpression(),
IRVariable(_indexAccess.baseExpression()).part("mpos").name() + *TypeProvider::uint256()
", " + );
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) + string const memAddress = indexAccessFunction + "(" + baseRef + ", " + indexExpression + ")";
")";
setLValue(_indexAccess, IRLValue{ setLValue(_indexAccess, IRLValue{
*arrayType.baseType(), *arrayType.baseType(),
@ -2312,28 +2311,28 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
} }
case DataLocation::CallData: case DataLocation::CallData:
{ {
string indexAccessFunction = m_utils.calldataArrayIndexAccessFunction(arrayType); string const indexAccessFunction = m_utils.calldataArrayIndexAccessFunction(arrayType);
string const indexAccessFunctionCall = string const baseRef = IRVariable(_indexAccess.baseExpression()).commaSeparatedList();
indexAccessFunction + string const indexExpression = expressionAsType(
"(" + *_indexAccess.indexExpression(),
IRVariable(_indexAccess.baseExpression()).commaSeparatedList() + *TypeProvider::uint256()
", " + );
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) + string const calldataAddress = indexAccessFunction + "(" + baseRef + ", " + indexExpression + ")";
")";
if (arrayType.isByteArrayOrString()) if (arrayType.isByteArrayOrString())
define(_indexAccess) << define(_indexAccess) <<
m_utils.cleanupFunction(*arrayType.baseType()) << m_utils.cleanupFunction(*arrayType.baseType()) <<
"(calldataload(" << "(calldataload(" <<
indexAccessFunctionCall << calldataAddress <<
"))\n"; "))\n";
else if (arrayType.baseType()->isValueType()) else if (arrayType.baseType()->isValueType())
define(_indexAccess) << define(_indexAccess) <<
m_utils.readFromCalldata(*arrayType.baseType()) << m_utils.readFromCalldata(*arrayType.baseType()) <<
"(" << "(" <<
indexAccessFunctionCall << calldataAddress <<
")\n"; ")\n";
else else
define(_indexAccess) << indexAccessFunctionCall << "\n"; define(_indexAccess) << calldataAddress << "\n";
break; break;
} }
} }