Adjust code to review findings

This commit is contained in:
wechman
2022-09-28 13:06:25 +02:00
parent 1084a34f28
commit a8bf1f255d
5 changed files with 52 additions and 30 deletions
@@ -689,11 +689,23 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
solAssert(functionType);
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
solAssert(functionType);
solAssert(
functionType->parameterTypes().size() == 0,
"Functions with parameters other than self parameter cannot be bound to a user type unary operator."
);
string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType());
solAssert(!parameter.empty());
solAssert(function->isImplemented(), "");
solAssert(
function->returnParameters().size() == 1,
"A function bound to the user type operator is supposed to return exactly one value."
);
solAssert(*_unaryOperation.annotation().type == *function->returnParameters().at(0)->type(),
"A return type of the bound function is supposed to be same as a operator type."
);
define(_unaryOperation) <<
m_context.enqueueFunctionForCodeGeneration(*function) <<
("(" + parameter + ")\n");
@@ -821,6 +833,10 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
solAssert(functionType);
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
solAssert(functionType);
solAssert(
functionType->parameterTypes().size() == 1,
"Only functions with one parameter other than self parameter can be bound to a user type binary operator."
);
string left = expressionAsType(_binOp.leftExpression(), *functionType->selfType());
string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0));
@@ -828,6 +844,14 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
solAssert(function->isImplemented(), "");
solAssert(
function->returnParameters().size() == 1,
"A function bound to the user type operator is supposed to return exactly one value."
);
solAssert(*_binOp.annotation().type == *function->returnParameters().at(0)->type(),
"A return type of the bound function is supposed to be same as a operator type."
);
define(_binOp) <<
m_context.enqueueFunctionForCodeGeneration(*function) <<
("(" + left + ", " + right + ")\n");