Merge pull request #1729 from ethereum/constantvariables

Only allow pure expressions for constant state variables.
This commit is contained in:
Yoichi Hirai
2017-03-15 10:03:35 +01:00
committed by GitHub
8 changed files with 241 additions and 35 deletions
+2
View File
@@ -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.
+12
View File
@@ -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;
+4
View File
@@ -973,6 +973,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