mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
merging develop
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user