{
if (operationType == null || leftType == null || rightType == null)
{
return null;
}
HaxeType intType = TypeUtils.getInt();
switch (operationType)
{
//If both expressions are Int then return Int, else if both
//expressions are either Int or Float then return Float, else return String.
case PLUS:
if (leftType.equals(intType) && rightType.equals(intType))
{
return intType;
}
HaxeType floatType = TypeUtils.getFloat();
if ((leftType.equals(intType) || rightType.equals(intType)) &&
(leftType.equals(floatType) || rightType.equals(floatType)))
{
return floatType;
}
return TypeUtils.getString();
//Divide two numbers, return Float.
case DIVIDE:
if (TypeUtils.areBothNumbers(leftType, rightType))
{
return TypeUtils.getFloat();
}
break;
// Return Int if both are Int and return Float
// if they are either both Float or mixed.
case NUMERABLE:
if (TypeUtils.areBothNumbers(leftType, rightType))
{
return TypeUtils.getCommonPrimaryType(leftType, rightType);
}
break;
// bitwise operations between two Int expressions. Returns Int.
case BITWISE:
if (leftType.equals(intType) && rightType.equals(intType))
{
return intType;
}
break;
//perform normal or physical comparisons between two
//expressions sharing a common type. Returns Bool.
//TODO we can compare two strings ???????
case COMPARISON:
if (TypeUtils.isComparable(leftType, rightType))
{
return TypeUtils.getBool();
}
break;
//Both e1 and e2 must be Bool
case BOOLEAN:
HaxeType bool = TypeUtils.getBool();
if (leftType.equals(bool) && rightType.equals(bool))
{
return leftType;
}
break;