diff options
author | Christian <c@ethdev.com> | 2014-11-05 15:40:21 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-06 09:44:43 +0800 |
commit | 627c80f0a8b37426c2c6625ff4852d77e4d43464 (patch) | |
tree | 496c5f2bdcd6d5c3bb92556081f707cdefac9d47 /Types.cpp | |
parent | b5e77678c9257f97be89139cf1d12bfa178147ef (diff) | |
download | dexon-solidity-627c80f0a8b37426c2c6625ff4852d77e4d43464.tar.gz dexon-solidity-627c80f0a8b37426c2c6625ff4852d77e4d43464.tar.zst dexon-solidity-627c80f0a8b37426c2c6625ff4852d77e4d43464.zip |
Support for negative literals.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -89,10 +89,14 @@ shared_ptr<Type> Type::forLiteral(Literal const& _literal) shared_ptr<IntegerType> IntegerType::smallestTypeForLiteral(string const& _literal) { bigint value(_literal); + bool isSigned = value < 0 || (!_literal.empty() && _literal.front() == '-'); + if (isSigned) + // convert to positive number of same bit requirements + value = ((-value) - 1) << 1; unsigned bytes = max(bytesRequired(value), 1u); if (bytes > 32) return shared_ptr<IntegerType>(); - return make_shared<IntegerType>(bytes * 8, Modifier::UNSIGNED); + return make_shared<IntegerType>(bytes * 8, isSigned ? Modifier::SIGNED : Modifier::UNSIGNED); } IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier): @@ -169,8 +173,6 @@ string IntegerType::toString() const u256 IntegerType::literalValue(Literal const& _literal) const { bigint value(_literal.getValue()); - //@todo check that the number is not too large - //@todo does this work for signed numbers? return u256(value); } |