merging develop

This commit is contained in:
Lefteris Karapetsas
2015-01-08 17:43:38 +01:00
9 changed files with 116 additions and 49 deletions
+42 -10
View File
@@ -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))