mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7161 from ethereum/permit-zerolength-dyn-array-dimensions
Dynamically sized array dimensions can be zero sized
This commit is contained in:
commit
967ee944a5
@ -328,13 +328,10 @@ void ProtoConverter::visit(StructType const&)
|
||||
|
||||
std::string ProtoConverter::arrayDimInfoAsString(ArrayDimensionInfo const& _x)
|
||||
{
|
||||
unsigned arrLength = getArrayLengthFromFuzz(_x.length());
|
||||
if (_x.is_static())
|
||||
return Whiskers(R"([<length>])")
|
||||
("length", std::to_string(arrLength))
|
||||
return Whiskers(R"([<?isStatic><length></isStatic>])")
|
||||
("isStatic", _x.is_static())
|
||||
("length", std::to_string(getStaticArrayLengthFromFuzz(_x.length())))
|
||||
.render();
|
||||
else
|
||||
return R"([])";
|
||||
}
|
||||
|
||||
void ProtoConverter::arrayDimensionsAsStringVector(
|
||||
@ -398,7 +395,7 @@ ProtoConverter::DataType ProtoConverter::getDataTypeByBaseType(ArrayType const&
|
||||
// Adds a resize operation for a given dimension of type `_type` and expression referenced
|
||||
// by `_var`. `_isStatic` is true for statically sized dimensions, false otherwise.
|
||||
// `_arrayLen` is equal to length of statically sized array dimension. For dynamically
|
||||
// sized dimension, we use `getArrayLengthFromFuzz()` and a monotonically increasing
|
||||
// sized dimension, we use `getDynArrayLengthFromFuzz()` and a monotonically increasing
|
||||
// counter to obtain actual length. Function returns dimension length.
|
||||
unsigned ProtoConverter::resizeDimension(
|
||||
bool _isStatic,
|
||||
@ -413,7 +410,7 @@ unsigned ProtoConverter::resizeDimension(
|
||||
length = _arrayLen;
|
||||
else
|
||||
{
|
||||
length = getArrayLengthFromFuzz(_arrayLen, getNextCounter());
|
||||
length = getDynArrayLengthFromFuzz(_arrayLen, getNextCounter());
|
||||
|
||||
// If local var, new T(l);
|
||||
// Else, l;
|
||||
|
@ -334,14 +334,28 @@ private:
|
||||
return toHex(maskUnsignedInt(_counter, _numMaskNibbles), HexPrefix::Add);
|
||||
}
|
||||
|
||||
static unsigned getArrayLengthFromFuzz(unsigned _fuzz, unsigned _counter = 0)
|
||||
/// Dynamically sized arrays can have a length of at least zero
|
||||
/// and at most s_maxArrayLength.
|
||||
static unsigned getDynArrayLengthFromFuzz(unsigned _fuzz, unsigned _counter)
|
||||
{
|
||||
return ((_fuzz + _counter) % s_maxArrayLength) + 1;
|
||||
// Increment modulo value by one in order to meet upper bound
|
||||
return (_fuzz + _counter) % (s_maxArrayLength + 1);
|
||||
}
|
||||
|
||||
/// Statically sized arrays must have a length of at least one
|
||||
/// and at most s_maxArrayLength.
|
||||
static unsigned getStaticArrayLengthFromFuzz(unsigned _fuzz)
|
||||
{
|
||||
return _fuzz % s_maxArrayLength + 1;
|
||||
}
|
||||
|
||||
static std::pair<bool, unsigned> arrayDimInfoAsPair(ArrayDimensionInfo const& _x)
|
||||
{
|
||||
return std::make_pair(_x.is_static(), getArrayLengthFromFuzz(_x.length()));
|
||||
return (
|
||||
_x.is_static() ?
|
||||
std::make_pair(true, getStaticArrayLengthFromFuzz(_x.length())) :
|
||||
std::make_pair(false, getDynArrayLengthFromFuzz(_x.length(), 0))
|
||||
);
|
||||
}
|
||||
|
||||
/// Contains the test program
|
||||
@ -360,7 +374,7 @@ private:
|
||||
unsigned m_varCounter;
|
||||
/// Monotonically increasing return value for error reporting
|
||||
unsigned m_returnValue;
|
||||
static unsigned constexpr s_maxArrayLength = 2;
|
||||
static unsigned constexpr s_maxArrayLength = 4;
|
||||
static unsigned constexpr s_maxArrayDimensions = 10;
|
||||
/// Prefixes for declared and parameterized variable names
|
||||
static auto constexpr s_varNamePrefix = "x_";
|
||||
|
Loading…
Reference in New Issue
Block a user