mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Minor refactoring
This commit is contained in:
parent
8c9c5b74ae
commit
3d8b9f03fe
@ -977,4 +977,39 @@ void YulProtoMutator::configureCall(FunctionCall *_call, unsigned int _seed)
|
|||||||
case FunctionCall_Returns_ZERO:
|
case FunctionCall_Returns_ZERO:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T YulProtoMutator::EnumTypeConverter<T>::validEnum(unsigned _seed)
|
||||||
|
{
|
||||||
|
auto ret = static_cast<T>(_seed % (enumMax() + 1) + enumMin());
|
||||||
|
if constexpr (std::is_same_v<std::decay_t<T>, FunctionCall_Returns>)
|
||||||
|
yulAssert(FunctionCall_Returns_IsValid(ret), "Yul proto mutator: Invalid enum");
|
||||||
|
else if constexpr (std::is_same_v<std::decay_t<T>, StoreFunc_Storage>)
|
||||||
|
yulAssert(StoreFunc_Storage_IsValid(ret), "Yul proto mutator: Invalid enum");
|
||||||
|
else
|
||||||
|
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
int YulProtoMutator::EnumTypeConverter<T>::enumMax()
|
||||||
|
{
|
||||||
|
if constexpr (std::is_same_v<std::decay_t<T>, FunctionCall_Returns>)
|
||||||
|
return FunctionCall_Returns_Returns_MAX;
|
||||||
|
else if constexpr (std::is_same_v<std::decay_t<T>, StoreFunc_Storage>)
|
||||||
|
return StoreFunc_Storage_Storage_MAX;
|
||||||
|
else
|
||||||
|
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
int YulProtoMutator::EnumTypeConverter<T>::enumMin()
|
||||||
|
{
|
||||||
|
if constexpr (std::is_same_v<std::decay_t<T>, FunctionCall_Returns>)
|
||||||
|
return FunctionCall_Returns_Returns_MIN;
|
||||||
|
else if constexpr (std::is_same_v<std::decay_t<T>, StoreFunc_Storage>)
|
||||||
|
return StoreFunc_Storage_Storage_MIN;
|
||||||
|
else
|
||||||
|
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
|
||||||
}
|
}
|
||||||
@ -55,29 +55,15 @@ struct YulProtoMutator
|
|||||||
{
|
{
|
||||||
T enumFromSeed(unsigned _seed)
|
T enumFromSeed(unsigned _seed)
|
||||||
{
|
{
|
||||||
// TODO: Assert validity of return enum.
|
return validEnum(_seed);
|
||||||
return static_cast<T>(_seed % (enumMax() + 1) + enumMin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int enumMax()
|
/// Return a valid enum of type T from _seed
|
||||||
{
|
T validEnum(unsigned _seed);
|
||||||
if constexpr (std::is_same_v<std::decay_t<T>, FunctionCall_Returns>)
|
/// Return maximum enum value for enum of type T
|
||||||
return FunctionCall_Returns_Returns_MAX;
|
static int enumMax();
|
||||||
else if constexpr (std::is_same_v<std::decay_t<T>, StoreFunc_Storage>)
|
/// Return minimum enum value for enum of type T
|
||||||
return StoreFunc_Storage_Storage_MAX;
|
static int enumMin();
|
||||||
else
|
|
||||||
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int enumMin()
|
|
||||||
{
|
|
||||||
if constexpr (std::is_same_v<std::decay_t<T>, FunctionCall_Returns>)
|
|
||||||
return FunctionCall_Returns_Returns_MIN;
|
|
||||||
else if constexpr (std::is_same_v<std::decay_t<T>, StoreFunc_Storage>)
|
|
||||||
return StoreFunc_Storage_Storage_MIN;
|
|
||||||
else
|
|
||||||
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr unsigned s_lowIP = 827;
|
static constexpr unsigned s_lowIP = 827;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user