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 (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, othe operands are
97 // converted to type long.
99 if (!(left is UIntConstant))
100 left = left.ToUInt (loc);
101 else if (!(right is UIntConstant))
102 right = right.ToUInt (loc);
106 // Force conversions to int32
108 if (!(left is IntConstant))
109 left = left.ToInt (loc);
110 if (!(right is IntConstant))
111 right = right.ToInt (loc);
116 static void Error_CompileTimeOverflow (Location loc)
118 Report.Error (220, loc, "The operation overflows at compile time in checked mode");
122 /// Constant expression folder for binary operations.
124 /// Returns null if the expression can not be folded.
126 static public Expression BinaryFold (EmitContext ec, Binary.Operator oper,
127 Constant left, Constant right, Location loc)
130 Type rt = right.Type;
131 Type result_type = null;
135 // Enumerator folding
137 if (rt == lt && left is EnumConstant)
141 // During an enum evaluation, we need to unwrap enumerations
143 if (ec.InEnumContext){
144 if (left is EnumConstant)
145 left = ((EnumConstant) left).Child;
147 if (right is EnumConstant)
148 right = ((EnumConstant) right).Child;
152 case Binary.Operator.BitwiseOr:
153 DoConstantNumericPromotions (oper, ref left, ref right, loc);
154 if (left == null || right == null)
157 if (left is IntConstant){
159 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
161 v = new IntConstant (res);
162 if (result_type == null)
165 return new EnumConstant (v, result_type);
166 } else if (left is UIntConstant){
168 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
170 v = new UIntConstant (res);
171 if (result_type == null)
174 return new EnumConstant (v, result_type);
175 } else if (left is LongConstant){
177 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
179 v = new LongConstant (res);
180 if (result_type == null)
183 return new EnumConstant (v, result_type);
184 } else if (left is ULongConstant){
186 ulong res = ((ULongConstant)left).Value |
187 ((ULongConstant)right).Value;
189 v = new ULongConstant (res);
190 if (result_type == null)
193 return new EnumConstant (v, result_type);
197 case Binary.Operator.BitwiseAnd:
198 DoConstantNumericPromotions (oper, ref left, ref right, loc);
199 if (left == null || right == null)
202 if (left is IntConstant){
204 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
206 v = new IntConstant (res);
207 if (result_type == null)
210 return new EnumConstant (v, result_type);
211 } else if (left is UIntConstant){
213 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
215 v = new UIntConstant (res);
216 if (result_type == null)
219 return new EnumConstant (v, result_type);
220 } else if (left is LongConstant){
222 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
224 v = new LongConstant (res);
225 if (result_type == null)
228 return new EnumConstant (v, result_type);
229 } else if (left is ULongConstant){
231 ulong res = ((ULongConstant)left).Value &
232 ((ULongConstant)right).Value;
234 v = new ULongConstant (res);
235 if (result_type == null)
238 return new EnumConstant (v, result_type);
242 case Binary.Operator.ExclusiveOr:
243 DoConstantNumericPromotions (oper, ref left, ref right, loc);
244 if (left == null || right == null)
247 if (left is IntConstant){
249 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
251 v = new IntConstant (res);
252 if (result_type == null)
255 return new EnumConstant (v, result_type);
256 } else if (left is UIntConstant){
258 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
260 v = new UIntConstant (res);
261 if (result_type == null)
264 return new EnumConstant (v, result_type);
265 } else if (left is LongConstant){
267 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
269 v = new LongConstant (res);
270 if (result_type == null)
273 return new EnumConstant (v, result_type);
274 } else if (left is ULongConstant){
276 ulong res = ((ULongConstant)left).Value ^
277 ((ULongConstant)right).Value;
279 v = new ULongConstant (res);
280 if (result_type == null)
283 return new EnumConstant (v, result_type);
287 case Binary.Operator.Addition:
289 bool left_is_string = left is StringConstant;
290 bool right_is_string = right is StringConstant;
293 // If both sides are strings, then concatenate, if
294 // one is a string, and the other is not, then defer
295 // to runtime concatenation
297 if (left_is_string || right_is_string){
298 if (left_is_string && right_is_string)
299 return new StringConstant (
300 ((StringConstant) left).Value +
301 ((StringConstant) right).Value);
307 // handle "E operator + (E x, U y)"
308 // handle "E operator + (Y y, E x)"
310 // note that E operator + (E x, E y) is invalid
313 if (left is EnumConstant){
314 if (right is EnumConstant){
317 if (((EnumConstant) left).Child.Type != right.Type)
321 } else if (right is EnumConstant){
322 if (((EnumConstant) right).Child.Type != left.Type)
324 wrap_as = right.Type;
328 DoConstantNumericPromotions (oper, ref left, ref right, loc);
329 if (left == null || right == null)
333 if (left is DoubleConstant){
336 if (ec.ConstantCheckState)
337 res = checked (((DoubleConstant) left).Value +
338 ((DoubleConstant) right).Value);
340 res = unchecked (((DoubleConstant) left).Value +
341 ((DoubleConstant) right).Value);
343 result = new DoubleConstant (res);
344 } else if (left is FloatConstant){
347 if (ec.ConstantCheckState)
348 res = checked (((FloatConstant) left).Value +
349 ((FloatConstant) right).Value);
351 res = unchecked (((FloatConstant) left).Value +
352 ((FloatConstant) right).Value);
354 result = new FloatConstant (res);
355 } else if (left is ULongConstant){
358 if (ec.ConstantCheckState)
359 res = checked (((ULongConstant) left).Value +
360 ((ULongConstant) right).Value);
362 res = unchecked (((ULongConstant) left).Value +
363 ((ULongConstant) right).Value);
365 result = new ULongConstant (res);
366 } else if (left is LongConstant){
369 if (ec.ConstantCheckState)
370 res = checked (((LongConstant) left).Value +
371 ((LongConstant) right).Value);
373 res = unchecked (((LongConstant) left).Value +
374 ((LongConstant) right).Value);
376 result = new LongConstant (res);
377 } else if (left is UIntConstant){
380 if (ec.ConstantCheckState)
381 res = checked (((UIntConstant) left).Value +
382 ((UIntConstant) right).Value);
384 res = unchecked (((UIntConstant) left).Value +
385 ((UIntConstant) right).Value);
387 result = new UIntConstant (res);
388 } else if (left is IntConstant){
391 if (ec.ConstantCheckState)
392 res = checked (((IntConstant) left).Value +
393 ((IntConstant) right).Value);
395 res = unchecked (((IntConstant) left).Value +
396 ((IntConstant) right).Value);
398 result = new IntConstant (res);
400 throw new Exception ( "Unexepected input: " + left);
402 } catch (OverflowException){
403 Error_CompileTimeOverflow (loc);
407 return new EnumConstant (result, wrap_as);
411 case Binary.Operator.Subtraction:
412 DoConstantNumericPromotions (oper, ref left, ref right, loc);
413 if (left == null || right == null)
417 if (left is DoubleConstant){
420 if (ec.ConstantCheckState)
421 res = checked (((DoubleConstant) left).Value -
422 ((DoubleConstant) right).Value);
424 res = unchecked (((DoubleConstant) left).Value -
425 ((DoubleConstant) right).Value);
427 return new DoubleConstant (res);
428 } else if (left is FloatConstant){
431 if (ec.ConstantCheckState)
432 res = checked (((FloatConstant) left).Value -
433 ((FloatConstant) right).Value);
435 res = unchecked (((FloatConstant) left).Value -
436 ((FloatConstant) right).Value);
438 return new FloatConstant (res);
439 } else if (left is ULongConstant){
442 if (ec.ConstantCheckState)
443 res = checked (((ULongConstant) left).Value -
444 ((ULongConstant) right).Value);
446 res = unchecked (((ULongConstant) left).Value -
447 ((ULongConstant) right).Value);
449 return new ULongConstant (res);
450 } else if (left is LongConstant){
453 if (ec.ConstantCheckState)
454 res = checked (((LongConstant) left).Value -
455 ((LongConstant) right).Value);
457 res = unchecked (((LongConstant) left).Value -
458 ((LongConstant) right).Value);
460 return new LongConstant (res);
461 } else if (left is UIntConstant){
464 if (ec.ConstantCheckState)
465 res = checked (((UIntConstant) left).Value -
466 ((UIntConstant) right).Value);
468 res = unchecked (((UIntConstant) left).Value -
469 ((UIntConstant) right).Value);
471 return new UIntConstant (res);
472 } else if (left is IntConstant){
475 if (ec.ConstantCheckState)
476 res = checked (((IntConstant) left).Value -
477 ((IntConstant) right).Value);
479 res = unchecked (((IntConstant) left).Value -
480 ((IntConstant) right).Value);
482 return new IntConstant (res);
484 throw new Exception ( "Unexepected input: " + left);
486 } catch (OverflowException){
487 Error_CompileTimeOverflow (loc);
491 case Binary.Operator.Multiply:
492 DoConstantNumericPromotions (oper, ref left, ref right, loc);
493 if (left == null || right == null)
497 if (left is DoubleConstant){
500 if (ec.ConstantCheckState)
501 res = checked (((DoubleConstant) left).Value *
502 ((DoubleConstant) right).Value);
504 res = unchecked (((DoubleConstant) left).Value *
505 ((DoubleConstant) right).Value);
507 return new DoubleConstant (res);
508 } else if (left is FloatConstant){
511 if (ec.ConstantCheckState)
512 res = checked (((FloatConstant) left).Value *
513 ((FloatConstant) right).Value);
515 res = unchecked (((FloatConstant) left).Value *
516 ((FloatConstant) right).Value);
518 return new FloatConstant (res);
519 } else if (left is ULongConstant){
522 if (ec.ConstantCheckState)
523 res = checked (((ULongConstant) left).Value *
524 ((ULongConstant) right).Value);
526 res = unchecked (((ULongConstant) left).Value *
527 ((ULongConstant) right).Value);
529 return new ULongConstant (res);
530 } else if (left is LongConstant){
533 if (ec.ConstantCheckState)
534 res = checked (((LongConstant) left).Value *
535 ((LongConstant) right).Value);
537 res = unchecked (((LongConstant) left).Value *
538 ((LongConstant) right).Value);
540 return new LongConstant (res);
541 } else if (left is UIntConstant){
544 if (ec.ConstantCheckState)
545 res = checked (((UIntConstant) left).Value *
546 ((UIntConstant) right).Value);
548 res = unchecked (((UIntConstant) left).Value *
549 ((UIntConstant) right).Value);
551 return new UIntConstant (res);
552 } else if (left is IntConstant){
555 if (ec.ConstantCheckState)
556 res = checked (((IntConstant) left).Value *
557 ((IntConstant) right).Value);
559 res = unchecked (((IntConstant) left).Value *
560 ((IntConstant) right).Value);
562 return new IntConstant (res);
564 throw new Exception ( "Unexepected input: " + left);
566 } catch (OverflowException){
567 Error_CompileTimeOverflow (loc);
571 case Binary.Operator.Division:
572 DoConstantNumericPromotions (oper, ref left, ref right, loc);
573 if (left == null || right == null)
577 if (left is DoubleConstant){
580 if (ec.ConstantCheckState)
581 res = checked (((DoubleConstant) left).Value /
582 ((DoubleConstant) right).Value);
584 res = unchecked (((DoubleConstant) left).Value /
585 ((DoubleConstant) right).Value);
587 return new DoubleConstant (res);
588 } else if (left is FloatConstant){
591 if (ec.ConstantCheckState)
592 res = checked (((FloatConstant) left).Value /
593 ((FloatConstant) right).Value);
595 res = unchecked (((FloatConstant) left).Value /
596 ((FloatConstant) right).Value);
598 return new FloatConstant (res);
599 } else if (left is ULongConstant){
602 if (ec.ConstantCheckState)
603 res = checked (((ULongConstant) left).Value /
604 ((ULongConstant) right).Value);
606 res = unchecked (((ULongConstant) left).Value /
607 ((ULongConstant) right).Value);
609 return new ULongConstant (res);
610 } else if (left is LongConstant){
613 if (ec.ConstantCheckState)
614 res = checked (((LongConstant) left).Value /
615 ((LongConstant) right).Value);
617 res = unchecked (((LongConstant) left).Value /
618 ((LongConstant) right).Value);
620 return new LongConstant (res);
621 } else if (left is UIntConstant){
624 if (ec.ConstantCheckState)
625 res = checked (((UIntConstant) left).Value /
626 ((UIntConstant) right).Value);
628 res = unchecked (((UIntConstant) left).Value /
629 ((UIntConstant) right).Value);
631 return new UIntConstant (res);
632 } else if (left is IntConstant){
635 if (ec.ConstantCheckState)
636 res = checked (((IntConstant) left).Value /
637 ((IntConstant) right).Value);
639 res = unchecked (((IntConstant) left).Value /
640 ((IntConstant) right).Value);
642 return new IntConstant (res);
644 throw new Exception ( "Unexepected input: " + left);
646 } catch (OverflowException){
647 Error_CompileTimeOverflow (loc);
649 } catch (DivideByZeroException) {
650 Report.Error (020, loc, "Division by constant zero");
655 case Binary.Operator.Modulus:
656 DoConstantNumericPromotions (oper, ref left, ref right, loc);
657 if (left == null || right == null)
661 if (left is DoubleConstant){
664 if (ec.ConstantCheckState)
665 res = checked (((DoubleConstant) left).Value %
666 ((DoubleConstant) right).Value);
668 res = unchecked (((DoubleConstant) left).Value %
669 ((DoubleConstant) right).Value);
671 return new DoubleConstant (res);
672 } else if (left is FloatConstant){
675 if (ec.ConstantCheckState)
676 res = checked (((FloatConstant) left).Value %
677 ((FloatConstant) right).Value);
679 res = unchecked (((FloatConstant) left).Value %
680 ((FloatConstant) right).Value);
682 return new FloatConstant (res);
683 } else if (left is ULongConstant){
686 if (ec.ConstantCheckState)
687 res = checked (((ULongConstant) left).Value %
688 ((ULongConstant) right).Value);
690 res = unchecked (((ULongConstant) left).Value %
691 ((ULongConstant) right).Value);
693 return new ULongConstant (res);
694 } else if (left is LongConstant){
697 if (ec.ConstantCheckState)
698 res = checked (((LongConstant) left).Value %
699 ((LongConstant) right).Value);
701 res = unchecked (((LongConstant) left).Value %
702 ((LongConstant) right).Value);
704 return new LongConstant (res);
705 } else if (left is UIntConstant){
708 if (ec.ConstantCheckState)
709 res = checked (((UIntConstant) left).Value %
710 ((UIntConstant) right).Value);
712 res = unchecked (((UIntConstant) left).Value %
713 ((UIntConstant) right).Value);
715 return new UIntConstant (res);
716 } else if (left is IntConstant){
719 if (ec.ConstantCheckState)
720 res = checked (((IntConstant) left).Value %
721 ((IntConstant) right).Value);
723 res = unchecked (((IntConstant) left).Value %
724 ((IntConstant) right).Value);
726 return new IntConstant (res);
728 throw new Exception ( "Unexepected input: " + left);
730 } catch (OverflowException){
731 Error_CompileTimeOverflow (loc);
736 // There is no overflow checking on left shift
738 case Binary.Operator.LeftShift:
739 IntConstant ic = right.ToInt (loc);
741 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
744 int lshift_val = ic.Value;
747 if ((lic = left.ConvertToInt ()) != null)
748 return new IntConstant (lic.Value << lshift_val);
751 if ((luic = left.ConvertToUInt ()) != null)
752 return new UIntConstant (luic.Value << lshift_val);
755 if ((llc = left.ConvertToLong ()) != null)
756 return new LongConstant (llc.Value << lshift_val);
759 if ((lulc = left.ConvertToULong ()) != null)
760 return new ULongConstant (lulc.Value << lshift_val);
762 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
766 // There is no overflow checking on right shift
768 case Binary.Operator.RightShift:
769 IntConstant sic = right.ToInt (loc);
771 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
774 int rshift_val = sic.Value;
777 if ((ric = left.ConvertToInt ()) != null)
778 return new IntConstant (ric.Value >> rshift_val);
781 if ((ruic = left.ConvertToUInt ()) != null)
782 return new UIntConstant (ruic.Value >> rshift_val);
785 if ((rlc = left.ConvertToLong ()) != null)
786 return new LongConstant (rlc.Value >> rshift_val);
789 if ((rulc = left.ConvertToULong ()) != null)
790 return new ULongConstant (rulc.Value >> rshift_val);
792 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
795 case Binary.Operator.LogicalAnd:
796 if (left is BoolConstant && right is BoolConstant){
797 return new BoolConstant (
798 ((BoolConstant) left).Value &&
799 ((BoolConstant) right).Value);
803 case Binary.Operator.LogicalOr:
804 if (left is BoolConstant && right is BoolConstant){
805 return new BoolConstant (
806 ((BoolConstant) left).Value ||
807 ((BoolConstant) right).Value);
811 case Binary.Operator.Equality:
812 if (left is BoolConstant && right is BoolConstant){
813 return new BoolConstant (
814 ((BoolConstant) left).Value ==
815 ((BoolConstant) right).Value);
818 if (left is StringConstant && right is StringConstant){
819 return new BoolConstant (
820 ((StringConstant) left).Value ==
821 ((StringConstant) right).Value);
825 DoConstantNumericPromotions (oper, ref left, ref right, loc);
826 if (left == null || right == null)
830 if (left is DoubleConstant)
831 bool_res = ((DoubleConstant) left).Value ==
832 ((DoubleConstant) right).Value;
833 else if (left is FloatConstant)
834 bool_res = ((FloatConstant) left).Value ==
835 ((FloatConstant) right).Value;
836 else if (left is ULongConstant)
837 bool_res = ((ULongConstant) left).Value ==
838 ((ULongConstant) right).Value;
839 else if (left is LongConstant)
840 bool_res = ((LongConstant) left).Value ==
841 ((LongConstant) right).Value;
842 else if (left is UIntConstant)
843 bool_res = ((UIntConstant) left).Value ==
844 ((UIntConstant) right).Value;
845 else if (left is IntConstant)
846 bool_res = ((IntConstant) left).Value ==
847 ((IntConstant) right).Value;
851 return new BoolConstant (bool_res);
853 case Binary.Operator.Inequality:
854 if (left is BoolConstant && right is BoolConstant){
855 return new BoolConstant (
856 ((BoolConstant) left).Value !=
857 ((BoolConstant) right).Value);
859 if (left is StringConstant && right is StringConstant){
860 return new BoolConstant (
861 ((StringConstant) left).Value !=
862 ((StringConstant) right).Value);
865 DoConstantNumericPromotions (oper, ref left, ref right, loc);
866 if (left == null || right == null)
870 if (left is DoubleConstant)
871 bool_res = ((DoubleConstant) left).Value !=
872 ((DoubleConstant) right).Value;
873 else if (left is FloatConstant)
874 bool_res = ((FloatConstant) left).Value !=
875 ((FloatConstant) right).Value;
876 else if (left is ULongConstant)
877 bool_res = ((ULongConstant) left).Value !=
878 ((ULongConstant) right).Value;
879 else if (left is LongConstant)
880 bool_res = ((LongConstant) left).Value !=
881 ((LongConstant) right).Value;
882 else if (left is UIntConstant)
883 bool_res = ((UIntConstant) left).Value !=
884 ((UIntConstant) right).Value;
885 else if (left is IntConstant)
886 bool_res = ((IntConstant) left).Value !=
887 ((IntConstant) right).Value;
891 return new BoolConstant (bool_res);
893 case Binary.Operator.LessThan:
894 DoConstantNumericPromotions (oper, ref left, ref right, loc);
895 if (left == null || right == null)
899 if (left is DoubleConstant)
900 bool_res = ((DoubleConstant) left).Value <
901 ((DoubleConstant) right).Value;
902 else if (left is FloatConstant)
903 bool_res = ((FloatConstant) left).Value <
904 ((FloatConstant) right).Value;
905 else if (left is ULongConstant)
906 bool_res = ((ULongConstant) left).Value <
907 ((ULongConstant) right).Value;
908 else if (left is LongConstant)
909 bool_res = ((LongConstant) left).Value <
910 ((LongConstant) right).Value;
911 else if (left is UIntConstant)
912 bool_res = ((UIntConstant) left).Value <
913 ((UIntConstant) right).Value;
914 else if (left is IntConstant)
915 bool_res = ((IntConstant) left).Value <
916 ((IntConstant) right).Value;
920 return new BoolConstant (bool_res);
922 case Binary.Operator.GreaterThan:
923 DoConstantNumericPromotions (oper, ref left, ref right, loc);
924 if (left == null || right == null)
928 if (left is DoubleConstant)
929 bool_res = ((DoubleConstant) left).Value >
930 ((DoubleConstant) right).Value;
931 else if (left is FloatConstant)
932 bool_res = ((FloatConstant) left).Value >
933 ((FloatConstant) right).Value;
934 else if (left is ULongConstant)
935 bool_res = ((ULongConstant) left).Value >
936 ((ULongConstant) right).Value;
937 else if (left is LongConstant)
938 bool_res = ((LongConstant) left).Value >
939 ((LongConstant) right).Value;
940 else if (left is UIntConstant)
941 bool_res = ((UIntConstant) left).Value >
942 ((UIntConstant) right).Value;
943 else if (left is IntConstant)
944 bool_res = ((IntConstant) left).Value >
945 ((IntConstant) right).Value;
949 return new BoolConstant (bool_res);
951 case Binary.Operator.GreaterThanOrEqual:
952 DoConstantNumericPromotions (oper, ref left, ref right, loc);
953 if (left == null || right == null)
957 if (left is DoubleConstant)
958 bool_res = ((DoubleConstant) left).Value >=
959 ((DoubleConstant) right).Value;
960 else if (left is FloatConstant)
961 bool_res = ((FloatConstant) left).Value >=
962 ((FloatConstant) right).Value;
963 else if (left is ULongConstant)
964 bool_res = ((ULongConstant) left).Value >=
965 ((ULongConstant) right).Value;
966 else if (left is LongConstant)
967 bool_res = ((LongConstant) left).Value >=
968 ((LongConstant) right).Value;
969 else if (left is UIntConstant)
970 bool_res = ((UIntConstant) left).Value >=
971 ((UIntConstant) right).Value;
972 else if (left is IntConstant)
973 bool_res = ((IntConstant) left).Value >=
974 ((IntConstant) right).Value;
978 return new BoolConstant (bool_res);
980 case Binary.Operator.LessThanOrEqual:
981 DoConstantNumericPromotions (oper, ref left, ref right, loc);
982 if (left == null || right == null)
986 if (left is DoubleConstant)
987 bool_res = ((DoubleConstant) left).Value <=
988 ((DoubleConstant) right).Value;
989 else if (left is FloatConstant)
990 bool_res = ((FloatConstant) left).Value <=
991 ((FloatConstant) right).Value;
992 else if (left is ULongConstant)
993 bool_res = ((ULongConstant) left).Value <=
994 ((ULongConstant) right).Value;
995 else if (left is LongConstant)
996 bool_res = ((LongConstant) left).Value <=
997 ((LongConstant) right).Value;
998 else if (left is UIntConstant)
999 bool_res = ((UIntConstant) left).Value <=
1000 ((UIntConstant) right).Value;
1001 else if (left is IntConstant)
1002 bool_res = ((IntConstant) left).Value <=
1003 ((IntConstant) right).Value;
1007 return new BoolConstant (bool_res);