diff options
author | chriseth <chris@ethereum.org> | 2018-06-26 23:54:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-26 23:54:09 +0800 |
commit | 503eb8caa53c1f6ef00cec1fee099b2457c304f4 (patch) | |
tree | a0a4a088142277d8ca0d18d9ce340f79e69cbb5c | |
parent | 4bb9fced1e45df87d21941c8964c113f6aa91a53 (diff) | |
parent | 097a3fabf40af014320f383f916c524a5a44e78b (diff) | |
download | dexon-solidity-503eb8caa53c1f6ef00cec1fee099b2457c304f4.tar.gz dexon-solidity-503eb8caa53c1f6ef00cec1fee099b2457c304f4.tar.zst dexon-solidity-503eb8caa53c1f6ef00cec1fee099b2457c304f4.zip |
Merge pull request #4342 from rnaby/l/a/Types
RationalNumberType::isImplicitlyConvertibleTo Refactor
-rw-r--r-- | libsolidity/ast/Types.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 68c53af1..69124705 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 (isFractional()) return false; @@ -870,31 +872,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 |