aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-06 17:05:05 +0800
committerchriseth <chris@ethereum.org>2017-07-11 17:24:41 +0800
commit01a1296e90e48d64d5494ab4ba9231911ec72ac9 (patch)
tree7dc51a4d8abd1da74e090f94469f2bd9c9fed53e /libsolidity
parent6fa5d47f8fcd7076464ce8ed83c9d89883586f7a (diff)
downloaddexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar.gz
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar.bz2
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar.lz
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar.xz
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.tar.zst
dexon-solidity-01a1296e90e48d64d5494ab4ba9231911ec72ac9.zip
Helper functions.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/AST.cpp17
-rw-r--r--libsolidity/ast/AST.h4
-rw-r--r--libsolidity/ast/Types.cpp16
-rw-r--r--libsolidity/ast/Types.h3
4 files changed, 40 insertions, 0 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 403f4b79..724a908f 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -416,6 +416,23 @@ bool VariableDeclaration::isCallableParameter() const
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
{
auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index e8831dc0..f90a9b2f 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -650,6 +650,10 @@ public:
bool isLocalVariable() const { return !!dynamic_cast<CallableDeclaration const*>(scope()); }
/// @returns true if this variable is a parameter or return parameter of a function.
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.
bool isExternalCallableParameter() const;
/// @returns true if the type of the variable does not need to be specified, i.e. it is declared
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 7dc6c4a6..6ecf509d 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -413,6 +413,22 @@ u256 IntegerType::literalValue(Literal const* _literal) const
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
{
if (
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index f7a73ab5..87d88a79 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -323,6 +323,9 @@ public:
bool isAddress() const { return m_modifier == Modifier::Address; }
bool isSigned() const { return m_modifier == Modifier::Signed; }
+ bigint minValue() const;
+ bigint maxValue() const;
+
private:
int m_bits;
Modifier m_modifier;