if (other is SByteConstant || other is ShortConstant || ic != null){
left = left.ToLong (loc);
right = right.ToLong (loc);
+ } else {
+ left = left.ToUInt (loc);
+ right = left.ToUInt (loc);
}
return;
+ } else if (left is DecimalConstant || right is DecimalConstant) {
+ if (!(left is DecimalConstant))
+ left = left.ToDecimal (loc);
+ else if (!(right is DecimalConstant))
+ right = right.ToDecimal (loc);
+ return;
} else if (left is EnumConstant || right is EnumConstant){
//
// If either operand is an enum constant, the other one must
left = ((EnumConstant) left).Child;
if (right is EnumConstant)
right = ((EnumConstant) right).Child;
+
+ DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
return;
} else {
DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
if (left == null || right == null)
return null;
-
+
if (left is IntConstant){
IntConstant v;
int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
((IntConstant) right).Value);
result = new IntConstant (res);
+ } else if (left is DecimalConstant) {
+ decimal res;
+
+ if (ec.ConstantCheckState)
+ res = checked (((DecimalConstant) left).Value +
+ ((DecimalConstant) right).Value);
+ else
+ res = unchecked (((DecimalConstant) left).Value +
+ ((DecimalConstant) right).Value);
+
+ result = new DecimalConstant (res);
} else {
- throw new Exception ( "Unexepected input: " + left);
+ throw new Exception ( "Unexepected addition input: " + left);
}
} catch (OverflowException){
Error_CompileTimeOverflow (loc);
((IntConstant) right).Value);
result = new IntConstant (res);
+ } else if (left is DecimalConstant) {
+ decimal res;
+
+ if (ec.ConstantCheckState)
+ res = checked (((DecimalConstant) left).Value -
+ ((DecimalConstant) right).Value);
+ else
+ res = unchecked (((DecimalConstant) left).Value -
+ ((DecimalConstant) right).Value);
+
+ return new DecimalConstant (res);
} else {
- throw new Exception ( "Unexepected input: " + left);
+ throw new Exception ( "Unexepected subtraction input: " + left);
}
} catch (OverflowException){
Error_CompileTimeOverflow (loc);
if (ec.ConstantCheckState)
res = checked (((DoubleConstant) left).Value *
- ((DoubleConstant) right).Value);
+ ((DoubleConstant) right).Value);
else
res = unchecked (((DoubleConstant) left).Value *
- ((DoubleConstant) right).Value);
+ ((DoubleConstant) right).Value);
return new DoubleConstant (res);
} else if (left is FloatConstant){
if (ec.ConstantCheckState)
res = checked (((FloatConstant) left).Value *
- ((FloatConstant) right).Value);
+ ((FloatConstant) right).Value);
else
res = unchecked (((FloatConstant) left).Value *
- ((FloatConstant) right).Value);
+ ((FloatConstant) right).Value);
return new FloatConstant (res);
} else if (left is ULongConstant){
if (ec.ConstantCheckState)
res = checked (((ULongConstant) left).Value *
- ((ULongConstant) right).Value);
+ ((ULongConstant) right).Value);
else
res = unchecked (((ULongConstant) left).Value *
- ((ULongConstant) right).Value);
+ ((ULongConstant) right).Value);
return new ULongConstant (res);
} else if (left is LongConstant){
if (ec.ConstantCheckState)
res = checked (((LongConstant) left).Value *
- ((LongConstant) right).Value);
+ ((LongConstant) right).Value);
else
res = unchecked (((LongConstant) left).Value *
- ((LongConstant) right).Value);
+ ((LongConstant) right).Value);
return new LongConstant (res);
} else if (left is UIntConstant){
if (ec.ConstantCheckState)
res = checked (((UIntConstant) left).Value *
- ((UIntConstant) right).Value);
+ ((UIntConstant) right).Value);
else
res = unchecked (((UIntConstant) left).Value *
- ((UIntConstant) right).Value);
+ ((UIntConstant) right).Value);
return new UIntConstant (res);
} else if (left is IntConstant){
if (ec.ConstantCheckState)
res = checked (((IntConstant) left).Value *
- ((IntConstant) right).Value);
+ ((IntConstant) right).Value);
else
res = unchecked (((IntConstant) left).Value *
- ((IntConstant) right).Value);
+ ((IntConstant) right).Value);
return new IntConstant (res);
+ } else if (left is DecimalConstant) {
+ decimal res;
+
+ if (ec.ConstantCheckState)
+ res = checked (((DecimalConstant) left).Value *
+ ((DecimalConstant) right).Value);
+ else
+ res = unchecked (((DecimalConstant) left).Value *
+ ((DecimalConstant) right).Value);
+
+ return new DecimalConstant (res);
} else {
- throw new Exception ( "Unexepected input: " + left);
+ throw new Exception ( "Unexepected multiply input: " + left);
}
} catch (OverflowException){
Error_CompileTimeOverflow (loc);
if (ec.ConstantCheckState)
res = checked (((DoubleConstant) left).Value /
- ((DoubleConstant) right).Value);
+ ((DoubleConstant) right).Value);
else
res = unchecked (((DoubleConstant) left).Value /
- ((DoubleConstant) right).Value);
+ ((DoubleConstant) right).Value);
return new DoubleConstant (res);
} else if (left is FloatConstant){
if (ec.ConstantCheckState)
res = checked (((FloatConstant) left).Value /
- ((FloatConstant) right).Value);
+ ((FloatConstant) right).Value);
else
res = unchecked (((FloatConstant) left).Value /
- ((FloatConstant) right).Value);
+ ((FloatConstant) right).Value);
return new FloatConstant (res);
} else if (left is ULongConstant){
if (ec.ConstantCheckState)
res = checked (((ULongConstant) left).Value /
- ((ULongConstant) right).Value);
+ ((ULongConstant) right).Value);
else
res = unchecked (((ULongConstant) left).Value /
- ((ULongConstant) right).Value);
+ ((ULongConstant) right).Value);
return new ULongConstant (res);
} else if (left is LongConstant){
if (ec.ConstantCheckState)
res = checked (((LongConstant) left).Value /
- ((LongConstant) right).Value);
+ ((LongConstant) right).Value);
else
res = unchecked (((LongConstant) left).Value /
- ((LongConstant) right).Value);
+ ((LongConstant) right).Value);
return new LongConstant (res);
} else if (left is UIntConstant){
if (ec.ConstantCheckState)
res = checked (((UIntConstant) left).Value /
- ((UIntConstant) right).Value);
+ ((UIntConstant) right).Value);
else
res = unchecked (((UIntConstant) left).Value /
- ((UIntConstant) right).Value);
+ ((UIntConstant) right).Value);
return new UIntConstant (res);
} else if (left is IntConstant){
if (ec.ConstantCheckState)
res = checked (((IntConstant) left).Value /
- ((IntConstant) right).Value);
+ ((IntConstant) right).Value);
else
res = unchecked (((IntConstant) left).Value /
- ((IntConstant) right).Value);
+ ((IntConstant) right).Value);
return new IntConstant (res);
+ } else if (left is DecimalConstant) {
+ decimal res;
+
+ if (ec.ConstantCheckState)
+ res = checked (((DecimalConstant) left).Value /
+ ((DecimalConstant) right).Value);
+ else
+ res = unchecked (((DecimalConstant) left).Value /
+ ((DecimalConstant) right).Value);
+
+ return new DecimalConstant (res);
} else {
- throw new Exception ( "Unexepected input: " + left);
+ throw new Exception ( "Unexepected division input: " + left);
}
} catch (OverflowException){
Error_CompileTimeOverflow (loc);
return new IntConstant (res);
} else {
- throw new Exception ( "Unexepected input: " + left);
+ throw new Exception ( "Unexepected modulus input: " + left);
}
} catch (DivideByZeroException){
Report.Error (020, loc, "Division by constant zero");
((BoolConstant) right).Value);
}
+ if (left is NullLiteral){
+ if (right is NullLiteral)
+ return new BoolConstant (true);
+ else if (right is StringConstant)
+ return new BoolConstant (
+ ((StringConstant) right).Value == null);
+ } else if (right is NullLiteral){
+ if (left is NullLiteral)
+ return new BoolConstant (true);
+ else if (left is StringConstant)
+ return new BoolConstant (
+ ((StringConstant) left).Value == null);
+ }
if (left is StringConstant && right is StringConstant){
return new BoolConstant (
((StringConstant) left).Value ==
((BoolConstant) left).Value !=
((BoolConstant) right).Value);
}
+ if (left is NullLiteral){
+ if (right is NullLiteral)
+ return new BoolConstant (false);
+ else if (right is StringConstant)
+ return new BoolConstant (
+ ((StringConstant) right).Value != null);
+ } else if (right is NullLiteral){
+ if (left is NullLiteral)
+ return new BoolConstant (false);
+ else if (left is StringConstant)
+ return new BoolConstant (
+ ((StringConstant) left).Value != null);
+ }
if (left is StringConstant && right is StringConstant){
return new BoolConstant (
((StringConstant) left).Value !=