switch (oper){
case Binary.Operator.BitwiseOr:
//
- // bool? operator &(bool? x, bool? y);
+ // bool? operator |(bool? x, bool? y);
//
if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
(rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
- var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ var b = new Binary (oper, left, right).ResolveOperator (ec);
// false | null => null
// null | false => null
//
if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
(rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
- var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ var b = new Binary (oper, left, right).ResolveOperator (ec);
// false & null => false
// null & false => false
return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is FloatConstant){
- float res;
-
+ double a, b, res;
+ a = ((FloatConstant) left).DoubleValue;
+ b = ((FloatConstant) right).DoubleValue;
+
if (ec.ConstantCheckState)
- res = checked (((FloatConstant) left).Value +
- ((FloatConstant) right).Value);
+ res = checked (a + b);
else
- res = unchecked (((FloatConstant) left).Value +
- ((FloatConstant) right).Value);
+ res = unchecked (a + b);
result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
result = new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
- float res;
-
+ double a, b, res;
+ a = ((FloatConstant) left).DoubleValue;
+ b = ((FloatConstant) right).DoubleValue;
+
if (ec.ConstantCheckState)
- res = checked (((FloatConstant) left).Value -
- ((FloatConstant) right).Value);
+ res = checked (a - b);
else
- res = unchecked (((FloatConstant) left).Value -
- ((FloatConstant) right).Value);
+ res = unchecked (a - b);
result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
- float res;
-
+ double a, b, res;
+ a = ((FloatConstant) left).DoubleValue;
+ b = ((FloatConstant) right).DoubleValue;
+
if (ec.ConstantCheckState)
- res = checked (((FloatConstant) left).Value *
- ((FloatConstant) right).Value);
+ res = checked (a * b);
else
- res = unchecked (((FloatConstant) left).Value *
- ((FloatConstant) right).Value);
+ res = unchecked (a * b);
return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
- float res;
-
+ double a, b, res;
+ a = ((FloatConstant) left).DoubleValue;
+ b = ((FloatConstant) right).DoubleValue;
+
if (ec.ConstantCheckState)
- res = checked (((FloatConstant) left).Value /
- ((FloatConstant) right).Value);
+ res = checked (a / b);
else
- res = unchecked (((FloatConstant) left).Value /
- ((FloatConstant) right).Value);
+ res = unchecked (a / b);
return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
- float res;
+ double a, b, res;
+ a = ((FloatConstant) left).DoubleValue;
+ b = ((FloatConstant) right).DoubleValue;
if (ec.ConstantCheckState)
- res = checked (((FloatConstant) left).Value %
- ((FloatConstant) right).Value);
+ res = checked (a % b);
else
- res = unchecked (((FloatConstant) left).Value %
- ((FloatConstant) right).Value);
+ res = unchecked (a % b);
return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
IntConstant ic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
if (ic == null){
- Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
return null;
}
// null << value => null
if (left is NullLiteral)
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, left, right).ResolveOperator (ec);
left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value << lshift_val, left.Location);
- Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
- break;
+ return null;
//
// There is no overflow checking on right shift
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
if (sic == null){
- Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
return null;
}
int rshift_val = sic.Value;
// null >> value => null
if (left is NullLiteral)
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, left, right).ResolveOperator (ec);
left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value >> rshift_val, left.Location);
- Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
- break;
+ return null;
case Binary.Operator.Equality:
if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
bool_res = ((DoubleConstant) left).Value ==
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value ==
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue ==
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value ==
((ULongConstant) right).Value;
bool_res = ((DoubleConstant) left).Value !=
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value !=
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue !=
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value !=
((ULongConstant) right).Value;
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
- }
-
- if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
}
bool_res = ((DoubleConstant) left).Value <
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value <
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue <
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value <
((ULongConstant) right).Value;
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
- }
-
- if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
}
bool_res = ((DoubleConstant) left).Value >
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value >
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue >
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value >
((ULongConstant) right).Value;
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
- }
-
- if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
}
bool_res = ((DoubleConstant) left).Value >=
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value >=
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue >=
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value >=
((ULongConstant) right).Value;
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
lifted_int.ResolveAsType (ec);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
- }
-
- if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
+ return (Constant) new Binary (oper, lifted_int, right).ResolveOperator (ec);
}
}
bool_res = ((DoubleConstant) left).Value <=
((DoubleConstant) right).Value;
else if (left is FloatConstant)
- bool_res = ((FloatConstant) left).Value <=
- ((FloatConstant) right).Value;
+ bool_res = ((FloatConstant) left).DoubleValue <=
+ ((FloatConstant) right).DoubleValue;
else if (left is ULongConstant)
bool_res = ((ULongConstant) left).Value <=
((ULongConstant) right).Value;
return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
}
-
+
return null;
}
}