2 // cfold.cs: Constant Folding
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2002 Ximian, Inc.
12 namespace Mono.CSharp {
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 case Binary.Operator.BitwiseOr:
201 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
202 if (left == null || right == null)
205 if (left is IntConstant){
207 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
209 v = new IntConstant (res);
210 if (result_type == null)
213 return new EnumConstant (v, result_type);
214 } else if (left is UIntConstant){
216 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
218 v = new UIntConstant (res);
219 if (result_type == null)
222 return new EnumConstant (v, result_type);
223 } else if (left is LongConstant){
225 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
227 v = new LongConstant (res);
228 if (result_type == null)
231 return new EnumConstant (v, result_type);
232 } else if (left is ULongConstant){
234 ulong res = ((ULongConstant)left).Value |
235 ((ULongConstant)right).Value;
237 v = new ULongConstant (res);
238 if (result_type == null)
241 return new EnumConstant (v, result_type);
245 case Binary.Operator.BitwiseAnd:
246 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
247 if (left == null || right == null)
250 if (left is IntConstant){
252 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
254 v = new IntConstant (res);
255 if (result_type == null)
258 return new EnumConstant (v, result_type);
259 } else if (left is UIntConstant){
261 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
263 v = new UIntConstant (res);
264 if (result_type == null)
267 return new EnumConstant (v, result_type);
268 } else if (left is LongConstant){
270 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
272 v = new LongConstant (res);
273 if (result_type == null)
276 return new EnumConstant (v, result_type);
277 } else if (left is ULongConstant){
279 ulong res = ((ULongConstant)left).Value &
280 ((ULongConstant)right).Value;
282 v = new ULongConstant (res);
283 if (result_type == null)
286 return new EnumConstant (v, result_type);
290 case Binary.Operator.ExclusiveOr:
291 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
292 if (left == null || right == null)
295 if (left is IntConstant){
297 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
299 v = new IntConstant (res);
300 if (result_type == null)
303 return new EnumConstant (v, result_type);
304 } else if (left is UIntConstant){
306 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
308 v = new UIntConstant (res);
309 if (result_type == null)
312 return new EnumConstant (v, result_type);
313 } else if (left is LongConstant){
315 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
317 v = new LongConstant (res);
318 if (result_type == null)
321 return new EnumConstant (v, result_type);
322 } else if (left is ULongConstant){
324 ulong res = ((ULongConstant)left).Value ^
325 ((ULongConstant)right).Value;
327 v = new ULongConstant (res);
328 if (result_type == null)
331 return new EnumConstant (v, result_type);
335 case Binary.Operator.Addition:
337 bool left_is_string = left is StringConstant;
338 bool right_is_string = right is StringConstant;
341 // If both sides are strings, then concatenate, if
342 // one is a string, and the other is not, then defer
343 // to runtime concatenation
345 if (left_is_string || right_is_string){
346 if (left_is_string && right_is_string)
347 return new StringConstant (
348 ((StringConstant) left).Value +
349 ((StringConstant) right).Value);
355 // handle "E operator + (E x, U y)"
356 // handle "E operator + (Y y, E x)"
358 // note that E operator + (E x, E y) is invalid
361 if (left is EnumConstant){
362 if (right is EnumConstant){
365 if (((EnumConstant) left).Child.Type != right.Type)
369 } else if (right is EnumConstant){
370 if (((EnumConstant) right).Child.Type != left.Type)
372 wrap_as = right.Type;
376 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
377 if (left == null || right == null)
381 if (left is DoubleConstant){
384 if (ec.ConstantCheckState)
385 res = checked (((DoubleConstant) left).Value +
386 ((DoubleConstant) right).Value);
388 res = unchecked (((DoubleConstant) left).Value +
389 ((DoubleConstant) right).Value);
391 result = new DoubleConstant (res);
392 } else if (left is FloatConstant){
395 if (ec.ConstantCheckState)
396 res = checked (((FloatConstant) left).Value +
397 ((FloatConstant) right).Value);
399 res = unchecked (((FloatConstant) left).Value +
400 ((FloatConstant) right).Value);
402 result = new FloatConstant (res);
403 } else if (left is ULongConstant){
406 if (ec.ConstantCheckState)
407 res = checked (((ULongConstant) left).Value +
408 ((ULongConstant) right).Value);
410 res = unchecked (((ULongConstant) left).Value +
411 ((ULongConstant) right).Value);
413 result = new ULongConstant (res);
414 } else if (left is LongConstant){
417 if (ec.ConstantCheckState)
418 res = checked (((LongConstant) left).Value +
419 ((LongConstant) right).Value);
421 res = unchecked (((LongConstant) left).Value +
422 ((LongConstant) right).Value);
424 result = new LongConstant (res);
425 } else if (left is UIntConstant){
428 if (ec.ConstantCheckState)
429 res = checked (((UIntConstant) left).Value +
430 ((UIntConstant) right).Value);
432 res = unchecked (((UIntConstant) left).Value +
433 ((UIntConstant) right).Value);
435 result = new UIntConstant (res);
436 } else if (left is IntConstant){
439 if (ec.ConstantCheckState)
440 res = checked (((IntConstant) left).Value +
441 ((IntConstant) right).Value);
443 res = unchecked (((IntConstant) left).Value +
444 ((IntConstant) right).Value);
446 result = new IntConstant (res);
448 throw new Exception ( "Unexepected input: " + left);
450 } catch (OverflowException){
451 Error_CompileTimeOverflow (loc);
455 return new EnumConstant (result, wrap_as);
459 case Binary.Operator.Subtraction:
460 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
461 if (left == null || right == null)
465 if (left is DoubleConstant){
468 if (ec.ConstantCheckState)
469 res = checked (((DoubleConstant) left).Value -
470 ((DoubleConstant) right).Value);
472 res = unchecked (((DoubleConstant) left).Value -
473 ((DoubleConstant) right).Value);
475 return new DoubleConstant (res);
476 } else if (left is FloatConstant){
479 if (ec.ConstantCheckState)
480 res = checked (((FloatConstant) left).Value -
481 ((FloatConstant) right).Value);
483 res = unchecked (((FloatConstant) left).Value -
484 ((FloatConstant) right).Value);
486 return new FloatConstant (res);
487 } else if (left is ULongConstant){
490 if (ec.ConstantCheckState)
491 res = checked (((ULongConstant) left).Value -
492 ((ULongConstant) right).Value);
494 res = unchecked (((ULongConstant) left).Value -
495 ((ULongConstant) right).Value);
497 return new ULongConstant (res);
498 } else if (left is LongConstant){
501 if (ec.ConstantCheckState)
502 res = checked (((LongConstant) left).Value -
503 ((LongConstant) right).Value);
505 res = unchecked (((LongConstant) left).Value -
506 ((LongConstant) right).Value);
508 return new LongConstant (res);
509 } else if (left is UIntConstant){
512 if (ec.ConstantCheckState)
513 res = checked (((UIntConstant) left).Value -
514 ((UIntConstant) right).Value);
516 res = unchecked (((UIntConstant) left).Value -
517 ((UIntConstant) right).Value);
519 return new UIntConstant (res);
520 } else if (left is IntConstant){
523 if (ec.ConstantCheckState)
524 res = checked (((IntConstant) left).Value -
525 ((IntConstant) right).Value);
527 res = unchecked (((IntConstant) left).Value -
528 ((IntConstant) right).Value);
530 return new IntConstant (res);
532 throw new Exception ( "Unexepected input: " + left);
534 } catch (OverflowException){
535 Error_CompileTimeOverflow (loc);
539 case Binary.Operator.Multiply:
540 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
541 if (left == null || right == null)
545 if (left is DoubleConstant){
548 if (ec.ConstantCheckState)
549 res = checked (((DoubleConstant) left).Value *
550 ((DoubleConstant) right).Value);
552 res = unchecked (((DoubleConstant) left).Value *
553 ((DoubleConstant) right).Value);
555 return new DoubleConstant (res);
556 } else if (left is FloatConstant){
559 if (ec.ConstantCheckState)
560 res = checked (((FloatConstant) left).Value *
561 ((FloatConstant) right).Value);
563 res = unchecked (((FloatConstant) left).Value *
564 ((FloatConstant) right).Value);
566 return new FloatConstant (res);
567 } else if (left is ULongConstant){
570 if (ec.ConstantCheckState)
571 res = checked (((ULongConstant) left).Value *
572 ((ULongConstant) right).Value);
574 res = unchecked (((ULongConstant) left).Value *
575 ((ULongConstant) right).Value);
577 return new ULongConstant (res);
578 } else if (left is LongConstant){
581 if (ec.ConstantCheckState)
582 res = checked (((LongConstant) left).Value *
583 ((LongConstant) right).Value);
585 res = unchecked (((LongConstant) left).Value *
586 ((LongConstant) right).Value);
588 return new LongConstant (res);
589 } else if (left is UIntConstant){
592 if (ec.ConstantCheckState)
593 res = checked (((UIntConstant) left).Value *
594 ((UIntConstant) right).Value);
596 res = unchecked (((UIntConstant) left).Value *
597 ((UIntConstant) right).Value);
599 return new UIntConstant (res);
600 } else if (left is IntConstant){
603 if (ec.ConstantCheckState)
604 res = checked (((IntConstant) left).Value *
605 ((IntConstant) right).Value);
607 res = unchecked (((IntConstant) left).Value *
608 ((IntConstant) right).Value);
610 return new IntConstant (res);
612 throw new Exception ( "Unexepected input: " + left);
614 } catch (OverflowException){
615 Error_CompileTimeOverflow (loc);
619 case Binary.Operator.Division:
620 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
621 if (left == null || right == null)
625 if (left is DoubleConstant){
628 if (ec.ConstantCheckState)
629 res = checked (((DoubleConstant) left).Value /
630 ((DoubleConstant) right).Value);
632 res = unchecked (((DoubleConstant) left).Value /
633 ((DoubleConstant) right).Value);
635 return new DoubleConstant (res);
636 } else if (left is FloatConstant){
639 if (ec.ConstantCheckState)
640 res = checked (((FloatConstant) left).Value /
641 ((FloatConstant) right).Value);
643 res = unchecked (((FloatConstant) left).Value /
644 ((FloatConstant) right).Value);
646 return new FloatConstant (res);
647 } else if (left is ULongConstant){
650 if (ec.ConstantCheckState)
651 res = checked (((ULongConstant) left).Value /
652 ((ULongConstant) right).Value);
654 res = unchecked (((ULongConstant) left).Value /
655 ((ULongConstant) right).Value);
657 return new ULongConstant (res);
658 } else if (left is LongConstant){
661 if (ec.ConstantCheckState)
662 res = checked (((LongConstant) left).Value /
663 ((LongConstant) right).Value);
665 res = unchecked (((LongConstant) left).Value /
666 ((LongConstant) right).Value);
668 return new LongConstant (res);
669 } else if (left is UIntConstant){
672 if (ec.ConstantCheckState)
673 res = checked (((UIntConstant) left).Value /
674 ((UIntConstant) right).Value);
676 res = unchecked (((UIntConstant) left).Value /
677 ((UIntConstant) right).Value);
679 return new UIntConstant (res);
680 } else if (left is IntConstant){
683 if (ec.ConstantCheckState)
684 res = checked (((IntConstant) left).Value /
685 ((IntConstant) right).Value);
687 res = unchecked (((IntConstant) left).Value /
688 ((IntConstant) right).Value);
690 return new IntConstant (res);
692 throw new Exception ( "Unexepected input: " + left);
694 } catch (OverflowException){
695 Error_CompileTimeOverflow (loc);
697 } catch (DivideByZeroException) {
698 Report.Error (020, loc, "Division by constant zero");
703 case Binary.Operator.Modulus:
704 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
705 if (left == null || right == null)
709 if (left is DoubleConstant){
712 if (ec.ConstantCheckState)
713 res = checked (((DoubleConstant) left).Value %
714 ((DoubleConstant) right).Value);
716 res = unchecked (((DoubleConstant) left).Value %
717 ((DoubleConstant) right).Value);
719 return new DoubleConstant (res);
720 } else if (left is FloatConstant){
723 if (ec.ConstantCheckState)
724 res = checked (((FloatConstant) left).Value %
725 ((FloatConstant) right).Value);
727 res = unchecked (((FloatConstant) left).Value %
728 ((FloatConstant) right).Value);
730 return new FloatConstant (res);
731 } else if (left is ULongConstant){
734 if (ec.ConstantCheckState)
735 res = checked (((ULongConstant) left).Value %
736 ((ULongConstant) right).Value);
738 res = unchecked (((ULongConstant) left).Value %
739 ((ULongConstant) right).Value);
741 return new ULongConstant (res);
742 } else if (left is LongConstant){
745 if (ec.ConstantCheckState)
746 res = checked (((LongConstant) left).Value %
747 ((LongConstant) right).Value);
749 res = unchecked (((LongConstant) left).Value %
750 ((LongConstant) right).Value);
752 return new LongConstant (res);
753 } else if (left is UIntConstant){
756 if (ec.ConstantCheckState)
757 res = checked (((UIntConstant) left).Value %
758 ((UIntConstant) right).Value);
760 res = unchecked (((UIntConstant) left).Value %
761 ((UIntConstant) right).Value);
763 return new UIntConstant (res);
764 } else if (left is IntConstant){
767 if (ec.ConstantCheckState)
768 res = checked (((IntConstant) left).Value %
769 ((IntConstant) right).Value);
771 res = unchecked (((IntConstant) left).Value %
772 ((IntConstant) right).Value);
774 return new IntConstant (res);
776 throw new Exception ( "Unexepected input: " + left);
778 } catch (OverflowException){
779 Error_CompileTimeOverflow (loc);
784 // There is no overflow checking on left shift
786 case Binary.Operator.LeftShift:
787 IntConstant ic = right.ToInt (loc);
789 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
792 int lshift_val = ic.Value;
795 if ((lic = left.ConvertToInt ()) != null)
796 return new IntConstant (lic.Value << lshift_val);
799 if ((luic = left.ConvertToUInt ()) != null)
800 return new UIntConstant (luic.Value << lshift_val);
803 if ((llc = left.ConvertToLong ()) != null)
804 return new LongConstant (llc.Value << lshift_val);
807 if ((lulc = left.ConvertToULong ()) != null)
808 return new ULongConstant (lulc.Value << lshift_val);
810 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
814 // There is no overflow checking on right shift
816 case Binary.Operator.RightShift:
817 IntConstant sic = right.ToInt (loc);
819 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
822 int rshift_val = sic.Value;
825 if ((ric = left.ConvertToInt ()) != null)
826 return new IntConstant (ric.Value >> rshift_val);
829 if ((ruic = left.ConvertToUInt ()) != null)
830 return new UIntConstant (ruic.Value >> rshift_val);
833 if ((rlc = left.ConvertToLong ()) != null)
834 return new LongConstant (rlc.Value >> rshift_val);
837 if ((rulc = left.ConvertToULong ()) != null)
838 return new ULongConstant (rulc.Value >> rshift_val);
840 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
843 case Binary.Operator.LogicalAnd:
844 if (left is BoolConstant && right is BoolConstant){
845 return new BoolConstant (
846 ((BoolConstant) left).Value &&
847 ((BoolConstant) right).Value);
851 case Binary.Operator.LogicalOr:
852 if (left is BoolConstant && right is BoolConstant){
853 return new BoolConstant (
854 ((BoolConstant) left).Value ||
855 ((BoolConstant) right).Value);
859 case Binary.Operator.Equality:
860 if (left is BoolConstant && right is BoolConstant){
861 return new BoolConstant (
862 ((BoolConstant) left).Value ==
863 ((BoolConstant) right).Value);
866 if (left is StringConstant && right is StringConstant){
867 return new BoolConstant (
868 ((StringConstant) left).Value ==
869 ((StringConstant) right).Value);
873 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
874 if (left == null || right == null)
878 if (left is DoubleConstant)
879 bool_res = ((DoubleConstant) left).Value ==
880 ((DoubleConstant) right).Value;
881 else if (left is FloatConstant)
882 bool_res = ((FloatConstant) left).Value ==
883 ((FloatConstant) right).Value;
884 else if (left is ULongConstant)
885 bool_res = ((ULongConstant) left).Value ==
886 ((ULongConstant) right).Value;
887 else if (left is LongConstant)
888 bool_res = ((LongConstant) left).Value ==
889 ((LongConstant) right).Value;
890 else if (left is UIntConstant)
891 bool_res = ((UIntConstant) left).Value ==
892 ((UIntConstant) right).Value;
893 else if (left is IntConstant)
894 bool_res = ((IntConstant) left).Value ==
895 ((IntConstant) right).Value;
899 return new BoolConstant (bool_res);
901 case Binary.Operator.Inequality:
902 if (left is BoolConstant && right is BoolConstant){
903 return new BoolConstant (
904 ((BoolConstant) left).Value !=
905 ((BoolConstant) right).Value);
907 if (left is StringConstant && right is StringConstant){
908 return new BoolConstant (
909 ((StringConstant) left).Value !=
910 ((StringConstant) right).Value);
913 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
914 if (left == null || right == null)
918 if (left is DoubleConstant)
919 bool_res = ((DoubleConstant) left).Value !=
920 ((DoubleConstant) right).Value;
921 else if (left is FloatConstant)
922 bool_res = ((FloatConstant) left).Value !=
923 ((FloatConstant) right).Value;
924 else if (left is ULongConstant)
925 bool_res = ((ULongConstant) left).Value !=
926 ((ULongConstant) right).Value;
927 else if (left is LongConstant)
928 bool_res = ((LongConstant) left).Value !=
929 ((LongConstant) right).Value;
930 else if (left is UIntConstant)
931 bool_res = ((UIntConstant) left).Value !=
932 ((UIntConstant) right).Value;
933 else if (left is IntConstant)
934 bool_res = ((IntConstant) left).Value !=
935 ((IntConstant) right).Value;
939 return new BoolConstant (bool_res);
941 case Binary.Operator.LessThan:
942 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
943 if (left == null || right == null)
947 if (left is DoubleConstant)
948 bool_res = ((DoubleConstant) left).Value <
949 ((DoubleConstant) right).Value;
950 else if (left is FloatConstant)
951 bool_res = ((FloatConstant) left).Value <
952 ((FloatConstant) right).Value;
953 else if (left is ULongConstant)
954 bool_res = ((ULongConstant) left).Value <
955 ((ULongConstant) right).Value;
956 else if (left is LongConstant)
957 bool_res = ((LongConstant) left).Value <
958 ((LongConstant) right).Value;
959 else if (left is UIntConstant)
960 bool_res = ((UIntConstant) left).Value <
961 ((UIntConstant) right).Value;
962 else if (left is IntConstant)
963 bool_res = ((IntConstant) left).Value <
964 ((IntConstant) right).Value;
968 return new BoolConstant (bool_res);
970 case Binary.Operator.GreaterThan:
971 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
972 if (left == null || right == null)
976 if (left is DoubleConstant)
977 bool_res = ((DoubleConstant) left).Value >
978 ((DoubleConstant) right).Value;
979 else if (left is FloatConstant)
980 bool_res = ((FloatConstant) left).Value >
981 ((FloatConstant) right).Value;
982 else if (left is ULongConstant)
983 bool_res = ((ULongConstant) left).Value >
984 ((ULongConstant) right).Value;
985 else if (left is LongConstant)
986 bool_res = ((LongConstant) left).Value >
987 ((LongConstant) right).Value;
988 else if (left is UIntConstant)
989 bool_res = ((UIntConstant) left).Value >
990 ((UIntConstant) right).Value;
991 else if (left is IntConstant)
992 bool_res = ((IntConstant) left).Value >
993 ((IntConstant) right).Value;
997 return new BoolConstant (bool_res);
999 case Binary.Operator.GreaterThanOrEqual:
1000 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1001 if (left == null || right == null)
1005 if (left is DoubleConstant)
1006 bool_res = ((DoubleConstant) left).Value >=
1007 ((DoubleConstant) right).Value;
1008 else if (left is FloatConstant)
1009 bool_res = ((FloatConstant) left).Value >=
1010 ((FloatConstant) right).Value;
1011 else if (left is ULongConstant)
1012 bool_res = ((ULongConstant) left).Value >=
1013 ((ULongConstant) right).Value;
1014 else if (left is LongConstant)
1015 bool_res = ((LongConstant) left).Value >=
1016 ((LongConstant) right).Value;
1017 else if (left is UIntConstant)
1018 bool_res = ((UIntConstant) left).Value >=
1019 ((UIntConstant) right).Value;
1020 else if (left is IntConstant)
1021 bool_res = ((IntConstant) left).Value >=
1022 ((IntConstant) right).Value;
1026 return new BoolConstant (bool_res);
1028 case Binary.Operator.LessThanOrEqual:
1029 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1030 if (left == null || right == null)
1034 if (left is DoubleConstant)
1035 bool_res = ((DoubleConstant) left).Value <=
1036 ((DoubleConstant) right).Value;
1037 else if (left is FloatConstant)
1038 bool_res = ((FloatConstant) left).Value <=
1039 ((FloatConstant) right).Value;
1040 else if (left is ULongConstant)
1041 bool_res = ((ULongConstant) left).Value <=
1042 ((ULongConstant) right).Value;
1043 else if (left is LongConstant)
1044 bool_res = ((LongConstant) left).Value <=
1045 ((LongConstant) right).Value;
1046 else if (left is UIntConstant)
1047 bool_res = ((UIntConstant) left).Value <=
1048 ((UIntConstant) right).Value;
1049 else if (left is IntConstant)
1050 bool_res = ((IntConstant) left).Value <=
1051 ((IntConstant) right).Value;
1055 return new BoolConstant (bool_res);