From d3d28e96a8c1804a1569f64734571744bec8f96c Mon Sep 17 00:00:00 2001 From: wechman Date: Fri, 8 Jul 2022 11:20:14 +0200 Subject: [PATCH] Update code to review comments --- libsolidity/codegen/ExpressionCompiler.cpp | 10 ++-------- .../codegen/ir/IRGeneratorForStatements.cpp | 14 ++++++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 68d2547a2..d6963462f 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -422,10 +422,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation) solAssert(functionType); evmasm::AssemblyItem returnLabel = m_context.pushNewTag(); _unaryOperation.subExpression().accept(*this); - utils().pushCombinedFunctionEntryLabel( - function.resolveVirtual(m_context.mostDerivedContract()), - false - ); + m_context << m_context.functionEntryLabel(function).pushTag(); unsigned parameterSize = CompilerUtils::sizeOnStack(functionType->parameterTypes()) + @@ -558,10 +555,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation) acceptAndConvert(leftExpression, *functionType->selfType()); acceptAndConvert(rightExpression, *functionType->parameterTypes().at(0)); - utils().pushCombinedFunctionEntryLabel( - function.resolveVirtual(m_context.mostDerivedContract()), - false - ); + m_context << m_context.functionEntryLabel(function).pushTag(); unsigned parameterSize = CompilerUtils::sizeOnStack(functionType->parameterTypes()) + diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index f23307faf..c1e8bf4c1 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -680,6 +680,11 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation) // TODO extract from function call FunctionDefinition const& function = *_unaryOperation.annotation().userDefinedFunction; + solAssert( + dynamic_cast(function.scope()), + "Only file-level functions and library functions can be bound to a user type operator." + ); + FunctionType const* functionType = dynamic_cast( function.libraryFunction() ? function.typeViaContractName() : function.type() ); @@ -687,8 +692,6 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation) functionType = dynamic_cast(*functionType).asBoundFunction(); solAssert(functionType); - // TODO virtual? - string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType()); solAssert(!parameter.empty()); solAssert(function.isImplemented(), ""); @@ -812,6 +815,11 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp) // TODO extract from function call FunctionDefinition const& function = *_binOp.annotation().userDefinedFunction; + solAssert( + dynamic_cast(function.scope()), + "Only file-level functions and library functions can be bound to a user type operator." + ); + FunctionType const* functionType = dynamic_cast( function.libraryFunction() ? function.typeViaContractName() : function.type() ); @@ -819,8 +827,6 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp) functionType = dynamic_cast(*functionType).asBoundFunction(); solAssert(functionType); - // TODO virtual? - string left = expressionAsType(_binOp.leftExpression(), *functionType->selfType()); string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0)); solAssert(!left.empty() && !right.empty());