aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorKhan M Rashedun-Naby <naby88@gmail.com>2018-06-24 10:15:25 +0800
committerKhan M Rashedun-Naby <naby88@gmail.com>2018-06-24 10:15:25 +0800
commit097a3fabf40af014320f383f916c524a5a44e78b (patch)
tree672f4ac836c2087fd2bd19666da777a5f0e62d9a /libsolidity
parent9b67bdb3f47754006e8c3d93cd72db2f0700b073 (diff)
downloaddexon-solidity-097a3fabf40af014320f383f916c524a5a44e78b.tar.gz
dexon-solidity-097a3fabf40af014320f383f916c524a5a44e78b.tar.zst
dexon-solidity-097a3fabf40af014320f383f916c524a5a44e78b.zip
RationalNumberType::isImplicitlyConvertibleTo Refactor
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index c4d97c64..f9a4b7d6 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -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