aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
authorLiana Husikyan <liana@ethdev.com>2015-02-17 23:21:38 +0800
committerLiana Husikyan <liana@ethdev.com>2015-02-21 05:50:34 +0800
commit52050201e39b823ea9e6133e47c7e9e779dc1f07 (patch)
treebf415cf6c45a0f6ee9468849c5c708217f366260 /AST.cpp
parent26132363d5a11d762224cc7c8acc6b8c854cf646 (diff)
downloaddexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.gz
dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.tar.zst
dexon-solidity-52050201e39b823ea9e6133e47c7e9e779dc1f07.zip
Inline member initialisation
renamed VariableDefinition class to VariableDeclarationStatement added tests
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/AST.cpp b/AST.cpp
index 761427db..a18785ae 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -77,6 +77,9 @@ void ContractDefinition::checkTypeRequirements()
for (ASTPointer<FunctionDefinition> const& function: getDefinedFunctions())
function->checkTypeRequirements();
+ for (ASTPointer<VariableDeclaration> const& variable: m_stateVariables)
+ variable->checkTypeRequirements();
+
// check for hash collisions in function signatures
set<FixedHash<4>> hashes;
for (auto const& it: getInterfaceFunctionList())
@@ -294,6 +297,12 @@ bool VariableDeclaration::isLValue() const
return !isExternalFunctionParameter();
}
+void VariableDeclaration::checkTypeRequirements()
+{
+ if (m_value)
+ m_value->checkTypeRequirements();
+}
+
bool VariableDeclaration::isExternalFunctionParameter() const
{
auto const* function = dynamic_cast<FunctionDefinition const*>(getScope());
@@ -390,26 +399,26 @@ void Return::checkTypeRequirements()
m_expression->expectType(*m_returnParameters->getParameters().front()->getType());
}
-void VariableDefinition::checkTypeRequirements()
+void VariableDeclarationStatement::checkTypeRequirements()
{
// Variables can be declared without type (with "var"), in which case the first assignment
// sets the type.
// Note that assignments before the first declaration are legal because of the special scoping
// rules inherited from JavaScript.
- if (m_value)
+ if (m_variable->getValue())
{
if (m_variable->getType())
- m_value->expectType(*m_variable->getType());
+ m_variable->getValue()->expectType(*m_variable->getType());
else
{
// no type declared and no previous assignment, infer the type
- m_value->checkTypeRequirements();
- TypePointer type = m_value->getType();
+ m_variable->getValue()->checkTypeRequirements();
+ TypePointer type = m_variable->getValue()->getType();
if (type->getCategory() == Type::Category::IntegerConstant)
{
auto intType = dynamic_pointer_cast<IntegerConstantType const>(type)->getIntegerType();
if (!intType)
- BOOST_THROW_EXCEPTION(m_value->createTypeError("Invalid integer constant " + type->toString()));
+ BOOST_THROW_EXCEPTION(m_variable->getValue()->createTypeError("Invalid integer constant " + type->toString()));
type = intType;
}
else if (type->getCategory() == Type::Category::Void)
@@ -418,7 +427,6 @@ void VariableDefinition::checkTypeRequirements()
}
}
}
-
void Assignment::checkTypeRequirements()
{
m_leftHandSide->checkTypeRequirements();