aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-05 04:29:36 +0800
committerChristian <c@ethdev.com>2014-11-06 09:36:39 +0800
commit95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7 (patch)
tree1653e65dfdb4530985214f54cc0c72dc32cdb69a /ExpressionCompiler.cpp
parent13baaf98b8a3ca2a97c96e5a25398a0cae26e5fb (diff)
downloaddexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar.gz
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar.bz2
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar.lz
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar.xz
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.tar.zst
dexon-solidity-95d2edfbac4dff62ac987a9fe0fc58fbce76e5b7.zip
Type promotion fixes and tests.
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index 0df74184..324cd10d 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -136,15 +136,9 @@ bool ExpressionCompiler::visit(BinaryOperation& _binaryOperation)
cleanupNeeded = true;
leftExpression.accept(*this);
- if (cleanupNeeded)
- appendHighBitsCleanup(dynamic_cast<IntegerType const&>(*leftExpression.getType()));
- else
- appendTypeConversion(*leftExpression.getType(), commonType);
+ appendTypeConversion(*leftExpression.getType(), commonType, cleanupNeeded);
rightExpression.accept(*this);
- if (cleanupNeeded)
- appendHighBitsCleanup(dynamic_cast<IntegerType const&>(*leftExpression.getType()));
- else
- appendTypeConversion(*rightExpression.getType(), commonType);
+ appendTypeConversion(*rightExpression.getType(), commonType, cleanupNeeded);
if (Token::isCompareOp(op))
appendCompareOperatorCode(op, commonType);
else
@@ -368,20 +362,20 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator)
}
}
-void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType)
+void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded)
{
// If the type of one of the operands is extended, we need to remove all
// higher-order bits that we might have ignored in previous operations.
// @todo: store in the AST whether the operand might have "dirty" higher
// order bits
- if (_typeOnStack == _targetType)
+ if (_typeOnStack == _targetType && !_cleanupNeeded)
return;
if (_typeOnStack.getCategory() == Type::Category::INTEGER)
{
appendHighBitsCleanup(dynamic_cast<IntegerType const&>(_typeOnStack));
}
- else
+ else if (_typeOnStack != _targetType)
{
// All other types should not be convertible to non-equal types.
assert(!_typeOnStack.isExplicitlyConvertibleTo(_targetType));