mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Comparison operations.
This commit is contained in:
@@ -203,14 +203,45 @@ void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
||||
{
|
||||
solAssert(!!_binOp.annotation().commonType, "");
|
||||
TypePointer commonType = _binOp.annotation().commonType;
|
||||
langutil::Token op = _binOp.getOperator();
|
||||
|
||||
if (_binOp.getOperator() == Token::And || _binOp.getOperator() == Token::Or)
|
||||
if (op == Token::And || op == Token::Or)
|
||||
// special case: short-circuiting
|
||||
solUnimplementedAssert(false, "");
|
||||
else if (commonType->category() == Type::Category::RationalNumber)
|
||||
defineExpression(_binOp) <<
|
||||
toCompactHexWithPrefix(commonType->literalValue(nullptr)) <<
|
||||
"\n";
|
||||
else if (TokenTraits::isCompareOp(op))
|
||||
{
|
||||
solUnimplementedAssert(commonType->category() != Type::Category::Function, "");
|
||||
solAssert(commonType->isValueType(), "");
|
||||
bool isSigned = false;
|
||||
if (auto type = dynamic_cast<IntegerType const*>(commonType))
|
||||
isSigned = type->isSigned();
|
||||
|
||||
string args =
|
||||
expressionAsType(_binOp.leftExpression(), *commonType) +
|
||||
", " +
|
||||
expressionAsType(_binOp.rightExpression(), *commonType);
|
||||
|
||||
string expr;
|
||||
if (op == Token::Equal)
|
||||
expr = "eq(" + move(args) + ")";
|
||||
else if (op == Token::NotEqual)
|
||||
expr = "iszero(eq(" + move(args) + "))";
|
||||
else if (op == Token::GreaterThanOrEqual)
|
||||
expr = "iszero(" + string(isSigned ? "slt(" : "lt(") + move(args) + "))";
|
||||
else if (op == Token::LessThanOrEqual)
|
||||
expr = "iszero(" + string(isSigned ? "sgt(" : "gt(") + move(args) + "))";
|
||||
else if (op == Token::GreaterThan)
|
||||
expr = (isSigned ? "sgt(" : "gt(") + move(args) + ")";
|
||||
else if (op == Token::LessThan)
|
||||
expr = (isSigned ? "slt(" : "lt(") + move(args) + ")";
|
||||
else
|
||||
solAssert(false, "Unknown comparison operator.");
|
||||
defineExpression(_binOp) << expr << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
solUnimplementedAssert(_binOp.getOperator() == Token::Add, "");
|
||||
|
||||
Reference in New Issue
Block a user