corrected accept for variableDeclaration

changes after code review
This commit is contained in:
Liana Husikyan 2015-02-20 12:27:39 +01:00
parent 1ed86b33bc
commit 858acaa193
5 changed files with 17 additions and 20 deletions

2
AST.h
View File

@ -451,7 +451,7 @@ public:
virtual bool isLValue() const override;
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
/// Calls checkTypeRequirments for all state variables.
void checkTypeRequirements();
bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); }
bool isExternalFunctionParameter() const;

View File

@ -227,7 +227,7 @@ bool ASTPrinter::visit(Return const& _node)
bool ASTPrinter::visit(VariableDeclarationStatement const& _node)
{
writeLine("VariableDefinition");
writeLine("VariableDeclarationStatement");
printSourcePart(_node);
return goDeeper();
}

View File

@ -196,17 +196,24 @@ void FunctionDefinition::accept(ASTConstVisitor& _visitor) const
void VariableDeclaration::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
{
if (m_typeName)
m_typeName->accept(_visitor);
if (m_value)
m_value->accept(_visitor);
}
_visitor.endVisit(*this);
}
void VariableDeclaration::accept(ASTConstVisitor& _visitor) const
{
if (_visitor.visit(*this))
{
if (m_typeName)
m_typeName->accept(_visitor);
_visitor.endVisit(*this);
if (m_value)
m_value->accept(_visitor);
}
}
void ModifierDefinition::accept(ASTVisitor& _visitor)
@ -478,22 +485,14 @@ void ExpressionStatement::accept(ASTConstVisitor& _visitor) const
void VariableDeclarationStatement::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
{
m_variable->accept(_visitor);
if (m_variable->getValue())
m_variable->getValue()->accept(_visitor);
}
_visitor.endVisit(*this);
}
void VariableDeclarationStatement::accept(ASTConstVisitor& _visitor) const
{
if (_visitor.visit(*this))
{
m_variable->accept(_visitor);
if (m_variable->getValue())
m_variable->getValue()->accept(_visitor);
}
_visitor.endVisit(*this);
}

View File

@ -253,10 +253,7 @@ void Compiler::initializeStateVariables(ContractDefinition const& _contract)
{
for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables())
if (variable->getValue())
{
compileExpression(*(variable->getValue()), (variable->getValue())->getType());
ExpressionCompiler::appendStateVariableInitialization(m_context, *variable);
}
}
bool Compiler::visit(VariableDeclaration const& _variableDeclaration)

View File

@ -58,15 +58,19 @@ void ExpressionCompiler::appendStateVariableAccessor(CompilerContext& _context,
void ExpressionCompiler::appendStateVariableInitialization(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize)
{
compileExpression(_context, *(_varDecl.getValue()), _optimize);
if (_varDecl.getValue()->getType())
appendTypeConversion(_context, *(_varDecl.getValue())->getType(), *(_varDecl.getValue())->getType());
ExpressionCompiler compiler(_context, _optimize);
compiler.appendStateVariableInitialization(_varDecl);
}
void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration const& _varDecl)
{
m_currentLValue.fromVariableDeclaration(_varDecl);
m_currentLValue.storeValue(*_varDecl.getType(), _varDecl.getLocation());
m_currentLValue.reset();
LValue lvalue = LValue(m_context);
lvalue.fromVariableDeclaration(_varDecl);
lvalue.storeValue(*_varDecl.getType(), _varDecl.getLocation());
}
bool ExpressionCompiler::visit(Assignment const& _assignment)
@ -1024,9 +1028,7 @@ void ExpressionCompiler::LValue::fromIdentifier(Identifier const& _identifier, D
m_baseStackOffset = m_context->getBaseStackOffsetOfVariable(_declaration);
}
else if (m_context->isStateVariable(&_declaration))
//{
fromVariableDeclaration(_declaration);
//}
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_identifier.getLocation())
<< errinfo_comment("Identifier type not supported or identifier not found."));
@ -1034,7 +1036,6 @@ void ExpressionCompiler::LValue::fromIdentifier(Identifier const& _identifier, D
void ExpressionCompiler::LValue::fromVariableDeclaration(Declaration const& _declaration)
{
//solAssert(m_context->isStateVariable(&_declaration), "Not a state variable.");
*m_context << m_context->getStorageLocationOfVariable(_declaration);
m_type = LValueType::Storage;
m_dataType = _declaration.getType();