From 5b70830a6410ecfb935231b1c9f33a3b10687901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 13 Jul 2023 11:07:40 +0200 Subject: [PATCH] IRGeneratorForStatements: Small refactor in endVisit(IndexAccess) for readability --- .../codegen/ir/IRGeneratorForStatements.cpp | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index e4eaaf5e8..b2d9571d9 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -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; } }