aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-19 01:53:43 +0800
committerChristian <c@ethdev.com>2014-12-19 07:12:04 +0800
commit7dc7827907087c25d89589244f7fa57f5a66e48d (patch)
treefa011514eb4cc8f56e4fec008422e19d6bb0901c /Types.cpp
parent59835e9df19332397d6e16b25bfe0dac4807996c (diff)
downloaddexon-solidity-7dc7827907087c25d89589244f7fa57f5a66e48d.tar.gz
dexon-solidity-7dc7827907087c25d89589244f7fa57f5a66e48d.tar.zst
dexon-solidity-7dc7827907087c25d89589244f7fa57f5a66e48d.zip
Possibility for binary operators to yield types different from their operands'.
Diffstat (limited to 'Types.cpp')
-rw-r--r--Types.cpp52
1 files changed, 42 insertions, 10 deletions
diff --git a/Types.cpp b/Types.cpp
index 71319c3a..664b56ff 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -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();
+
+ if (commonType->isAddress())
+ {
+ if (!Token::isCompareOp(_operator))
+ return TypePointer();
+ }
+ else if (commonType->isHash())
+ {
+ if (!(Token::isCompareOp(_operator) || Token::isBitOp(_operator)))
+ return TypePointer();
+ }
+ 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))