diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
commit | a7b661d3be53b4c6a05401782ab8f90202a4f776 (patch) | |
tree | a2fdb25e88821def4962e1eacf303ec8f89cdfc3 /Types.cpp | |
parent | 184ddca5a108c5f3d026aa372a2af2f63b2694f9 (diff) | |
parent | d18fa27b6a48540298e835ad324152566586c65c (diff) | |
download | dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.gz dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.zst dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.zip |
merging develop
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 52 |
1 files changed, 42 insertions, 10 deletions
@@ -100,6 +100,16 @@ shared_ptr<Type const> Type::forLiteral(Literal const& _literal) } } +TypePointer Type::commonType(TypePointer const& _a, TypePointer const& _b) +{ + if (_b->isImplicitlyConvertibleTo(*_a)) + return _a; + else if (_a->isImplicitlyConvertibleTo(*_b)) + return _b; + else + return TypePointer(); +} + const MemberList Type::EmptyMemberList = MemberList(); shared_ptr<IntegerType const> IntegerType::smallestTypeForLiteral(string const& _literal) @@ -146,16 +156,6 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const return _convertTo.getCategory() == getCategory() || _convertTo.getCategory() == Category::CONTRACT; } -bool IntegerType::acceptsBinaryOperator(Token::Value _operator) const -{ - if (isAddress()) - return Token::isCompareOp(_operator); - else if (isHash()) - return Token::isCompareOp(_operator) || Token::isBitOp(_operator); - else - return true; -} - bool IntegerType::acceptsUnaryOperator(Token::Value _operator) const { if (_operator == Token::DELETE) @@ -192,6 +192,28 @@ u256 IntegerType::literalValue(Literal const& _literal) const return u256(value); } +TypePointer IntegerType::binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const +{ + if (getCategory() != _other->getCategory()) + return TypePointer(); + auto commonType = dynamic_pointer_cast<IntegerType const>(Type::commonType(_this, _other)); + + if (!commonType) + return TypePointer(); + + // All integer types can be compared + if (Token::isCompareOp(_operator)) + return commonType; + + // Nothing else can be done with addresses, but hashes can receive bit operators + if (commonType->isAddress()) + return TypePointer(); + else if (commonType->isHash() && !Token::isBitOp(_operator)) + return TypePointer(); + else + return commonType; +} + const MemberList IntegerType::AddressMemberList = MemberList({{"balance", make_shared<IntegerType const>(256)}, @@ -266,6 +288,16 @@ u256 BoolType::literalValue(Literal const& _literal) const BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Bool type constructed from non-boolean literal.")); } +TypePointer BoolType::binaryOperatorResultImpl(Token::Value _operator, TypePointer const& _this, TypePointer const& _other) const +{ + if (getCategory() != _other->getCategory()) + return TypePointer(); + if (Token::isCompareOp(_operator) || _operator == Token::AND || _operator == Token::OR) + return _this; + else + return TypePointer(); +} + bool ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const { if (isImplicitlyConvertibleTo(_convertTo)) |