mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Minor code adjustments in ExpressionCompiler and IRGeneratorForStatements
This commit is contained in:
parent
beae1e6263
commit
61075e28db
@ -411,18 +411,17 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
CompilerContext::LocationSetter locationSetter(m_context, _unaryOperation);
|
||||
|
||||
if (_unaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = _unaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
FunctionDefinition const& function = *_unaryOperation.annotation().userDefinedFunction;
|
||||
FunctionType const* functionType = dynamic_cast<FunctionType const*>(
|
||||
function.libraryFunction() ? function.typeViaContractName() : function.type());
|
||||
function->libraryFunction() ? function->typeViaContractName() : function->type());
|
||||
|
||||
solAssert(functionType);
|
||||
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
|
||||
solAssert(functionType);
|
||||
evmasm::AssemblyItem returnLabel = m_context.pushNewTag();
|
||||
_unaryOperation.subExpression().accept(*this);
|
||||
m_context << m_context.functionEntryLabel(function).pushTag();
|
||||
m_context << m_context.functionEntryLabel(*function).pushTag();
|
||||
|
||||
unsigned parameterSize =
|
||||
CompilerUtils::sizeOnStack(functionType->parameterTypes()) +
|
||||
@ -540,12 +539,10 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
|
||||
CompilerContext::LocationSetter locationSetter(m_context, _binaryOperation);
|
||||
Expression const& leftExpression = _binaryOperation.leftExpression();
|
||||
Expression const& rightExpression = _binaryOperation.rightExpression();
|
||||
if (_binaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function =_binaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
// TODO extract from function call
|
||||
FunctionDefinition const& function = *_binaryOperation.annotation().userDefinedFunction;
|
||||
FunctionType const* functionType = dynamic_cast<FunctionType const*>(
|
||||
function.libraryFunction() ? function.typeViaContractName() : function.type()
|
||||
function->libraryFunction() ? function->typeViaContractName() : function->type()
|
||||
);
|
||||
solAssert(functionType);
|
||||
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
|
||||
@ -555,7 +552,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
|
||||
acceptAndConvert(leftExpression, *functionType->selfType());
|
||||
acceptAndConvert(rightExpression, *functionType->parameterTypes().at(0));
|
||||
|
||||
m_context << m_context.functionEntryLabel(function).pushTag();
|
||||
m_context << m_context.functionEntryLabel(*function).pushTag();
|
||||
|
||||
unsigned parameterSize =
|
||||
CompilerUtils::sizeOnStack(functionType->parameterTypes()) +
|
||||
|
@ -673,20 +673,18 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
|
||||
{
|
||||
setLocation(_unaryOperation);
|
||||
|
||||
if (_unaryOperation.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = _unaryOperation.annotation().userDefinedFunction)
|
||||
{
|
||||
_unaryOperation.subExpression().accept(*this);
|
||||
setLocation(_unaryOperation);
|
||||
|
||||
// TODO extract from function call
|
||||
FunctionDefinition const& function = *_unaryOperation.annotation().userDefinedFunction;
|
||||
solAssert(
|
||||
dynamic_cast<SourceUnit const*>(function.scope()),
|
||||
dynamic_cast<SourceUnit const*>(function->scope()),
|
||||
"Only file-level functions and library functions can be bound to a user type operator."
|
||||
);
|
||||
|
||||
FunctionType const* functionType = dynamic_cast<FunctionType const*>(
|
||||
function.libraryFunction() ? function.typeViaContractName() : function.type()
|
||||
function->libraryFunction() ? function->typeViaContractName() : function->type()
|
||||
);
|
||||
solAssert(functionType);
|
||||
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
|
||||
@ -694,10 +692,10 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
|
||||
|
||||
string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType());
|
||||
solAssert(!parameter.empty());
|
||||
solAssert(function.isImplemented(), "");
|
||||
solAssert(function->isImplemented(), "");
|
||||
|
||||
define(_unaryOperation) <<
|
||||
m_context.enqueueFunctionForCodeGeneration(function) <<
|
||||
m_context.enqueueFunctionForCodeGeneration(*function) <<
|
||||
("(" + parameter + ")\n");
|
||||
|
||||
return false;
|
||||
@ -806,22 +804,19 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
|
||||
{
|
||||
setLocation(_binOp);
|
||||
|
||||
// TODO: make this nicer
|
||||
if (_binOp.annotation().userDefinedFunction)
|
||||
if (FunctionDefinition const* function = _binOp.annotation().userDefinedFunction)
|
||||
{
|
||||
_binOp.leftExpression().accept(*this);
|
||||
_binOp.rightExpression().accept(*this);
|
||||
setLocation(_binOp);
|
||||
|
||||
// TODO extract from function call
|
||||
FunctionDefinition const& function = *_binOp.annotation().userDefinedFunction;
|
||||
solAssert(
|
||||
dynamic_cast<SourceUnit const*>(function.scope()),
|
||||
dynamic_cast<SourceUnit const*>(function->scope()),
|
||||
"Only file-level functions and library functions can be bound to a user type operator."
|
||||
);
|
||||
|
||||
FunctionType const* functionType = dynamic_cast<FunctionType const*>(
|
||||
function.libraryFunction() ? function.typeViaContractName() : function.type()
|
||||
function->libraryFunction() ? function->typeViaContractName() : function->type()
|
||||
);
|
||||
solAssert(functionType);
|
||||
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
|
||||
@ -831,10 +826,10 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
|
||||
string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0));
|
||||
solAssert(!left.empty() && !right.empty());
|
||||
|
||||
solAssert(function.isImplemented(), "");
|
||||
solAssert(function->isImplemented(), "");
|
||||
|
||||
define(_binOp) <<
|
||||
m_context.enqueueFunctionForCodeGeneration(function) <<
|
||||
m_context.enqueueFunctionForCodeGeneration(*function) <<
|
||||
("(" + left + ", " + right + ")\n");
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user