mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
explicit conversion and loosening of binary operations on integer and fixed point types...still other problems
fixed some spaces and deleted lines from failing test
This commit is contained in:
parent
3ba308fb2e
commit
6289410152
@ -274,18 +274,8 @@ bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
else if (_convertTo.category() == Category::FixedPoint)
|
else if (_convertTo.category() == Category::FixedPoint)
|
||||||
{
|
{
|
||||||
FixedPointType const& convertTo = dynamic_cast<FixedPointType const&>(_convertTo);
|
FixedPointType const& convertTo = dynamic_cast<FixedPointType const&>(_convertTo);
|
||||||
cout << endl;
|
|
||||||
cout << "Integer bits: " << m_bits << endl;
|
|
||||||
cout << "Fraction integer bits: " << convertTo.integerBits() << endl;
|
|
||||||
cout << "Integer signed: " << isSigned() << endl;
|
|
||||||
cout << "Fractional signed: " << convertTo.isSigned() << endl;
|
|
||||||
cout << "Unsigned convert?: " << bool(!convertTo.isSigned() || convertTo.integerBits() > m_bits) << endl;
|
|
||||||
cout << endl;
|
|
||||||
if (convertTo.integerBits() < m_bits || isAddress())
|
if (convertTo.integerBits() < m_bits || isAddress())
|
||||||
{
|
|
||||||
cout << "problem with the integer bits" << endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
else if (isSigned())
|
else if (isSigned())
|
||||||
return convertTo.isSigned();
|
return convertTo.isSigned();
|
||||||
else
|
else
|
||||||
@ -300,7 +290,8 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
return _convertTo.category() == category() ||
|
return _convertTo.category() == category() ||
|
||||||
_convertTo.category() == Category::Contract ||
|
_convertTo.category() == Category::Contract ||
|
||||||
_convertTo.category() == Category::Enum ||
|
_convertTo.category() == Category::Enum ||
|
||||||
_convertTo.category() == Category::FixedBytes;
|
_convertTo.category() == Category::FixedBytes ||
|
||||||
|
_convertTo.category() == Category::FixedPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePointer IntegerType::unaryOperatorResult(Token::Value _operator) const
|
TypePointer IntegerType::unaryOperatorResult(Token::Value _operator) const
|
||||||
@ -344,22 +335,18 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe
|
|||||||
_other->category() != category()
|
_other->category() != category()
|
||||||
)
|
)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
auto commonType = dynamic_pointer_cast<IntegerType const>(Type::commonType(shared_from_this(), _other));
|
auto commonType = Type::commonType(shared_from_this(), _other); //might be a integer or fixed point
|
||||||
|
|
||||||
if (!commonType)
|
if (!commonType)
|
||||||
{
|
|
||||||
cout << "Not common type" << endl;
|
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
}
|
|
||||||
cout << "Integer binary operator: " << commonType->toString(false) << endl;
|
|
||||||
cout << "Token: " << string(Token::toString(_operator)) << endl;
|
|
||||||
// All integer types can be compared
|
// All integer types can be compared
|
||||||
if (Token::isCompareOp(_operator))
|
if (Token::isCompareOp(_operator))
|
||||||
return commonType;
|
return commonType;
|
||||||
if (Token::isBooleanOp(_operator))
|
if (Token::isBooleanOp(_operator))
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
// Nothing else can be done with addresses
|
// Nothing else can be done with addresses
|
||||||
if (commonType->isAddress())
|
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
|
||||||
|
if (intType->isAddress())
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
|
|
||||||
return commonType;
|
return commonType;
|
||||||
@ -404,7 +391,6 @@ bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
else
|
else
|
||||||
return !convertTo.isSigned() || (convertTo.m_integerBits > m_integerBits);
|
return !convertTo.isSigned() || (convertTo.m_integerBits > m_integerBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +441,7 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi
|
|||||||
&& _other->category() != Category::Integer
|
&& _other->category() != Category::Integer
|
||||||
)
|
)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
auto commonType = dynamic_pointer_cast<FixedPointType const>(Type::commonType(shared_from_this(), _other));
|
auto commonType = Type::commonType(shared_from_this(), _other); //might be fixed point or integer
|
||||||
|
|
||||||
if (!commonType)
|
if (!commonType)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
@ -465,6 +451,7 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi
|
|||||||
return commonType;
|
return commonType;
|
||||||
if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator))
|
if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator))
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
|
if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType))
|
||||||
if (Token::Exp == _operator)
|
if (Token::Exp == _operator)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
return commonType;
|
return commonType;
|
||||||
|
@ -3688,8 +3688,7 @@ BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction)
|
|||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
contract test {
|
contract test {
|
||||||
function f() {
|
function f() {
|
||||||
uint128 a = uint128(1) + ufixed(2);
|
ufixed a = uint128(1) + ufixed(2);
|
||||||
ufixed b = .5 * uint128(7);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
Loading…
Reference in New Issue
Block a user