mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
More flexible array literals.
This commit is contained in:
@@ -3256,6 +3256,11 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
|
||||
solAssert(_to.category() == Type::Category::Array, "");
|
||||
return arrayConversionFunction(fromArrayType, dynamic_cast<ArrayType const&>(_to));
|
||||
}
|
||||
else if (auto tupleType = dynamic_cast<TupleType const*>(&_from))
|
||||
{
|
||||
if (tupleType->isArrayLiteral())
|
||||
return arrayLiteralConversionFunction(*tupleType, dynamic_cast<ArrayType const&>(_to));
|
||||
}
|
||||
|
||||
if (_from.sizeOnStack() != 1 || _to.sizeOnStack() != 1)
|
||||
return conversionFunctionSpecial(_from, _to);
|
||||
@@ -3418,10 +3423,8 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
|
||||
break;
|
||||
}
|
||||
case Type::Category::Tuple:
|
||||
{
|
||||
solUnimplementedAssert(false, "Tuple conversion not implemented.");
|
||||
solAssert(false, "");
|
||||
break;
|
||||
}
|
||||
case Type::Category::TypeType:
|
||||
{
|
||||
TypeType const& typeType = dynamic_cast<decltype(typeType)>(_from);
|
||||
@@ -3704,6 +3707,34 @@ string YulUtilFunctions::arrayConversionFunction(ArrayType const& _from, ArrayTy
|
||||
});
|
||||
}
|
||||
|
||||
string YulUtilFunctions::arrayLiteralConversionFunction(TupleType const& _from, ArrayType const& _to)
|
||||
{
|
||||
solUnimplementedAssert(_to.dataStoredIn(DataLocation::Memory, "");
|
||||
|
||||
string functionName =
|
||||
"convert_arrayliteral_" +
|
||||
_from.identifier() +
|
||||
"_to_" +
|
||||
_to.identifier();
|
||||
|
||||
return m_functionCollector.createFunction(functionName, [&](vector<string>& _args, vector<string>& _ret) {
|
||||
_args = _from.stackItems();
|
||||
_ret = "converted";
|
||||
Whiskers templ(R"(
|
||||
// Copy the array to a free position in memory
|
||||
converted := <allocate>(<length>)
|
||||
<?dynamic>
|
||||
mstore(converted, <length>)
|
||||
</dynamic>
|
||||
<#items>
|
||||
mstore(<pos>, <var>)
|
||||
</items>
|
||||
)");
|
||||
return templ.render();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
string YulUtilFunctions::cleanupFunction(Type const& _type)
|
||||
{
|
||||
if (auto userDefinedValueType = dynamic_cast<UserDefinedValueType const*>(&_type))
|
||||
|
||||
@@ -530,6 +530,8 @@ private:
|
||||
/// Special case of conversion functions - handles all array conversions.
|
||||
std::string arrayConversionFunction(ArrayType const& _from, ArrayType const& _to);
|
||||
|
||||
std::string arrayLiteralConversionFunction(TupleType const& _from, ArrayType const& _to);
|
||||
|
||||
/// Special case of conversionFunction - handles everything that does not
|
||||
/// use exactly one variable to hold the value.
|
||||
std::string conversionFunctionSpecial(Type const& _from, Type const& _to);
|
||||
|
||||
Reference in New Issue
Block a user