mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
IRGeneratorForStatements: Small refactor in endVisit(IndexAccess) for readability
This commit is contained in:
parent
16220db759
commit
5b70830a64
@ -2295,14 +2295,13 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
|
||||
}
|
||||
case DataLocation::Memory:
|
||||
{
|
||||
string indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType);
|
||||
string const memAddress =
|
||||
indexAccessFunction +
|
||||
"(" +
|
||||
IRVariable(_indexAccess.baseExpression()).part("mpos").name() +
|
||||
", " +
|
||||
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) +
|
||||
")";
|
||||
string const indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType);
|
||||
string const baseRef = IRVariable(_indexAccess.baseExpression()).part("mpos").name();
|
||||
string const indexExpression = expressionAsType(
|
||||
*_indexAccess.indexExpression(),
|
||||
*TypeProvider::uint256()
|
||||
);
|
||||
string const memAddress = indexAccessFunction + "(" + baseRef + ", " + indexExpression + ")";
|
||||
|
||||
setLValue(_indexAccess, IRLValue{
|
||||
*arrayType.baseType(),
|
||||
@ -2312,28 +2311,28 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
|
||||
}
|
||||
case DataLocation::CallData:
|
||||
{
|
||||
string indexAccessFunction = m_utils.calldataArrayIndexAccessFunction(arrayType);
|
||||
string const indexAccessFunctionCall =
|
||||
indexAccessFunction +
|
||||
"(" +
|
||||
IRVariable(_indexAccess.baseExpression()).commaSeparatedList() +
|
||||
", " +
|
||||
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) +
|
||||
")";
|
||||
string const indexAccessFunction = m_utils.calldataArrayIndexAccessFunction(arrayType);
|
||||
string const baseRef = IRVariable(_indexAccess.baseExpression()).commaSeparatedList();
|
||||
string const indexExpression = expressionAsType(
|
||||
*_indexAccess.indexExpression(),
|
||||
*TypeProvider::uint256()
|
||||
);
|
||||
string const calldataAddress = indexAccessFunction + "(" + baseRef + ", " + indexExpression + ")";
|
||||
|
||||
if (arrayType.isByteArrayOrString())
|
||||
define(_indexAccess) <<
|
||||
m_utils.cleanupFunction(*arrayType.baseType()) <<
|
||||
"(calldataload(" <<
|
||||
indexAccessFunctionCall <<
|
||||
calldataAddress <<
|
||||
"))\n";
|
||||
else if (arrayType.baseType()->isValueType())
|
||||
define(_indexAccess) <<
|
||||
m_utils.readFromCalldata(*arrayType.baseType()) <<
|
||||
"(" <<
|
||||
indexAccessFunctionCall <<
|
||||
calldataAddress <<
|
||||
")\n";
|
||||
else
|
||||
define(_indexAccess) << indexAccessFunctionCall << "\n";
|
||||
define(_indexAccess) << calldataAddress << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user