Update code to review comments

This commit is contained in:
wechman 2022-07-08 11:20:14 +02:00
parent dd251379e7
commit d3d28e96a8
2 changed files with 12 additions and 12 deletions

View File

@ -422,10 +422,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
solAssert(functionType); solAssert(functionType);
evmasm::AssemblyItem returnLabel = m_context.pushNewTag(); evmasm::AssemblyItem returnLabel = m_context.pushNewTag();
_unaryOperation.subExpression().accept(*this); _unaryOperation.subExpression().accept(*this);
utils().pushCombinedFunctionEntryLabel( m_context << m_context.functionEntryLabel(function).pushTag();
function.resolveVirtual(m_context.mostDerivedContract()),
false
);
unsigned parameterSize = unsigned parameterSize =
CompilerUtils::sizeOnStack(functionType->parameterTypes()) + CompilerUtils::sizeOnStack(functionType->parameterTypes()) +
@ -558,10 +555,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
acceptAndConvert(leftExpression, *functionType->selfType()); acceptAndConvert(leftExpression, *functionType->selfType());
acceptAndConvert(rightExpression, *functionType->parameterTypes().at(0)); acceptAndConvert(rightExpression, *functionType->parameterTypes().at(0));
utils().pushCombinedFunctionEntryLabel( m_context << m_context.functionEntryLabel(function).pushTag();
function.resolveVirtual(m_context.mostDerivedContract()),
false
);
unsigned parameterSize = unsigned parameterSize =
CompilerUtils::sizeOnStack(functionType->parameterTypes()) + CompilerUtils::sizeOnStack(functionType->parameterTypes()) +

View File

@ -680,6 +680,11 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
// TODO extract from function call // TODO extract from function call
FunctionDefinition const& function = *_unaryOperation.annotation().userDefinedFunction; FunctionDefinition const& function = *_unaryOperation.annotation().userDefinedFunction;
solAssert(
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*>( FunctionType const* functionType = dynamic_cast<FunctionType const*>(
function.libraryFunction() ? function.typeViaContractName() : function.type() function.libraryFunction() ? function.typeViaContractName() : function.type()
); );
@ -687,8 +692,6 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction(); functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
solAssert(functionType); solAssert(functionType);
// TODO virtual?
string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType()); string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType());
solAssert(!parameter.empty()); solAssert(!parameter.empty());
solAssert(function.isImplemented(), ""); solAssert(function.isImplemented(), "");
@ -812,6 +815,11 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
// TODO extract from function call // TODO extract from function call
FunctionDefinition const& function = *_binOp.annotation().userDefinedFunction; FunctionDefinition const& function = *_binOp.annotation().userDefinedFunction;
solAssert(
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*>( FunctionType const* functionType = dynamic_cast<FunctionType const*>(
function.libraryFunction() ? function.typeViaContractName() : function.type() function.libraryFunction() ? function.typeViaContractName() : function.type()
); );
@ -819,8 +827,6 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction(); functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
solAssert(functionType); solAssert(functionType);
// TODO virtual?
string left = expressionAsType(_binOp.leftExpression(), *functionType->selfType()); string left = expressionAsType(_binOp.leftExpression(), *functionType->selfType());
string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0)); string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0));
solAssert(!left.empty() && !right.empty()); solAssert(!left.empty() && !right.empty());