diff options
author | Christian <c@ethdev.com> | 2015-01-07 02:08:24 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-09 22:09:10 +0800 |
commit | be1e89da42e0ed9828dd2fb5939fd7bd48140be7 (patch) | |
tree | 977979fe84ea56786984dafe99be7952eb111c2a /Types.cpp | |
parent | dcda38cf3806c1d4205136c55d17f1e73eda48c1 (diff) | |
download | dexon-solidity-be1e89da42e0ed9828dd2fb5939fd7bd48140be7.tar.gz dexon-solidity-be1e89da42e0ed9828dd2fb5939fd7bd48140be7.tar.zst dexon-solidity-be1e89da42e0ed9828dd2fb5939fd7bd48140be7.zip |
Possibility for unary operators to change type.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -156,18 +156,26 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const return _convertTo.getCategory() == getCategory() || _convertTo.getCategory() == Category::CONTRACT; } -bool IntegerType::acceptsUnaryOperator(Token::Value _operator) const +TypePointer IntegerType::unaryOperatorResult(Token::Value _operator) const { + // "delete" is ok for all integer types if (_operator == Token::DELETE) - return true; - if (isAddress()) - return false; - if (_operator == Token::BIT_NOT) - return true; - if (isHash()) - return false; - return _operator == Token::ADD || _operator == Token::SUB || - _operator == Token::INC || _operator == Token::DEC; + return shared_from_this(); + // no further unary operators for addresses + else if (isAddress()) + return TypePointer(); + // "~" is ok for all other types + else if (_operator == Token::BIT_NOT) + return shared_from_this(); + // nothing else for hashes + else if (isHash()) + return TypePointer(); + // for non-hash integers, we allow +, -, ++ and -- + else if (_operator == Token::ADD || _operator == Token::SUB || + _operator == Token::INC || _operator == Token::DEC) + return shared_from_this(); + else + return TypePointer(); } bool IntegerType::operator==(Type const& _other) const |