mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2554 from ethereum/minMaxValue
Some helper functions.
This commit is contained in:
commit
0b17ff1bdd
@ -416,6 +416,23 @@ bool VariableDeclaration::isCallableParameter() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VariableDeclaration::isLocalOrReturn() const
|
||||||
|
{
|
||||||
|
return isReturnParameter() || (isLocalVariable() && !isCallableParameter());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VariableDeclaration::isReturnParameter() const
|
||||||
|
{
|
||||||
|
auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
|
||||||
|
if (!callable)
|
||||||
|
return false;
|
||||||
|
if (callable->returnParameterList())
|
||||||
|
for (auto const& variable: callable->returnParameterList()->parameters())
|
||||||
|
if (variable.get() == this)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool VariableDeclaration::isExternalCallableParameter() const
|
bool VariableDeclaration::isExternalCallableParameter() const
|
||||||
{
|
{
|
||||||
auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
|
auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
|
||||||
|
@ -650,6 +650,10 @@ public:
|
|||||||
bool isLocalVariable() const { return !!dynamic_cast<CallableDeclaration const*>(scope()); }
|
bool isLocalVariable() const { return !!dynamic_cast<CallableDeclaration const*>(scope()); }
|
||||||
/// @returns true if this variable is a parameter or return parameter of a function.
|
/// @returns true if this variable is a parameter or return parameter of a function.
|
||||||
bool isCallableParameter() const;
|
bool isCallableParameter() const;
|
||||||
|
/// @returns true if this variable is a return parameter of a function.
|
||||||
|
bool isReturnParameter() const;
|
||||||
|
/// @returns true if this variable is a local variable or return parameter.
|
||||||
|
bool isLocalOrReturn() const;
|
||||||
/// @returns true if this variable is a parameter (not return parameter) of an external function.
|
/// @returns true if this variable is a parameter (not return parameter) of an external function.
|
||||||
bool isExternalCallableParameter() const;
|
bool isExternalCallableParameter() const;
|
||||||
/// @returns true if the type of the variable does not need to be specified, i.e. it is declared
|
/// @returns true if the type of the variable does not need to be specified, i.e. it is declared
|
||||||
|
@ -413,6 +413,22 @@ u256 IntegerType::literalValue(Literal const* _literal) const
|
|||||||
return u256(_literal->value());
|
return u256(_literal->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bigint IntegerType::minValue() const
|
||||||
|
{
|
||||||
|
if (isSigned())
|
||||||
|
return -(bigint(1) << (m_bits - 1));
|
||||||
|
else
|
||||||
|
return bigint(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bigint IntegerType::maxValue() const
|
||||||
|
{
|
||||||
|
if (isSigned())
|
||||||
|
return (bigint(1) << (m_bits - 1)) - 1;
|
||||||
|
else
|
||||||
|
return (bigint(1) << m_bits) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const
|
TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
|
@ -323,6 +323,9 @@ public:
|
|||||||
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; }
|
||||||
|
|
||||||
|
bigint minValue() const;
|
||||||
|
bigint maxValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_bits;
|
int m_bits;
|
||||||
Modifier m_modifier;
|
Modifier m_modifier;
|
||||||
|
Loading…
Reference in New Issue
Block a user