mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change numBits to unsigned IntegerType
This commit is contained in:
parent
2c00ebbee1
commit
b34428249a
@ -1200,8 +1200,9 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
|||||||
string extension;
|
string extension;
|
||||||
if (auto type = dynamic_cast<IntegerType const*>(var.annotation().type.get()))
|
if (auto type = dynamic_cast<IntegerType const*>(var.annotation().type.get()))
|
||||||
{
|
{
|
||||||
int numBits = type->numBits();
|
unsigned numBits = type->numBits();
|
||||||
bool isSigned = type->isSigned();
|
bool isSigned = type->isSigned();
|
||||||
|
solAssert(numBits > 0, "");
|
||||||
string minValue;
|
string minValue;
|
||||||
string maxValue;
|
string maxValue;
|
||||||
if (isSigned)
|
if (isSigned)
|
||||||
|
@ -425,14 +425,14 @@ bool isValidShiftAndAmountType(Token::Value _operator, Type const& _shiftAmountT
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier):
|
IntegerType::IntegerType(unsigned _bits, IntegerType::Modifier _modifier):
|
||||||
m_bits(_bits), m_modifier(_modifier)
|
m_bits(_bits), m_modifier(_modifier)
|
||||||
{
|
{
|
||||||
if (isAddress())
|
if (isAddress())
|
||||||
solAssert(m_bits == 160, "");
|
solAssert(m_bits == 160, "");
|
||||||
solAssert(
|
solAssert(
|
||||||
m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0,
|
m_bits > 0 && m_bits <= 256 && m_bits % 8 == 0,
|
||||||
"Invalid bit number for integer type: " + dev::toString(_bits)
|
"Invalid bit number for integer type: " + dev::toString(m_bits)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi
|
|||||||
|
|
||||||
std::shared_ptr<IntegerType> FixedPointType::asIntegerType() const
|
std::shared_ptr<IntegerType> FixedPointType::asIntegerType() const
|
||||||
{
|
{
|
||||||
return std::make_shared<IntegerType>(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned);
|
return make_shared<IntegerType>(numBits(), isSigned() ? IntegerType::Modifier::Signed : IntegerType::Modifier::Unsigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<bool, rational> RationalNumberType::parseRational(string const& _value)
|
tuple<bool, rational> RationalNumberType::parseRational(string const& _value)
|
||||||
@ -850,7 +850,7 @@ bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
if (isFractional())
|
if (isFractional())
|
||||||
return false;
|
return false;
|
||||||
IntegerType const& targetType = dynamic_cast<IntegerType const&>(_convertTo);
|
IntegerType const& targetType = dynamic_cast<IntegerType const&>(_convertTo);
|
||||||
int forSignBit = (targetType.isSigned() ? 1 : 0);
|
unsigned forSignBit = (targetType.isSigned() ? 1 : 0);
|
||||||
if (m_value > rational(0))
|
if (m_value > rational(0))
|
||||||
{
|
{
|
||||||
if (m_value.numerator() <= (u256(-1) >> (256 - targetType.numBits() + forSignBit)))
|
if (m_value.numerator() <= (u256(-1) >> (256 - targetType.numBits() + forSignBit)))
|
||||||
|
@ -319,7 +319,7 @@ public:
|
|||||||
};
|
};
|
||||||
virtual Category category() const override { return Category::Integer; }
|
virtual Category category() const override { return Category::Integer; }
|
||||||
|
|
||||||
explicit IntegerType(int _bits, Modifier _modifier = Modifier::Unsigned);
|
explicit IntegerType(unsigned _bits, Modifier _modifier = Modifier::Unsigned);
|
||||||
|
|
||||||
virtual std::string richIdentifier() const override;
|
virtual std::string richIdentifier() const override;
|
||||||
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
|
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
@ -342,7 +342,7 @@ public:
|
|||||||
virtual TypePointer encodingType() const override { return shared_from_this(); }
|
virtual TypePointer encodingType() const override { return shared_from_this(); }
|
||||||
virtual TypePointer interfaceType(bool) const override { return shared_from_this(); }
|
virtual TypePointer interfaceType(bool) const override { return shared_from_this(); }
|
||||||
|
|
||||||
int numBits() const { return m_bits; }
|
unsigned numBits() const { return m_bits; }
|
||||||
bool isAddress() const { return m_modifier == Modifier::Address; }
|
bool isAddress() const { return m_modifier == Modifier::Address; }
|
||||||
bool isSigned() const { return m_modifier == Modifier::Signed; }
|
bool isSigned() const { return m_modifier == Modifier::Signed; }
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ public:
|
|||||||
bigint maxValue() const;
|
bigint maxValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_bits;
|
unsigned m_bits;
|
||||||
Modifier m_modifier;
|
Modifier m_modifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user