Conversion during binary operation.

This commit is contained in:
chriseth 2019-04-25 00:10:29 +02:00
parent 597d37b731
commit 0eef51ffa4

View File

@ -189,10 +189,24 @@ bool IRGeneratorForStatements::visit(Return const& _return)
} }
void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp) void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
{
solAssert(!!_binOp.annotation().commonType, "");
TypePointer commonType = _binOp.annotation().commonType;
if (_binOp.getOperator() == Token::And || _binOp.getOperator() == Token::Or)
// special case: short-circuiting
solUnimplementedAssert(false, "");
else if (commonType->category() == Type::Category::RationalNumber)
m_code <<
"let " <<
m_context.variable(_binOp) <<
" := " <<
toCompactHexWithPrefix(commonType->literalValue(nullptr)) <<
"\n";
else
{ {
solUnimplementedAssert(_binOp.getOperator() == Token::Add, ""); solUnimplementedAssert(_binOp.getOperator() == Token::Add, "");
solUnimplementedAssert(*_binOp.leftExpression().annotation().type == *_binOp.rightExpression().annotation().type, ""); if (IntegerType const* type = dynamic_cast<IntegerType const*>(commonType))
if (IntegerType const* type = dynamic_cast<IntegerType const*>(_binOp.annotation().commonType))
{ {
solUnimplementedAssert(!type->isSigned(), ""); solUnimplementedAssert(!type->isSigned(), "");
m_code << m_code <<
@ -201,14 +215,15 @@ void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
" := " << " := " <<
m_utils.overflowCheckedUIntAddFunction(type->numBits()) << m_utils.overflowCheckedUIntAddFunction(type->numBits()) <<
"(" << "(" <<
m_context.variable(_binOp.leftExpression()) << expressionAsType(_binOp.leftExpression(), *commonType) <<
", " << ", " <<
m_context.variable(_binOp.rightExpression()) << expressionAsType(_binOp.rightExpression(), *commonType) <<
")\n"; ")\n";
} }
else else
solUnimplementedAssert(false, ""); solUnimplementedAssert(false, "");
} }
}
bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall) bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
{ {