mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implement index access for storage arrays
This commit is contained in:
@@ -820,7 +820,45 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
|
||||
));
|
||||
}
|
||||
else if (baseType.category() == Type::Category::Array)
|
||||
solUnimplementedAssert(false, "");
|
||||
{
|
||||
ArrayType const& arrayType = dynamic_cast<ArrayType const&>(baseType);
|
||||
solAssert(_indexAccess.indexExpression(), "Index expression expected.");
|
||||
|
||||
switch (arrayType.location())
|
||||
{
|
||||
case DataLocation::Storage:
|
||||
{
|
||||
string slot = m_context.newYulVariable();
|
||||
string offset = m_context.newYulVariable();
|
||||
|
||||
m_code << Whiskers(R"(
|
||||
let <slot>, <offset> := <indexFunc>(<array>, <index>)
|
||||
)")
|
||||
("slot", slot)
|
||||
("offset", offset)
|
||||
("indexFunc", m_utils.storageArrayIndexAccessFunction(arrayType))
|
||||
("array", m_context.variable(_indexAccess.baseExpression()))
|
||||
("index", m_context.variable(*_indexAccess.indexExpression()))
|
||||
.render();
|
||||
|
||||
setLValue(_indexAccess, make_unique<IRStorageItem>(
|
||||
m_context,
|
||||
slot,
|
||||
offset,
|
||||
*_indexAccess.annotation().type
|
||||
));
|
||||
|
||||
break;
|
||||
}
|
||||
case DataLocation::Memory:
|
||||
solUnimplementedAssert(false, "");
|
||||
break;
|
||||
case DataLocation::CallData:
|
||||
solUnimplementedAssert(false, "");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else if (baseType.category() == Type::Category::FixedBytes)
|
||||
solUnimplementedAssert(false, "");
|
||||
else if (baseType.category() == Type::Category::TypeType)
|
||||
|
||||
@@ -135,7 +135,8 @@ string IRStorageItem::storeValue(string const& _value, Type const& _sourceType)
|
||||
|
||||
string IRStorageItem::setToZero() const
|
||||
{
|
||||
solUnimplemented("Delete for storage location not yet implemented");
|
||||
solUnimplementedAssert(m_type->isValueType(), "");
|
||||
return storeValue(m_context.utils().zeroValueFunction(*m_type) + "()", *m_type);
|
||||
}
|
||||
|
||||
IRStorageArrayLength::IRStorageArrayLength(IRGenerationContext& _context, string _slot, Type const& _type, ArrayType const& _arrayType):
|
||||
|
||||
Reference in New Issue
Block a user