mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
RationalNumberType::isImplicitlyConvertibleTo Refactor
This commit is contained in:
parent
9b67bdb3f4
commit
097a3fabf4
@ -856,7 +856,9 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
|
||||
|
||||
bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
if (_convertTo.category() == Category::Integer)
|
||||
switch (_convertTo.category())
|
||||
{
|
||||
case Category::Integer:
|
||||
{
|
||||
if (m_value == rational(0))
|
||||
return true;
|
||||
@ -868,31 +870,33 @@ bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
if (m_value.numerator() <= (u256(-1) >> (256 - targetType.numBits() + forSignBit)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (targetType.isSigned())
|
||||
{
|
||||
if (-m_value.numerator() <= (u256(1) << (targetType.numBits() - forSignBit)))
|
||||
return true;
|
||||
}
|
||||
else if (targetType.isSigned() && -m_value.numerator() <= (u256(1) << (targetType.numBits() - forSignBit)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
else if (_convertTo.category() == Category::FixedPoint)
|
||||
case Category::FixedPoint:
|
||||
{
|
||||
if (auto fixed = fixedPointType())
|
||||
return fixed->isImplicitlyConvertibleTo(_convertTo);
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
else if (_convertTo.category() == Category::FixedBytes)
|
||||
case Category::FixedBytes:
|
||||
{
|
||||
FixedBytesType const& fixedBytes = dynamic_cast<FixedBytesType const&>(_convertTo);
|
||||
if (!isFractional())
|
||||
{
|
||||
if (integerType())
|
||||
return fixedBytes.numBytes() * 8 >= integerType()->numBits();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (isFractional())
|
||||
return false;
|
||||
if (integerType())
|
||||
return fixedBytes.numBytes() * 8 >= integerType()->numBits();
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
|
Loading…
Reference in New Issue
Block a user