diff options
author | chriseth <c@ethdev.com> | 2017-03-02 02:12:40 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2017-03-13 20:30:21 +0800 |
commit | f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa (patch) | |
tree | 0dc1b367e2f5bc285457dc4358b2377ad4d5d1f0 /libsolidity/ast | |
parent | bde913f088c873cba75db30b2d463f50f9dfe862 (diff) | |
download | dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.gz dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.bz2 dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.lz dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.xz dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.zst dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.zip |
Type checking for pure expressions.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/ASTAnnotations.h | 2 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 12 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 4 |
3 files changed, 18 insertions, 0 deletions
diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h index 9c4c3ae8..bd297f9e 100644 --- a/libsolidity/ast/ASTAnnotations.h +++ b/libsolidity/ast/ASTAnnotations.h @@ -156,6 +156,8 @@ struct ExpressionAnnotation: ASTAnnotation TypePointer type; /// Whether the expression is a constant variable bool isConstant = false; + /// Whether the expression is pure, i.e. compile-time constant. + bool isPure = false; /// Whether it is an LValue (i.e. something that can be assigned to). bool isLValue = false; /// Whether the expression is used in a context where the LValue is actually required. diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index d2793b6d..0e11c3ec 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2456,6 +2456,18 @@ u256 FunctionType::externalIdentifier() const return FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(externalSignature()))); } +bool FunctionType::isPure() const +{ + return + m_location == Location::SHA3 || + m_location == Location::ECRecover || + m_location == Location::SHA256 || + m_location == Location::RIPEMD160 || + m_location == Location::AddMod || + m_location == Location::MulMod || + m_location == Location::ObjectCreation; +} + TypePointers FunctionType::parseElementaryTypeVector(strings const& _types) { TypePointers pointers; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 022b67c4..7c8fd429 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -972,6 +972,10 @@ public: } bool hasDeclaration() const { return !!m_declaration; } bool isConstant() const { return m_isConstant; } + /// @returns true if the the result of this function only depends on its arguments + /// and it does not modify the state. + /// Currently, this will only return true for internal functions like keccak and ecrecover. + bool isPure() const; bool isPayable() const { return m_isPayable; } /// @return A shared pointer of an ASTString. /// Can contain a nullptr in which case indicates absence of documentation |