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 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 (DivideByZeroException){
806 Report.Error (020, loc, "Division by constant zero");
807 } catch (OverflowException){
808 Error_CompileTimeOverflow (loc);
813 // There is no overflow checking on left shift
815 case Binary.Operator.LeftShift:
816 IntConstant ic = right.ToInt (loc);
818 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
821 int lshift_val = ic.Value;
824 if ((lic = left.ConvertToInt ()) != null)
825 return new IntConstant (lic.Value << lshift_val);
828 if ((luic = left.ConvertToUInt ()) != null)
829 return new UIntConstant (luic.Value << lshift_val);
832 if ((llc = left.ConvertToLong ()) != null)
833 return new LongConstant (llc.Value << lshift_val);
836 if ((lulc = left.ConvertToULong ()) != null)
837 return new ULongConstant (lulc.Value << lshift_val);
839 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
843 // There is no overflow checking on right shift
845 case Binary.Operator.RightShift:
846 IntConstant sic = right.ToInt (loc);
848 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
851 int rshift_val = sic.Value;
854 if ((ric = left.ConvertToInt ()) != null)
855 return new IntConstant (ric.Value >> rshift_val);
858 if ((ruic = left.ConvertToUInt ()) != null)
859 return new UIntConstant (ruic.Value >> rshift_val);
862 if ((rlc = left.ConvertToLong ()) != null)
863 return new LongConstant (rlc.Value >> rshift_val);
866 if ((rulc = left.ConvertToULong ()) != null)
867 return new ULongConstant (rulc.Value >> rshift_val);
869 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
872 case Binary.Operator.LogicalAnd:
873 if (left is BoolConstant && right is BoolConstant){
874 return new BoolConstant (
875 ((BoolConstant) left).Value &&
876 ((BoolConstant) right).Value);
880 case Binary.Operator.LogicalOr:
881 if (left is BoolConstant && right is BoolConstant){
882 return new BoolConstant (
883 ((BoolConstant) left).Value ||
884 ((BoolConstant) right).Value);
888 case Binary.Operator.Equality:
889 if (left is BoolConstant && right is BoolConstant){
890 return new BoolConstant (
891 ((BoolConstant) left).Value ==
892 ((BoolConstant) right).Value);
895 if (left is StringConstant && right is StringConstant){
896 return new BoolConstant (
897 ((StringConstant) left).Value ==
898 ((StringConstant) right).Value);
902 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
903 if (left == null || right == null)
907 if (left is DoubleConstant)
908 bool_res = ((DoubleConstant) left).Value ==
909 ((DoubleConstant) right).Value;
910 else if (left is FloatConstant)
911 bool_res = ((FloatConstant) left).Value ==
912 ((FloatConstant) right).Value;
913 else if (left is ULongConstant)
914 bool_res = ((ULongConstant) left).Value ==
915 ((ULongConstant) right).Value;
916 else if (left is LongConstant)
917 bool_res = ((LongConstant) left).Value ==
918 ((LongConstant) right).Value;
919 else if (left is UIntConstant)
920 bool_res = ((UIntConstant) left).Value ==
921 ((UIntConstant) right).Value;
922 else if (left is IntConstant)
923 bool_res = ((IntConstant) left).Value ==
924 ((IntConstant) right).Value;
928 return new BoolConstant (bool_res);
930 case Binary.Operator.Inequality:
931 if (left is BoolConstant && right is BoolConstant){
932 return new BoolConstant (
933 ((BoolConstant) left).Value !=
934 ((BoolConstant) right).Value);
936 if (left is StringConstant && right is StringConstant){
937 return new BoolConstant (
938 ((StringConstant) left).Value !=
939 ((StringConstant) right).Value);
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.LessThan:
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.GreaterThan:
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.GreaterThanOrEqual:
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);
1057 case Binary.Operator.LessThanOrEqual:
1058 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1059 if (left == null || right == null)
1063 if (left is DoubleConstant)
1064 bool_res = ((DoubleConstant) left).Value <=
1065 ((DoubleConstant) right).Value;
1066 else if (left is FloatConstant)
1067 bool_res = ((FloatConstant) left).Value <=
1068 ((FloatConstant) right).Value;
1069 else if (left is ULongConstant)
1070 bool_res = ((ULongConstant) left).Value <=
1071 ((ULongConstant) right).Value;
1072 else if (left is LongConstant)
1073 bool_res = ((LongConstant) left).Value <=
1074 ((LongConstant) right).Value;
1075 else if (left is UIntConstant)
1076 bool_res = ((UIntConstant) left).Value <=
1077 ((UIntConstant) right).Value;
1078 else if (left is IntConstant)
1079 bool_res = ((IntConstant) left).Value <=
1080 ((IntConstant) right).Value;
1084 return new BoolConstant (bool_res);