aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiana Husikyan <liana@ethdev.com>2015-02-20 19:27:39 +0800
committerLiana Husikyan <liana@ethdev.com>2015-02-21 05:51:16 +0800
commit858acaa1937ccc2f6cc13bb3076abc32c43789b0 (patch)
tree6628fd9080584e7dbae13272a00aee9a2357df1a
parent1ed86b33bcb07f432209953ec4ed1779d0831452 (diff)
downloaddexon-solidity-858acaa1937ccc2f6cc13bb3076abc32c43789b0.tar.gz
dexon-solidity-858acaa1937ccc2f6cc13bb3076abc32c43789b0.tar.zst
dexon-solidity-858acaa1937ccc2f6cc13bb3076abc32c43789b0.zip
corrected accept for variableDeclaration
changes after code review
-rw-r--r--AST.h2
-rw-r--r--ASTPrinter.cpp2
-rw-r--r--AST_accept.h17
-rw-r--r--Compiler.cpp3
-rw-r--r--ExpressionCompiler.cpp13
5 files changed, 17 insertions, 20 deletions
diff --git a/AST.h b/AST.h
index c7fd068d..064457d3 100644
--- a/AST.h
+++ b/AST.h
@@ -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;
diff --git a/ASTPrinter.cpp b/ASTPrinter.cpp
index aead6abd..209bb73e 100644
--- a/ASTPrinter.cpp
+++ b/ASTPrinter.cpp
@@ -227,7 +227,7 @@ bool ASTPrinter::visit(Return const& _node)
bool ASTPrinter::visit(VariableDeclarationStatement const& _node)
{
- writeLine("VariableDefinition");
+ writeLine("VariableDeclarationStatement");
printSourcePart(_node);
return goDeeper();
}
diff --git a/AST_accept.h b/AST_accept.h
index 217a565f..b1577ecd 100644
--- a/AST_accept.h
+++ b/AST_accept.h
@@ -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);
}
diff --git a/Compiler.cpp b/Compiler.cpp
index bdc29fab..23014da6 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -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)
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index c2a10ab4..653bf829 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -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();