2 // cfold.cs: Constant Folding
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2002 Ximian, Inc.
12 namespace Mono.MonoBASIC {
14 public class ConstantFold {
17 // Performs the numeric promotions on the left and right expresions
18 // and desposits the results on `lc' and `rc'.
20 // On success, the types of `lc' and `rc' on output will always match,
21 // and the pair will be one of:
30 static void DoConstantNumericPromotions (EmitContext ec, Binary.Operator oper,
31 ref Constant left, ref Constant right,
34 if (left is DoubleConstant || right is DoubleConstant){
36 // If either side is a double, convert the other to a double
38 if (!(left is DoubleConstant))
39 left = left.ToDouble (loc);
41 if (!(right is DoubleConstant))
42 right = right.ToDouble (loc);
44 } else if (left is FloatConstant || right is FloatConstant) {
46 // If either side is a float, convert the other to a float
48 if (!(left is FloatConstant))
49 left = left.ToFloat (loc);
51 if (!(right is FloatConstant))
52 right = right.ToFloat (loc);
54 } else if (left is ULongConstant || right is ULongConstant){
56 // If either operand is of type ulong, the other operand is
57 // converted to type ulong. or an error ocurrs if the other
58 // operand is of type sbyte, short, int or long
60 Constant match, other;
62 if (left is ULongConstant){
65 if (!(right is ULongConstant))
66 right = right.ToULong (loc);
70 left = left.ToULong (loc);
74 if (other is SByteConstant || other is ShortConstant ||
75 other is IntConstant || other is LongConstant){
76 Binary.Error_OperatorAmbiguous
77 (loc, oper, other.Type, match.Type);
83 } else if (left is LongConstant || right is LongConstant){
85 // If either operand is of type long, the other operand is converted
88 if (!(left is LongConstant))
89 left = left.ToLong (loc);
90 else if (!(right is LongConstant))
91 right = right.ToLong (loc);
93 } else if (left is UIntConstant || right is UIntConstant){
95 // If either operand is of type uint, and the other
96 // operand is of type sbyte, short or int, the operands are
97 // converted to type long.
99 Constant match, other;
100 if (left is UIntConstant){
109 if (other is UIntConstant)
112 if (other is SByteConstant || other is ShortConstant ||
113 other is IntConstant){
114 left = left.ToLong (loc);
115 right = right.ToLong (loc);
119 } else if (left is EnumConstant || right is EnumConstant){
121 // If either operand is an enum constant, the other one must
122 // be implicitly convertable to that enum's underlying type.
126 if (left is EnumConstant){
128 match = (EnumConstant) left;
131 match = (EnumConstant) right;
134 bool need_check = (other is EnumConstant) ||
135 ((oper != Binary.Operator.Addition) &&
136 (oper != Binary.Operator.Subtraction));
139 !Expression.ImplicitConversionExists (ec, match, other.Type)) {
140 Expression.Error_CannotConvertImplicit (loc, match.Type, other.Type);
146 if (left is EnumConstant)
147 left = ((EnumConstant) left).Child;
148 if (right is EnumConstant)
149 right = ((EnumConstant) right).Child;
154 // Force conversions to int32
156 if (!(left is IntConstant))
157 left = left.ToInt (loc);
158 if (!(right is IntConstant))
159 right = right.ToInt (loc);
164 static void Error_CompileTimeOverflow (Location loc)
166 Report.Error (220, loc, "The operation overflows at compile time in checked mode");
170 /// Constant expression folder for binary operations.
172 /// Returns null if the expression can not be folded.
174 static public Expression BinaryFold (EmitContext ec, Binary.Operator oper,
175 Constant left, Constant right, Location loc)
178 Type rt = right.Type;
179 Type result_type = null;
183 // Enumerator folding
185 if (rt == lt && left is EnumConstant)
189 // During an enum evaluation, we need to unwrap enumerations
191 if (ec.InEnumContext){
192 if (left is EnumConstant)
193 left = ((EnumConstant) left).Child;
195 if (right is EnumConstant)
196 right = ((EnumConstant) right).Child;
200 Constant result = null;
202 case Binary.Operator.BitwiseOr:
203 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
204 if (left == null || right == null)
207 if (left is IntConstant){
209 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
211 v = new IntConstant (res);
212 if (result_type == null)
215 return new EnumConstant (v, result_type);
216 } else if (left is UIntConstant){
218 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
220 v = new UIntConstant (res);
221 if (result_type == null)
224 return new EnumConstant (v, result_type);
225 } else if (left is LongConstant){
227 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
229 v = new LongConstant (res);
230 if (result_type == null)
233 return new EnumConstant (v, result_type);
234 } else if (left is ULongConstant){
236 ulong res = ((ULongConstant)left).Value |
237 ((ULongConstant)right).Value;
239 v = new ULongConstant (res);
240 if (result_type == null)
243 return new EnumConstant (v, result_type);
247 case Binary.Operator.BitwiseAnd:
248 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
249 if (left == null || right == null)
252 if (left is IntConstant){
254 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
256 v = new IntConstant (res);
257 if (result_type == null)
260 return new EnumConstant (v, result_type);
261 } else if (left is UIntConstant){
263 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
265 v = new UIntConstant (res);
266 if (result_type == null)
269 return new EnumConstant (v, result_type);
270 } else if (left is LongConstant){
272 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
274 v = new LongConstant (res);
275 if (result_type == null)
278 return new EnumConstant (v, result_type);
279 } else if (left is ULongConstant){
281 ulong res = ((ULongConstant)left).Value &
282 ((ULongConstant)right).Value;
284 v = new ULongConstant (res);
285 if (result_type == null)
288 return new EnumConstant (v, result_type);
292 case Binary.Operator.ExclusiveOr:
293 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
294 if (left == null || right == null)
297 if (left is IntConstant){
299 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
301 v = new IntConstant (res);
302 if (result_type == null)
305 return new EnumConstant (v, result_type);
306 } else if (left is UIntConstant){
308 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
310 v = new UIntConstant (res);
311 if (result_type == null)
314 return new EnumConstant (v, result_type);
315 } else if (left is LongConstant){
317 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
319 v = new LongConstant (res);
320 if (result_type == null)
323 return new EnumConstant (v, result_type);
324 } else if (left is ULongConstant){
326 ulong res = ((ULongConstant)left).Value ^
327 ((ULongConstant)right).Value;
329 v = new ULongConstant (res);
330 if (result_type == null)
333 return new EnumConstant (v, result_type);
337 case Binary.Operator.Addition:
338 bool left_is_string = left is StringConstant;
339 bool right_is_string = right is StringConstant;
342 // If both sides are strings, then concatenate, if
343 // one is a string, and the other is not, then defer
344 // to runtime concatenation
347 if (left_is_string || right_is_string){
348 if (left_is_string && right_is_string)
349 return new StringConstant (
350 ((StringConstant) left).Value +
351 ((StringConstant) right).Value);
357 // handle "E operator + (E x, U y)"
358 // handle "E operator + (Y y, E x)"
360 // note that E operator + (E x, E y) is invalid
362 if (left is EnumConstant){
363 if (right is EnumConstant){
366 if (((EnumConstant) left).Child.Type != right.Type)
370 } else if (right is EnumConstant){
371 if (((EnumConstant) right).Child.Type != left.Type)
373 wrap_as = right.Type;
377 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
378 if (left == null || right == null)
382 if (left is DoubleConstant){
385 if (ec.ConstantCheckState)
386 res = checked (((DoubleConstant) left).Value +
387 ((DoubleConstant) right).Value);
389 res = unchecked (((DoubleConstant) left).Value +
390 ((DoubleConstant) right).Value);
392 result = new DoubleConstant (res);
393 } else if (left is FloatConstant){
396 if (ec.ConstantCheckState)
397 res = checked (((FloatConstant) left).Value +
398 ((FloatConstant) right).Value);
400 res = unchecked (((FloatConstant) left).Value +
401 ((FloatConstant) right).Value);
403 result = new FloatConstant (res);
404 } else if (left is ULongConstant){
407 if (ec.ConstantCheckState)
408 res = checked (((ULongConstant) left).Value +
409 ((ULongConstant) right).Value);
411 res = unchecked (((ULongConstant) left).Value +
412 ((ULongConstant) right).Value);
414 result = new ULongConstant (res);
415 } else if (left is LongConstant){
418 if (ec.ConstantCheckState)
419 res = checked (((LongConstant) left).Value +
420 ((LongConstant) right).Value);
422 res = unchecked (((LongConstant) left).Value +
423 ((LongConstant) right).Value);
425 result = new LongConstant (res);
426 } else if (left is UIntConstant){
429 if (ec.ConstantCheckState)
430 res = checked (((UIntConstant) left).Value +
431 ((UIntConstant) right).Value);
433 res = unchecked (((UIntConstant) left).Value +
434 ((UIntConstant) right).Value);
436 result = new UIntConstant (res);
437 } else if (left is IntConstant){
440 if (ec.ConstantCheckState)
441 res = checked (((IntConstant) left).Value +
442 ((IntConstant) right).Value);
444 res = unchecked (((IntConstant) left).Value +
445 ((IntConstant) right).Value);
447 result = new IntConstant (res);
449 throw new Exception ( "Unexepected input: " + left);
451 } catch (OverflowException){
452 Error_CompileTimeOverflow (loc);
456 return new EnumConstant (result, wrap_as);
460 case Binary.Operator.Subtraction:
462 // handle "E operator - (E x, U y)"
463 // handle "E operator - (Y y, E x)"
464 // handle "U operator - (E x, E y)"
467 if (left is EnumConstant){
468 if (right is EnumConstant){
469 if (left.Type == right.Type)
470 wrap_as = TypeManager.EnumToUnderlying (left.Type);
474 if (((EnumConstant) left).Child.Type != right.Type)
478 } else if (right is EnumConstant){
479 if (((EnumConstant) right).Child.Type != left.Type)
481 wrap_as = right.Type;
484 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
485 if (left == null || right == null)
489 if (left is DoubleConstant){
492 if (ec.ConstantCheckState)
493 res = checked (((DoubleConstant) left).Value -
494 ((DoubleConstant) right).Value);
496 res = unchecked (((DoubleConstant) left).Value -
497 ((DoubleConstant) right).Value);
499 result = new DoubleConstant (res);
500 } else if (left is FloatConstant){
503 if (ec.ConstantCheckState)
504 res = checked (((FloatConstant) left).Value -
505 ((FloatConstant) right).Value);
507 res = unchecked (((FloatConstant) left).Value -
508 ((FloatConstant) right).Value);
510 result = new FloatConstant (res);
511 } else if (left is ULongConstant){
514 if (ec.ConstantCheckState)
515 res = checked (((ULongConstant) left).Value -
516 ((ULongConstant) right).Value);
518 res = unchecked (((ULongConstant) left).Value -
519 ((ULongConstant) right).Value);
521 result = new ULongConstant (res);
522 } else if (left is LongConstant){
525 if (ec.ConstantCheckState)
526 res = checked (((LongConstant) left).Value -
527 ((LongConstant) right).Value);
529 res = unchecked (((LongConstant) left).Value -
530 ((LongConstant) right).Value);
532 result = new LongConstant (res);
533 } else if (left is UIntConstant){
536 if (ec.ConstantCheckState)
537 res = checked (((UIntConstant) left).Value -
538 ((UIntConstant) right).Value);
540 res = unchecked (((UIntConstant) left).Value -
541 ((UIntConstant) right).Value);
543 result = new UIntConstant (res);
544 } else if (left is IntConstant){
547 if (ec.ConstantCheckState)
548 res = checked (((IntConstant) left).Value -
549 ((IntConstant) right).Value);
551 res = unchecked (((IntConstant) left).Value -
552 ((IntConstant) right).Value);
554 result = new IntConstant (res);
556 throw new Exception ( "Unexepected input: " + left);
558 } catch (OverflowException){
559 Error_CompileTimeOverflow (loc);
562 return new EnumConstant (result, wrap_as);
566 case Binary.Operator.Multiply:
567 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
568 if (left == null || right == null)
572 if (left is DoubleConstant){
575 if (ec.ConstantCheckState)
576 res = checked (((DoubleConstant) left).Value *
577 ((DoubleConstant) right).Value);
579 res = unchecked (((DoubleConstant) left).Value *
580 ((DoubleConstant) right).Value);
582 return new DoubleConstant (res);
583 } else if (left is FloatConstant){
586 if (ec.ConstantCheckState)
587 res = checked (((FloatConstant) left).Value *
588 ((FloatConstant) right).Value);
590 res = unchecked (((FloatConstant) left).Value *
591 ((FloatConstant) right).Value);
593 return new FloatConstant (res);
594 } else if (left is ULongConstant){
597 if (ec.ConstantCheckState)
598 res = checked (((ULongConstant) left).Value *
599 ((ULongConstant) right).Value);
601 res = unchecked (((ULongConstant) left).Value *
602 ((ULongConstant) right).Value);
604 return new ULongConstant (res);
605 } else if (left is LongConstant){
608 if (ec.ConstantCheckState)
609 res = checked (((LongConstant) left).Value *
610 ((LongConstant) right).Value);
612 res = unchecked (((LongConstant) left).Value *
613 ((LongConstant) right).Value);
615 return new LongConstant (res);
616 } else if (left is UIntConstant){
619 if (ec.ConstantCheckState)
620 res = checked (((UIntConstant) left).Value *
621 ((UIntConstant) right).Value);
623 res = unchecked (((UIntConstant) left).Value *
624 ((UIntConstant) right).Value);
626 return new UIntConstant (res);
627 } else if (left is IntConstant){
630 if (ec.ConstantCheckState)
631 res = checked (((IntConstant) left).Value *
632 ((IntConstant) right).Value);
634 res = unchecked (((IntConstant) left).Value *
635 ((IntConstant) right).Value);
637 return new IntConstant (res);
639 throw new Exception ( "Unexepected input: " + left);
641 } catch (OverflowException){
642 Error_CompileTimeOverflow (loc);
646 case Binary.Operator.Division:
647 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
648 if (left == null || right == null)
652 if (left is DoubleConstant){
655 if (ec.ConstantCheckState)
656 res = checked (((DoubleConstant) left).Value /
657 ((DoubleConstant) right).Value);
659 res = unchecked (((DoubleConstant) left).Value /
660 ((DoubleConstant) right).Value);
662 return new DoubleConstant (res);
663 } else if (left is FloatConstant){
666 if (ec.ConstantCheckState)
667 res = checked (((FloatConstant) left).Value /
668 ((FloatConstant) right).Value);
670 res = unchecked (((FloatConstant) left).Value /
671 ((FloatConstant) right).Value);
673 return new FloatConstant (res);
674 } else if (left is ULongConstant){
677 if (ec.ConstantCheckState)
678 res = checked (((ULongConstant) left).Value /
679 ((ULongConstant) right).Value);
681 res = unchecked (((ULongConstant) left).Value /
682 ((ULongConstant) right).Value);
684 return new ULongConstant (res);
685 } else if (left is LongConstant){
688 if (ec.ConstantCheckState)
689 res = checked (((LongConstant) left).Value /
690 ((LongConstant) right).Value);
692 res = unchecked (((LongConstant) left).Value /
693 ((LongConstant) right).Value);
695 return new LongConstant (res);
696 } else if (left is UIntConstant){
699 if (ec.ConstantCheckState)
700 res = checked (((UIntConstant) left).Value /
701 ((UIntConstant) right).Value);
703 res = unchecked (((UIntConstant) left).Value /
704 ((UIntConstant) right).Value);
706 return new UIntConstant (res);
707 } else if (left is IntConstant){
710 if (ec.ConstantCheckState)
711 res = checked (((IntConstant) left).Value /
712 ((IntConstant) right).Value);
714 res = unchecked (((IntConstant) left).Value /
715 ((IntConstant) right).Value);
717 return new IntConstant (res);
719 throw new Exception ( "Unexepected input: " + left);
721 } catch (OverflowException){
722 Error_CompileTimeOverflow (loc);
724 } catch (DivideByZeroException) {
725 Report.Error (020, loc, "Division by constant zero");
730 case Binary.Operator.Modulus:
731 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
732 if (left == null || right == null)
736 if (left is DoubleConstant){
739 if (ec.ConstantCheckState)
740 res = checked (((DoubleConstant) left).Value %
741 ((DoubleConstant) right).Value);
743 res = unchecked (((DoubleConstant) left).Value %
744 ((DoubleConstant) right).Value);
746 return new DoubleConstant (res);
747 } else if (left is FloatConstant){
750 if (ec.ConstantCheckState)
751 res = checked (((FloatConstant) left).Value %
752 ((FloatConstant) right).Value);
754 res = unchecked (((FloatConstant) left).Value %
755 ((FloatConstant) right).Value);
757 return new FloatConstant (res);
758 } else if (left is ULongConstant){
761 if (ec.ConstantCheckState)
762 res = checked (((ULongConstant) left).Value %
763 ((ULongConstant) right).Value);
765 res = unchecked (((ULongConstant) left).Value %
766 ((ULongConstant) right).Value);
768 return new ULongConstant (res);
769 } else if (left is LongConstant){
772 if (ec.ConstantCheckState)
773 res = checked (((LongConstant) left).Value %
774 ((LongConstant) right).Value);
776 res = unchecked (((LongConstant) left).Value %
777 ((LongConstant) right).Value);
779 return new LongConstant (res);
780 } else if (left is UIntConstant){
783 if (ec.ConstantCheckState)
784 res = checked (((UIntConstant) left).Value %
785 ((UIntConstant) right).Value);
787 res = unchecked (((UIntConstant) left).Value %
788 ((UIntConstant) right).Value);
790 return new UIntConstant (res);
791 } else if (left is IntConstant){
794 if (ec.ConstantCheckState)
795 res = checked (((IntConstant) left).Value %
796 ((IntConstant) right).Value);
798 res = unchecked (((IntConstant) left).Value %
799 ((IntConstant) right).Value);
801 return new IntConstant (res);
803 throw new Exception ( "Unexepected input: " + left);
805 } catch (OverflowException){
806 Error_CompileTimeOverflow (loc);
811 // There is no overflow checking on left shift
813 case Binary.Operator.LeftShift:
814 IntConstant ic = right.ToInt (loc);
816 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
819 int lshift_val = ic.Value;
822 if ((lic = left.ConvertToInt ()) != null)
823 return new IntConstant (lic.Value << lshift_val);
826 if ((luic = left.ConvertToUInt ()) != null)
827 return new UIntConstant (luic.Value << lshift_val);
830 if ((llc = left.ConvertToLong ()) != null)
831 return new LongConstant (llc.Value << lshift_val);
834 if ((lulc = left.ConvertToULong ()) != null)
835 return new ULongConstant (lulc.Value << lshift_val);
837 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
841 // There is no overflow checking on right shift
843 case Binary.Operator.RightShift:
844 IntConstant sic = right.ToInt (loc);
846 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
849 int rshift_val = sic.Value;
852 if ((ric = left.ConvertToInt ()) != null)
853 return new IntConstant (ric.Value >> rshift_val);
856 if ((ruic = left.ConvertToUInt ()) != null)
857 return new UIntConstant (ruic.Value >> rshift_val);
860 if ((rlc = left.ConvertToLong ()) != null)
861 return new LongConstant (rlc.Value >> rshift_val);
864 if ((rulc = left.ConvertToULong ()) != null)
865 return new ULongConstant (rulc.Value >> rshift_val);
867 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
870 case Binary.Operator.LogicalAnd:
871 if (left is BoolConstant && right is BoolConstant){
872 return new BoolConstant (
873 ((BoolConstant) left).Value &&
874 ((BoolConstant) right).Value);
878 case Binary.Operator.LogicalOr:
879 if (left is BoolConstant && right is BoolConstant){
880 return new BoolConstant (
881 ((BoolConstant) left).Value ||
882 ((BoolConstant) right).Value);
886 case Binary.Operator.Equality:
887 if (left is BoolConstant && right is BoolConstant){
888 return new BoolConstant (
889 ((BoolConstant) left).Value ==
890 ((BoolConstant) right).Value);
893 if (left is StringConstant && right is StringConstant){
894 return new BoolConstant (
895 ((StringConstant) left).Value ==
896 ((StringConstant) right).Value);
900 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
901 if (left == null || right == null)
905 if (left is DoubleConstant)
906 bool_res = ((DoubleConstant) left).Value ==
907 ((DoubleConstant) right).Value;
908 else if (left is FloatConstant)
909 bool_res = ((FloatConstant) left).Value ==
910 ((FloatConstant) right).Value;
911 else if (left is ULongConstant)
912 bool_res = ((ULongConstant) left).Value ==
913 ((ULongConstant) right).Value;
914 else if (left is LongConstant)
915 bool_res = ((LongConstant) left).Value ==
916 ((LongConstant) right).Value;
917 else if (left is UIntConstant)
918 bool_res = ((UIntConstant) left).Value ==
919 ((UIntConstant) right).Value;
920 else if (left is IntConstant)
921 bool_res = ((IntConstant) left).Value ==
922 ((IntConstant) right).Value;
926 return new BoolConstant (bool_res);
928 case Binary.Operator.Inequality:
929 if (left is BoolConstant && right is BoolConstant){
930 return new BoolConstant (
931 ((BoolConstant) left).Value !=
932 ((BoolConstant) right).Value);
934 if (left is StringConstant && right is StringConstant){
935 return new BoolConstant (
936 ((StringConstant) left).Value !=
937 ((StringConstant) right).Value);
940 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
941 if (left == null || right == null)
945 if (left is DoubleConstant)
946 bool_res = ((DoubleConstant) left).Value !=
947 ((DoubleConstant) right).Value;
948 else if (left is FloatConstant)
949 bool_res = ((FloatConstant) left).Value !=
950 ((FloatConstant) right).Value;
951 else if (left is ULongConstant)
952 bool_res = ((ULongConstant) left).Value !=
953 ((ULongConstant) right).Value;
954 else if (left is LongConstant)
955 bool_res = ((LongConstant) left).Value !=
956 ((LongConstant) right).Value;
957 else if (left is UIntConstant)
958 bool_res = ((UIntConstant) left).Value !=
959 ((UIntConstant) right).Value;
960 else if (left is IntConstant)
961 bool_res = ((IntConstant) left).Value !=
962 ((IntConstant) right).Value;
966 return new BoolConstant (bool_res);
968 case Binary.Operator.LessThan:
969 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
970 if (left == null || right == null)
974 if (left is DoubleConstant)
975 bool_res = ((DoubleConstant) left).Value <
976 ((DoubleConstant) right).Value;
977 else if (left is FloatConstant)
978 bool_res = ((FloatConstant) left).Value <
979 ((FloatConstant) right).Value;
980 else if (left is ULongConstant)
981 bool_res = ((ULongConstant) left).Value <
982 ((ULongConstant) right).Value;
983 else if (left is LongConstant)
984 bool_res = ((LongConstant) left).Value <
985 ((LongConstant) right).Value;
986 else if (left is UIntConstant)
987 bool_res = ((UIntConstant) left).Value <
988 ((UIntConstant) right).Value;
989 else if (left is IntConstant)
990 bool_res = ((IntConstant) left).Value <
991 ((IntConstant) right).Value;
995 return new BoolConstant (bool_res);
997 case Binary.Operator.GreaterThan:
998 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
999 if (left == null || right == null)
1003 if (left is DoubleConstant)
1004 bool_res = ((DoubleConstant) left).Value >
1005 ((DoubleConstant) right).Value;
1006 else if (left is FloatConstant)
1007 bool_res = ((FloatConstant) left).Value >
1008 ((FloatConstant) right).Value;
1009 else if (left is ULongConstant)
1010 bool_res = ((ULongConstant) left).Value >
1011 ((ULongConstant) right).Value;
1012 else if (left is LongConstant)
1013 bool_res = ((LongConstant) left).Value >
1014 ((LongConstant) right).Value;
1015 else if (left is UIntConstant)
1016 bool_res = ((UIntConstant) left).Value >
1017 ((UIntConstant) right).Value;
1018 else if (left is IntConstant)
1019 bool_res = ((IntConstant) left).Value >
1020 ((IntConstant) right).Value;
1024 return new BoolConstant (bool_res);
1026 case Binary.Operator.GreaterThanOrEqual:
1027 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1028 if (left == null || right == null)
1032 if (left is DoubleConstant)
1033 bool_res = ((DoubleConstant) left).Value >=
1034 ((DoubleConstant) right).Value;
1035 else if (left is FloatConstant)
1036 bool_res = ((FloatConstant) left).Value >=
1037 ((FloatConstant) right).Value;
1038 else if (left is ULongConstant)
1039 bool_res = ((ULongConstant) left).Value >=
1040 ((ULongConstant) right).Value;
1041 else if (left is LongConstant)
1042 bool_res = ((LongConstant) left).Value >=
1043 ((LongConstant) right).Value;
1044 else if (left is UIntConstant)
1045 bool_res = ((UIntConstant) left).Value >=
1046 ((UIntConstant) right).Value;
1047 else if (left is IntConstant)
1048 bool_res = ((IntConstant) left).Value >=
1049 ((IntConstant) right).Value;
1053 return new BoolConstant (bool_res);
1055 case Binary.Operator.LessThanOrEqual:
1056 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1057 if (left == null || right == null)
1061 if (left is DoubleConstant)
1062 bool_res = ((DoubleConstant) left).Value <=
1063 ((DoubleConstant) right).Value;
1064 else if (left is FloatConstant)
1065 bool_res = ((FloatConstant) left).Value <=
1066 ((FloatConstant) right).Value;
1067 else if (left is ULongConstant)
1068 bool_res = ((ULongConstant) left).Value <=
1069 ((ULongConstant) right).Value;
1070 else if (left is LongConstant)
1071 bool_res = ((LongConstant) left).Value <=
1072 ((LongConstant) right).Value;
1073 else if (left is UIntConstant)
1074 bool_res = ((UIntConstant) left).Value <=
1075 ((UIntConstant) right).Value;
1076 else if (left is IntConstant)
1077 bool_res = ((IntConstant) left).Value <=
1078 ((IntConstant) right).Value;
1082 return new BoolConstant (bool_res);