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, 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);
121 // Force conversions to int32
123 if (!(left is IntConstant))
124 left = left.ToInt (loc);
125 if (!(right is IntConstant))
126 right = right.ToInt (loc);
131 static void Error_CompileTimeOverflow (Location loc)
133 Report.Error (220, loc, "The operation overflows at compile time in checked mode");
137 /// Constant expression folder for binary operations.
139 /// Returns null if the expression can not be folded.
141 static public Expression BinaryFold (EmitContext ec, Binary.Operator oper,
142 Constant left, Constant right, Location loc)
145 Type rt = right.Type;
146 Type result_type = null;
150 // Enumerator folding
152 if (rt == lt && left is EnumConstant)
156 // During an enum evaluation, we need to unwrap enumerations
158 if (ec.InEnumContext){
159 if (left is EnumConstant)
160 left = ((EnumConstant) left).Child;
162 if (right is EnumConstant)
163 right = ((EnumConstant) right).Child;
167 case Binary.Operator.BitwiseOr:
168 DoConstantNumericPromotions (oper, ref left, ref right, loc);
169 if (left == null || right == null)
172 if (left is IntConstant){
174 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
176 v = new IntConstant (res);
177 if (result_type == null)
180 return new EnumConstant (v, result_type);
181 } else if (left is UIntConstant){
183 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
185 v = new UIntConstant (res);
186 if (result_type == null)
189 return new EnumConstant (v, result_type);
190 } else if (left is LongConstant){
192 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
194 v = new LongConstant (res);
195 if (result_type == null)
198 return new EnumConstant (v, result_type);
199 } else if (left is ULongConstant){
201 ulong res = ((ULongConstant)left).Value |
202 ((ULongConstant)right).Value;
204 v = new ULongConstant (res);
205 if (result_type == null)
208 return new EnumConstant (v, result_type);
212 case Binary.Operator.BitwiseAnd:
213 DoConstantNumericPromotions (oper, ref left, ref right, loc);
214 if (left == null || right == null)
217 if (left is IntConstant){
219 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
221 v = new IntConstant (res);
222 if (result_type == null)
225 return new EnumConstant (v, result_type);
226 } else if (left is UIntConstant){
228 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
230 v = new UIntConstant (res);
231 if (result_type == null)
234 return new EnumConstant (v, result_type);
235 } else if (left is LongConstant){
237 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
239 v = new LongConstant (res);
240 if (result_type == null)
243 return new EnumConstant (v, result_type);
244 } else if (left is ULongConstant){
246 ulong res = ((ULongConstant)left).Value &
247 ((ULongConstant)right).Value;
249 v = new ULongConstant (res);
250 if (result_type == null)
253 return new EnumConstant (v, result_type);
257 case Binary.Operator.ExclusiveOr:
258 DoConstantNumericPromotions (oper, ref left, ref right, loc);
259 if (left == null || right == null)
262 if (left is IntConstant){
264 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
266 v = new IntConstant (res);
267 if (result_type == null)
270 return new EnumConstant (v, result_type);
271 } else if (left is UIntConstant){
273 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
275 v = new UIntConstant (res);
276 if (result_type == null)
279 return new EnumConstant (v, result_type);
280 } else if (left is LongConstant){
282 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
284 v = new LongConstant (res);
285 if (result_type == null)
288 return new EnumConstant (v, result_type);
289 } else if (left is ULongConstant){
291 ulong res = ((ULongConstant)left).Value ^
292 ((ULongConstant)right).Value;
294 v = new ULongConstant (res);
295 if (result_type == null)
298 return new EnumConstant (v, result_type);
302 case Binary.Operator.Addition:
304 bool left_is_string = left is StringConstant;
305 bool right_is_string = right is StringConstant;
308 // If both sides are strings, then concatenate, if
309 // one is a string, and the other is not, then defer
310 // to runtime concatenation
312 if (left_is_string || right_is_string){
313 if (left_is_string && right_is_string)
314 return new StringConstant (
315 ((StringConstant) left).Value +
316 ((StringConstant) right).Value);
322 // handle "E operator + (E x, U y)"
323 // handle "E operator + (Y y, E x)"
325 // note that E operator + (E x, E y) is invalid
328 if (left is EnumConstant){
329 if (right is EnumConstant){
332 if (((EnumConstant) left).Child.Type != right.Type)
336 } else if (right is EnumConstant){
337 if (((EnumConstant) right).Child.Type != left.Type)
339 wrap_as = right.Type;
343 DoConstantNumericPromotions (oper, ref left, ref right, loc);
344 if (left == null || right == null)
348 if (left is DoubleConstant){
351 if (ec.ConstantCheckState)
352 res = checked (((DoubleConstant) left).Value +
353 ((DoubleConstant) right).Value);
355 res = unchecked (((DoubleConstant) left).Value +
356 ((DoubleConstant) right).Value);
358 result = new DoubleConstant (res);
359 } else if (left is FloatConstant){
362 if (ec.ConstantCheckState)
363 res = checked (((FloatConstant) left).Value +
364 ((FloatConstant) right).Value);
366 res = unchecked (((FloatConstant) left).Value +
367 ((FloatConstant) right).Value);
369 result = new FloatConstant (res);
370 } else if (left is ULongConstant){
373 if (ec.ConstantCheckState)
374 res = checked (((ULongConstant) left).Value +
375 ((ULongConstant) right).Value);
377 res = unchecked (((ULongConstant) left).Value +
378 ((ULongConstant) right).Value);
380 result = new ULongConstant (res);
381 } else if (left is LongConstant){
384 if (ec.ConstantCheckState)
385 res = checked (((LongConstant) left).Value +
386 ((LongConstant) right).Value);
388 res = unchecked (((LongConstant) left).Value +
389 ((LongConstant) right).Value);
391 result = new LongConstant (res);
392 } else if (left is UIntConstant){
395 if (ec.ConstantCheckState)
396 res = checked (((UIntConstant) left).Value +
397 ((UIntConstant) right).Value);
399 res = unchecked (((UIntConstant) left).Value +
400 ((UIntConstant) right).Value);
402 result = new UIntConstant (res);
403 } else if (left is IntConstant){
406 if (ec.ConstantCheckState)
407 res = checked (((IntConstant) left).Value +
408 ((IntConstant) right).Value);
410 res = unchecked (((IntConstant) left).Value +
411 ((IntConstant) right).Value);
413 result = new IntConstant (res);
415 throw new Exception ( "Unexepected input: " + left);
417 } catch (OverflowException){
418 Error_CompileTimeOverflow (loc);
422 return new EnumConstant (result, wrap_as);
426 case Binary.Operator.Subtraction:
427 DoConstantNumericPromotions (oper, ref left, ref right, loc);
428 if (left == null || right == null)
432 if (left is DoubleConstant){
435 if (ec.ConstantCheckState)
436 res = checked (((DoubleConstant) left).Value -
437 ((DoubleConstant) right).Value);
439 res = unchecked (((DoubleConstant) left).Value -
440 ((DoubleConstant) right).Value);
442 return new DoubleConstant (res);
443 } else if (left is FloatConstant){
446 if (ec.ConstantCheckState)
447 res = checked (((FloatConstant) left).Value -
448 ((FloatConstant) right).Value);
450 res = unchecked (((FloatConstant) left).Value -
451 ((FloatConstant) right).Value);
453 return new FloatConstant (res);
454 } else if (left is ULongConstant){
457 if (ec.ConstantCheckState)
458 res = checked (((ULongConstant) left).Value -
459 ((ULongConstant) right).Value);
461 res = unchecked (((ULongConstant) left).Value -
462 ((ULongConstant) right).Value);
464 return new ULongConstant (res);
465 } else if (left is LongConstant){
468 if (ec.ConstantCheckState)
469 res = checked (((LongConstant) left).Value -
470 ((LongConstant) right).Value);
472 res = unchecked (((LongConstant) left).Value -
473 ((LongConstant) right).Value);
475 return new LongConstant (res);
476 } else if (left is UIntConstant){
479 if (ec.ConstantCheckState)
480 res = checked (((UIntConstant) left).Value -
481 ((UIntConstant) right).Value);
483 res = unchecked (((UIntConstant) left).Value -
484 ((UIntConstant) right).Value);
486 return new UIntConstant (res);
487 } else if (left is IntConstant){
490 if (ec.ConstantCheckState)
491 res = checked (((IntConstant) left).Value -
492 ((IntConstant) right).Value);
494 res = unchecked (((IntConstant) left).Value -
495 ((IntConstant) right).Value);
497 return new IntConstant (res);
499 throw new Exception ( "Unexepected input: " + left);
501 } catch (OverflowException){
502 Error_CompileTimeOverflow (loc);
506 case Binary.Operator.Multiply:
507 DoConstantNumericPromotions (oper, ref left, ref right, loc);
508 if (left == null || right == null)
512 if (left is DoubleConstant){
515 if (ec.ConstantCheckState)
516 res = checked (((DoubleConstant) left).Value *
517 ((DoubleConstant) right).Value);
519 res = unchecked (((DoubleConstant) left).Value *
520 ((DoubleConstant) right).Value);
522 return new DoubleConstant (res);
523 } else if (left is FloatConstant){
526 if (ec.ConstantCheckState)
527 res = checked (((FloatConstant) left).Value *
528 ((FloatConstant) right).Value);
530 res = unchecked (((FloatConstant) left).Value *
531 ((FloatConstant) right).Value);
533 return new FloatConstant (res);
534 } else if (left is ULongConstant){
537 if (ec.ConstantCheckState)
538 res = checked (((ULongConstant) left).Value *
539 ((ULongConstant) right).Value);
541 res = unchecked (((ULongConstant) left).Value *
542 ((ULongConstant) right).Value);
544 return new ULongConstant (res);
545 } else if (left is LongConstant){
548 if (ec.ConstantCheckState)
549 res = checked (((LongConstant) left).Value *
550 ((LongConstant) right).Value);
552 res = unchecked (((LongConstant) left).Value *
553 ((LongConstant) right).Value);
555 return new LongConstant (res);
556 } else if (left is UIntConstant){
559 if (ec.ConstantCheckState)
560 res = checked (((UIntConstant) left).Value *
561 ((UIntConstant) right).Value);
563 res = unchecked (((UIntConstant) left).Value *
564 ((UIntConstant) right).Value);
566 return new UIntConstant (res);
567 } else if (left is IntConstant){
570 if (ec.ConstantCheckState)
571 res = checked (((IntConstant) left).Value *
572 ((IntConstant) right).Value);
574 res = unchecked (((IntConstant) left).Value *
575 ((IntConstant) right).Value);
577 return new IntConstant (res);
579 throw new Exception ( "Unexepected input: " + left);
581 } catch (OverflowException){
582 Error_CompileTimeOverflow (loc);
586 case Binary.Operator.Division:
587 DoConstantNumericPromotions (oper, ref left, ref right, loc);
588 if (left == null || right == null)
592 if (left is DoubleConstant){
595 if (ec.ConstantCheckState)
596 res = checked (((DoubleConstant) left).Value /
597 ((DoubleConstant) right).Value);
599 res = unchecked (((DoubleConstant) left).Value /
600 ((DoubleConstant) right).Value);
602 return new DoubleConstant (res);
603 } else if (left is FloatConstant){
606 if (ec.ConstantCheckState)
607 res = checked (((FloatConstant) left).Value /
608 ((FloatConstant) right).Value);
610 res = unchecked (((FloatConstant) left).Value /
611 ((FloatConstant) right).Value);
613 return new FloatConstant (res);
614 } else if (left is ULongConstant){
617 if (ec.ConstantCheckState)
618 res = checked (((ULongConstant) left).Value /
619 ((ULongConstant) right).Value);
621 res = unchecked (((ULongConstant) left).Value /
622 ((ULongConstant) right).Value);
624 return new ULongConstant (res);
625 } else if (left is LongConstant){
628 if (ec.ConstantCheckState)
629 res = checked (((LongConstant) left).Value /
630 ((LongConstant) right).Value);
632 res = unchecked (((LongConstant) left).Value /
633 ((LongConstant) right).Value);
635 return new LongConstant (res);
636 } else if (left is UIntConstant){
639 if (ec.ConstantCheckState)
640 res = checked (((UIntConstant) left).Value /
641 ((UIntConstant) right).Value);
643 res = unchecked (((UIntConstant) left).Value /
644 ((UIntConstant) right).Value);
646 return new UIntConstant (res);
647 } else if (left is IntConstant){
650 if (ec.ConstantCheckState)
651 res = checked (((IntConstant) left).Value /
652 ((IntConstant) right).Value);
654 res = unchecked (((IntConstant) left).Value /
655 ((IntConstant) right).Value);
657 return new IntConstant (res);
659 throw new Exception ( "Unexepected input: " + left);
661 } catch (OverflowException){
662 Error_CompileTimeOverflow (loc);
664 } catch (DivideByZeroException) {
665 Report.Error (020, loc, "Division by constant zero");
670 case Binary.Operator.Modulus:
671 DoConstantNumericPromotions (oper, ref left, ref right, loc);
672 if (left == null || right == null)
676 if (left is DoubleConstant){
679 if (ec.ConstantCheckState)
680 res = checked (((DoubleConstant) left).Value %
681 ((DoubleConstant) right).Value);
683 res = unchecked (((DoubleConstant) left).Value %
684 ((DoubleConstant) right).Value);
686 return new DoubleConstant (res);
687 } else if (left is FloatConstant){
690 if (ec.ConstantCheckState)
691 res = checked (((FloatConstant) left).Value %
692 ((FloatConstant) right).Value);
694 res = unchecked (((FloatConstant) left).Value %
695 ((FloatConstant) right).Value);
697 return new FloatConstant (res);
698 } else if (left is ULongConstant){
701 if (ec.ConstantCheckState)
702 res = checked (((ULongConstant) left).Value %
703 ((ULongConstant) right).Value);
705 res = unchecked (((ULongConstant) left).Value %
706 ((ULongConstant) right).Value);
708 return new ULongConstant (res);
709 } else if (left is LongConstant){
712 if (ec.ConstantCheckState)
713 res = checked (((LongConstant) left).Value %
714 ((LongConstant) right).Value);
716 res = unchecked (((LongConstant) left).Value %
717 ((LongConstant) right).Value);
719 return new LongConstant (res);
720 } else if (left is UIntConstant){
723 if (ec.ConstantCheckState)
724 res = checked (((UIntConstant) left).Value %
725 ((UIntConstant) right).Value);
727 res = unchecked (((UIntConstant) left).Value %
728 ((UIntConstant) right).Value);
730 return new UIntConstant (res);
731 } else if (left is IntConstant){
734 if (ec.ConstantCheckState)
735 res = checked (((IntConstant) left).Value %
736 ((IntConstant) right).Value);
738 res = unchecked (((IntConstant) left).Value %
739 ((IntConstant) right).Value);
741 return new IntConstant (res);
743 throw new Exception ( "Unexepected input: " + left);
745 } catch (OverflowException){
746 Error_CompileTimeOverflow (loc);
751 // There is no overflow checking on left shift
753 case Binary.Operator.LeftShift:
754 IntConstant ic = right.ToInt (loc);
756 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
759 int lshift_val = ic.Value;
762 if ((lic = left.ConvertToInt ()) != null)
763 return new IntConstant (lic.Value << lshift_val);
766 if ((luic = left.ConvertToUInt ()) != null)
767 return new UIntConstant (luic.Value << lshift_val);
770 if ((llc = left.ConvertToLong ()) != null)
771 return new LongConstant (llc.Value << lshift_val);
774 if ((lulc = left.ConvertToULong ()) != null)
775 return new ULongConstant (lulc.Value << lshift_val);
777 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
781 // There is no overflow checking on right shift
783 case Binary.Operator.RightShift:
784 IntConstant sic = right.ToInt (loc);
786 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
789 int rshift_val = sic.Value;
792 if ((ric = left.ConvertToInt ()) != null)
793 return new IntConstant (ric.Value >> rshift_val);
796 if ((ruic = left.ConvertToUInt ()) != null)
797 return new UIntConstant (ruic.Value >> rshift_val);
800 if ((rlc = left.ConvertToLong ()) != null)
801 return new LongConstant (rlc.Value >> rshift_val);
804 if ((rulc = left.ConvertToULong ()) != null)
805 return new ULongConstant (rulc.Value >> rshift_val);
807 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
810 case Binary.Operator.LogicalAnd:
811 if (left is BoolConstant && right is BoolConstant){
812 return new BoolConstant (
813 ((BoolConstant) left).Value &&
814 ((BoolConstant) right).Value);
818 case Binary.Operator.LogicalOr:
819 if (left is BoolConstant && right is BoolConstant){
820 return new BoolConstant (
821 ((BoolConstant) left).Value ||
822 ((BoolConstant) right).Value);
826 case Binary.Operator.Equality:
827 if (left is BoolConstant && right is BoolConstant){
828 return new BoolConstant (
829 ((BoolConstant) left).Value ==
830 ((BoolConstant) right).Value);
833 if (left is StringConstant && right is StringConstant){
834 return new BoolConstant (
835 ((StringConstant) left).Value ==
836 ((StringConstant) right).Value);
840 DoConstantNumericPromotions (oper, ref left, ref right, loc);
841 if (left == null || right == null)
845 if (left is DoubleConstant)
846 bool_res = ((DoubleConstant) left).Value ==
847 ((DoubleConstant) right).Value;
848 else if (left is FloatConstant)
849 bool_res = ((FloatConstant) left).Value ==
850 ((FloatConstant) right).Value;
851 else if (left is ULongConstant)
852 bool_res = ((ULongConstant) left).Value ==
853 ((ULongConstant) right).Value;
854 else if (left is LongConstant)
855 bool_res = ((LongConstant) left).Value ==
856 ((LongConstant) right).Value;
857 else if (left is UIntConstant)
858 bool_res = ((UIntConstant) left).Value ==
859 ((UIntConstant) right).Value;
860 else if (left is IntConstant)
861 bool_res = ((IntConstant) left).Value ==
862 ((IntConstant) right).Value;
866 return new BoolConstant (bool_res);
868 case Binary.Operator.Inequality:
869 if (left is BoolConstant && right is BoolConstant){
870 return new BoolConstant (
871 ((BoolConstant) left).Value !=
872 ((BoolConstant) right).Value);
874 if (left is StringConstant && right is StringConstant){
875 return new BoolConstant (
876 ((StringConstant) left).Value !=
877 ((StringConstant) right).Value);
880 DoConstantNumericPromotions (oper, ref left, ref right, loc);
881 if (left == null || right == null)
885 if (left is DoubleConstant)
886 bool_res = ((DoubleConstant) left).Value !=
887 ((DoubleConstant) right).Value;
888 else if (left is FloatConstant)
889 bool_res = ((FloatConstant) left).Value !=
890 ((FloatConstant) right).Value;
891 else if (left is ULongConstant)
892 bool_res = ((ULongConstant) left).Value !=
893 ((ULongConstant) right).Value;
894 else if (left is LongConstant)
895 bool_res = ((LongConstant) left).Value !=
896 ((LongConstant) right).Value;
897 else if (left is UIntConstant)
898 bool_res = ((UIntConstant) left).Value !=
899 ((UIntConstant) right).Value;
900 else if (left is IntConstant)
901 bool_res = ((IntConstant) left).Value !=
902 ((IntConstant) right).Value;
906 return new BoolConstant (bool_res);
908 case Binary.Operator.LessThan:
909 DoConstantNumericPromotions (oper, ref left, ref right, loc);
910 if (left == null || right == null)
914 if (left is DoubleConstant)
915 bool_res = ((DoubleConstant) left).Value <
916 ((DoubleConstant) right).Value;
917 else if (left is FloatConstant)
918 bool_res = ((FloatConstant) left).Value <
919 ((FloatConstant) right).Value;
920 else if (left is ULongConstant)
921 bool_res = ((ULongConstant) left).Value <
922 ((ULongConstant) right).Value;
923 else if (left is LongConstant)
924 bool_res = ((LongConstant) left).Value <
925 ((LongConstant) right).Value;
926 else if (left is UIntConstant)
927 bool_res = ((UIntConstant) left).Value <
928 ((UIntConstant) right).Value;
929 else if (left is IntConstant)
930 bool_res = ((IntConstant) left).Value <
931 ((IntConstant) right).Value;
935 return new BoolConstant (bool_res);
937 case Binary.Operator.GreaterThan:
938 DoConstantNumericPromotions (oper, ref left, ref right, loc);
939 if (left == null || right == null)
943 if (left is DoubleConstant)
944 bool_res = ((DoubleConstant) left).Value >
945 ((DoubleConstant) right).Value;
946 else if (left is FloatConstant)
947 bool_res = ((FloatConstant) left).Value >
948 ((FloatConstant) right).Value;
949 else if (left is ULongConstant)
950 bool_res = ((ULongConstant) left).Value >
951 ((ULongConstant) right).Value;
952 else if (left is LongConstant)
953 bool_res = ((LongConstant) left).Value >
954 ((LongConstant) right).Value;
955 else if (left is UIntConstant)
956 bool_res = ((UIntConstant) left).Value >
957 ((UIntConstant) right).Value;
958 else if (left is IntConstant)
959 bool_res = ((IntConstant) left).Value >
960 ((IntConstant) right).Value;
964 return new BoolConstant (bool_res);
966 case Binary.Operator.GreaterThanOrEqual:
967 DoConstantNumericPromotions (oper, ref left, ref right, loc);
968 if (left == null || right == null)
972 if (left is DoubleConstant)
973 bool_res = ((DoubleConstant) left).Value >=
974 ((DoubleConstant) right).Value;
975 else if (left is FloatConstant)
976 bool_res = ((FloatConstant) left).Value >=
977 ((FloatConstant) right).Value;
978 else if (left is ULongConstant)
979 bool_res = ((ULongConstant) left).Value >=
980 ((ULongConstant) right).Value;
981 else if (left is LongConstant)
982 bool_res = ((LongConstant) left).Value >=
983 ((LongConstant) right).Value;
984 else if (left is UIntConstant)
985 bool_res = ((UIntConstant) left).Value >=
986 ((UIntConstant) right).Value;
987 else if (left is IntConstant)
988 bool_res = ((IntConstant) left).Value >=
989 ((IntConstant) right).Value;
993 return new BoolConstant (bool_res);
995 case Binary.Operator.LessThanOrEqual:
996 DoConstantNumericPromotions (oper, ref left, ref right, loc);
997 if (left == null || right == null)
1001 if (left is DoubleConstant)
1002 bool_res = ((DoubleConstant) left).Value <=
1003 ((DoubleConstant) right).Value;
1004 else if (left is FloatConstant)
1005 bool_res = ((FloatConstant) left).Value <=
1006 ((FloatConstant) right).Value;
1007 else if (left is ULongConstant)
1008 bool_res = ((ULongConstant) left).Value <=
1009 ((ULongConstant) right).Value;
1010 else if (left is LongConstant)
1011 bool_res = ((LongConstant) left).Value <=
1012 ((LongConstant) right).Value;
1013 else if (left is UIntConstant)
1014 bool_res = ((UIntConstant) left).Value <=
1015 ((UIntConstant) right).Value;
1016 else if (left is IntConstant)
1017 bool_res = ((IntConstant) left).Value <=
1018 ((IntConstant) right).Value;
1022 return new BoolConstant (bool_res);