aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-05 15:40:21 +0800
committerChristian <c@ethdev.com>2014-11-06 09:44:43 +0800
commit627c80f0a8b37426c2c6625ff4852d77e4d43464 (patch)
tree496c5f2bdcd6d5c3bb92556081f707cdefac9d47 /Types.cpp
parentb5e77678c9257f97be89139cf1d12bfa178147ef (diff)
downloaddexon-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.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/Types.cpp b/Types.cpp
index 334f5044..7354255e 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -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);
}