aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorBalajiganapathi S <balajiganapathi.s@gmail.com>2017-10-28 19:03:11 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-11-22 09:41:46 +0800
commit165857b1d40ecb8a1bcf40eec9e371370ebe2541 (patch)
tree7629b806e2e9ea4465a55ac2ea500f4ab568611d /libsolidity/analysis
parent5c9e273d028bdcc65af50fdc1a2c5545e54739c3 (diff)
downloaddexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.tar.gz
dexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.tar.zst
dexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.zip
Allow constant integer variables as array lengths.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/ConstantEvaluator.cpp18
-rw-r--r--libsolidity/analysis/ConstantEvaluator.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp
index bc3b7cf1..50044eb6 100644
--- a/libsolidity/analysis/ConstantEvaluator.cpp
+++ b/libsolidity/analysis/ConstantEvaluator.cpp
@@ -74,3 +74,21 @@ void ConstantEvaluator::endVisit(Literal const& _literal)
if (!_literal.annotation().type)
m_errorReporter.fatalTypeError(_literal.location(), "Invalid literal value.");
}
+
+void ConstantEvaluator::endVisit(Identifier const& _identifier)
+{
+ VariableDeclaration const *variableDeclaration = dynamic_cast<VariableDeclaration const *>(_identifier.annotation().referencedDeclaration);
+ if (!variableDeclaration)
+ return;
+ if (!variableDeclaration->isConstant())
+ m_errorReporter.fatalTypeError(_identifier.location(), "Identifier must be declared constant.");
+
+ ASTPointer<Expression> value = variableDeclaration->value();
+ if (value)
+ {
+ if (!value->annotation().type)
+ ConstantEvaluator e(*value, m_errorReporter);
+
+ _identifier.annotation().type = value->annotation().type;
+ }
+}
diff --git a/libsolidity/analysis/ConstantEvaluator.h b/libsolidity/analysis/ConstantEvaluator.h
index 90bceb5d..42ccfe7e 100644
--- a/libsolidity/analysis/ConstantEvaluator.h
+++ b/libsolidity/analysis/ConstantEvaluator.h
@@ -48,6 +48,7 @@ private:
virtual void endVisit(BinaryOperation const& _operation);
virtual void endVisit(UnaryOperation const& _operation);
virtual void endVisit(Literal const& _literal);
+ virtual void endVisit(Identifier const& _identifier);
ErrorReporter& m_errorReporter;
};