mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Mapping access with multi-slot keys.
This commit is contained in:
parent
2d48052ae5
commit
5e9637bc39
@ -2353,8 +2353,6 @@ string YulUtilFunctions::copyArrayFromStorageToMemoryFunction(ArrayType const& _
|
|||||||
|
|
||||||
string YulUtilFunctions::mappingIndexAccessFunction(MappingType const& _mappingType, Type const& _keyType)
|
string YulUtilFunctions::mappingIndexAccessFunction(MappingType const& _mappingType, Type const& _keyType)
|
||||||
{
|
{
|
||||||
solAssert(_keyType.sizeOnStack() <= 1, "");
|
|
||||||
|
|
||||||
string functionName = "mapping_index_access_" + _mappingType.identifier() + "_of_" + _keyType.identifier();
|
string functionName = "mapping_index_access_" + _mappingType.identifier() + "_of_" + _keyType.identifier();
|
||||||
return m_functionCollector.createFunction(functionName, [&]() {
|
return m_functionCollector.createFunction(functionName, [&]() {
|
||||||
if (_mappingType.keyType()->isDynamicallySized())
|
if (_mappingType.keyType()->isDynamicallySized())
|
||||||
@ -2364,7 +2362,7 @@ string YulUtilFunctions::mappingIndexAccessFunction(MappingType const& _mappingT
|
|||||||
}
|
}
|
||||||
)")
|
)")
|
||||||
("functionName", functionName)
|
("functionName", functionName)
|
||||||
("key", _keyType.sizeOnStack() > 0 ? "key" : "")
|
("key", suffixedVariableNameList("key_", 0, _keyType.sizeOnStack()))
|
||||||
("hash", packedHashFunction(
|
("hash", packedHashFunction(
|
||||||
{&_keyType, TypeProvider::uint256()},
|
{&_keyType, TypeProvider::uint256()},
|
||||||
{_mappingType.keyType(), TypeProvider::uint256()}
|
{_mappingType.keyType(), TypeProvider::uint256()}
|
||||||
|
@ -2062,7 +2062,6 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
|
|||||||
|
|
||||||
MappingType const& mappingType = dynamic_cast<MappingType const&>(baseType);
|
MappingType const& mappingType = dynamic_cast<MappingType const&>(baseType);
|
||||||
Type const& keyType = *_indexAccess.indexExpression()->annotation().type;
|
Type const& keyType = *_indexAccess.indexExpression()->annotation().type;
|
||||||
solAssert(keyType.sizeOnStack() <= 1, "");
|
|
||||||
|
|
||||||
string slot = m_context.newYulVariable();
|
string slot = m_context.newYulVariable();
|
||||||
Whiskers templ("let <slot> := <indexAccess>(<base><?+key>,<key></+key>)\n");
|
Whiskers templ("let <slot> := <indexAccess>(<base><?+key>,<key></+key>)\n");
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
contract C {
|
||||||
|
mapping (string => uint) m_nameToRecord;
|
||||||
|
function set(string calldata key, uint value) external {
|
||||||
|
m_nameToRecord[key] = value;
|
||||||
|
}
|
||||||
|
function get(string calldata key) external view returns (uint) {
|
||||||
|
return m_nameToRecord[key];
|
||||||
|
}
|
||||||
|
function setFixed(uint value) external {
|
||||||
|
m_nameToRecord["fixed"] = value;
|
||||||
|
}
|
||||||
|
function getFixed() external view returns (uint) {
|
||||||
|
return m_nameToRecord["fixed"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// set(string,uint256): 0x40, 8, 3, "abc" ->
|
||||||
|
// get(string): 0x20, 3, "abc" -> 8
|
||||||
|
// get(string): 0x20, 3, "abe" -> 0
|
||||||
|
// getFixed() -> 0
|
||||||
|
// setFixed(uint256): 9 ->
|
||||||
|
// getFixed() -> 9
|
Loading…
Reference in New Issue
Block a user