mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
codegen: refactor common code
This commit is contained in:
parent
acba7b92e5
commit
5245a3cf74
@ -889,17 +889,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
// no-op
|
||||
}
|
||||
else if (auto variable = dynamic_cast<VariableDeclaration const*>(_memberAccess.annotation().referencedDeclaration))
|
||||
{
|
||||
// TODO duplicate code should be unified
|
||||
|
||||
if (!variable->isConstant())
|
||||
setLValueFromDeclaration(*_memberAccess.annotation().referencedDeclaration, _memberAccess);
|
||||
else
|
||||
{
|
||||
variable->value()->accept(*this);
|
||||
utils().convertType(*variable->value()->annotation().type, *variable->annotation().type);
|
||||
}
|
||||
}
|
||||
appendVariable(*variable, static_cast<Expression const&>(_memberAccess));
|
||||
else
|
||||
_memberAccess.expression().accept(*this);
|
||||
}
|
||||
@ -1213,15 +1203,7 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
||||
else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration))
|
||||
m_context << m_context.virtualFunctionEntryLabel(*functionDef).pushTag();
|
||||
else if (auto variable = dynamic_cast<VariableDeclaration const*>(declaration))
|
||||
{
|
||||
if (!variable->isConstant())
|
||||
setLValueFromDeclaration(*declaration, _identifier);
|
||||
else
|
||||
{
|
||||
variable->value()->accept(*this);
|
||||
utils().convertType(*variable->value()->annotation().type, *variable->annotation().type);
|
||||
}
|
||||
}
|
||||
appendVariable(*variable, static_cast<Expression const&>(_identifier));
|
||||
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
|
||||
{
|
||||
if (contract->isLibrary())
|
||||
@ -1650,6 +1632,17 @@ void ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
|
||||
utils().storeInMemoryDynamic(_expectedType);
|
||||
}
|
||||
|
||||
void ExpressionCompiler::appendVariable(VariableDeclaration const& _variable, Expression const& _expression)
|
||||
{
|
||||
if (!_variable.isConstant())
|
||||
setLValueFromDeclaration(_variable, _expression);
|
||||
else
|
||||
{
|
||||
_variable.value()->accept(*this);
|
||||
utils().convertType(*_variable.value()->annotation().type, *_variable.annotation().type);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionCompiler::setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression)
|
||||
{
|
||||
if (m_context.isLocalVariable(&_declaration))
|
||||
|
@ -103,6 +103,8 @@ private:
|
||||
/// expected to be on the stack and is updated by this call.
|
||||
void appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression);
|
||||
|
||||
/// Appends code for a variable that might be a constant or not
|
||||
void appendVariable(VariableDeclaration const& _variable, Expression const& _expression);
|
||||
/// Sets the current LValue to a new one (of the appropriate type) from the given declaration.
|
||||
/// Also retrieves the value if it was not requested by @a _expression.
|
||||
void setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression);
|
||||
|
Loading…
Reference in New Issue
Block a user