From 29c9a7aed90e415bcf5eebb16228336576643a3f Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 4 Nov 2014 15:01:07 +0100 Subject: Allow implicit type conversions for comparisons. --- ExpressionCompiler.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'ExpressionCompiler.cpp') diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index d23579b1..a7d87221 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -113,7 +113,7 @@ bool ExpressionCompiler::visit(BinaryOperation& _binaryOperation) { Expression& leftExpression = _binaryOperation.getLeftExpression(); Expression& rightExpression = _binaryOperation.getRightExpression(); - Type const& resultType = *_binaryOperation.getType(); + Type const& commonType = _binaryOperation.getCommonType(); Token::Value const op = _binaryOperation.getOperator(); if (op == Token::AND || op == Token::OR) @@ -121,23 +121,16 @@ bool ExpressionCompiler::visit(BinaryOperation& _binaryOperation) // special case: short-circuiting appendAndOrOperatorCode(_binaryOperation); } - else if (Token::isCompareOp(op)) - { - leftExpression.accept(*this); - rightExpression.accept(*this); - - // the types to compare have to be the same, but the resulting type is always bool - if (asserts(*leftExpression.getType() == *rightExpression.getType())) - BOOST_THROW_EXCEPTION(InternalCompilerError()); - appendCompareOperatorCode(op, *leftExpression.getType()); - } else { leftExpression.accept(*this); - cleanHigherOrderBitsIfNeeded(*leftExpression.getType(), resultType); + cleanHigherOrderBitsIfNeeded(*leftExpression.getType(), commonType); rightExpression.accept(*this); - cleanHigherOrderBitsIfNeeded(*rightExpression.getType(), resultType); - appendOrdinaryBinaryOperatorCode(op, resultType); + cleanHigherOrderBitsIfNeeded(*rightExpression.getType(), commonType); + if (Token::isCompareOp(op)) + appendCompareOperatorCode(op, commonType); + else + appendOrdinaryBinaryOperatorCode(op, commonType); } // do not visit the child nodes, we already did that explicitly -- cgit v1.2.3