2 // cfold.cs: Constant Folding
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2002 Ximian, Inc.
12 namespace Mono.MonoBASIC {
14 public class ConstantFold {
17 // Performs the numeric promotions on the left and right expresions
18 // and desposits the results on `lc' and `rc'.
20 // On success, the types of `lc' and `rc' on output will always match,
21 // and the pair will be one of:
30 static void DoConstantNumericPromotions (EmitContext ec, Binary.Operator oper,
31 ref Constant left, ref Constant right,
34 if (left is DoubleConstant || right is DoubleConstant || oper == Binary.Operator.Exponentiation){
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 (30542, loc, "Division by constant zero");
730 case Binary.Operator.Modulus:
731 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
732 if (left == null || right == null)
736 if (left is DoubleConstant){
739 if (ec.ConstantCheckState)
740 res = checked (((DoubleConstant) left).Value %
741 ((DoubleConstant) right).Value);
743 res = unchecked (((DoubleConstant) left).Value %
744 ((DoubleConstant) right).Value);
746 return new DoubleConstant (res);
747 } else if (left is FloatConstant){
750 if (ec.ConstantCheckState)
751 res = checked (((FloatConstant) left).Value %
752 ((FloatConstant) right).Value);
754 res = unchecked (((FloatConstant) left).Value %
755 ((FloatConstant) right).Value);
757 return new FloatConstant (res);
758 } else if (left is ULongConstant){
761 if (ec.ConstantCheckState)
762 res = checked (((ULongConstant) left).Value %
763 ((ULongConstant) right).Value);
765 res = unchecked (((ULongConstant) left).Value %
766 ((ULongConstant) right).Value);
768 return new ULongConstant (res);
769 } else if (left is LongConstant){
772 if (ec.ConstantCheckState)
773 res = checked (((LongConstant) left).Value %
774 ((LongConstant) right).Value);
776 res = unchecked (((LongConstant) left).Value %
777 ((LongConstant) right).Value);
779 return new LongConstant (res);
780 } else if (left is UIntConstant){
783 if (ec.ConstantCheckState)
784 res = checked (((UIntConstant) left).Value %
785 ((UIntConstant) right).Value);
787 res = unchecked (((UIntConstant) left).Value %
788 ((UIntConstant) right).Value);
790 return new UIntConstant (res);
791 } else if (left is IntConstant){
794 if (ec.ConstantCheckState)
795 res = checked (((IntConstant) left).Value %
796 ((IntConstant) right).Value);
798 res = unchecked (((IntConstant) left).Value %
799 ((IntConstant) right).Value);
801 return new IntConstant (res);
803 throw new Exception ( "Unexepected input: " + left);
805 } catch (OverflowException){
806 Error_CompileTimeOverflow (loc);
810 case Binary.Operator.Exponentiation:
811 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
812 if (left == null || right == null)
815 double powVal = System.Math.Pow(((DoubleConstant) left).Value,
816 ((DoubleConstant) right).Value);
818 return new DoubleConstant(powVal);
821 // There is no overflow checking on left shift
823 case Binary.Operator.LeftShift:
824 IntConstant ic = right.ToInt (loc);
826 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
829 int lshift_val = ic.Value;
832 if ((lic = left.ConvertToInt ()) != null)
833 return new IntConstant (lic.Value << lshift_val);
836 if ((luic = left.ConvertToUInt ()) != null)
837 return new UIntConstant (luic.Value << lshift_val);
840 if ((llc = left.ConvertToLong ()) != null)
841 return new LongConstant (llc.Value << lshift_val);
844 if ((lulc = left.ConvertToULong ()) != null)
845 return new ULongConstant (lulc.Value << lshift_val);
847 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
851 // There is no overflow checking on right shift
853 case Binary.Operator.RightShift:
854 IntConstant sic = right.ToInt (loc);
856 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
859 int rshift_val = sic.Value;
862 if ((ric = left.ConvertToInt ()) != null)
863 return new IntConstant (ric.Value >> rshift_val);
866 if ((ruic = left.ConvertToUInt ()) != null)
867 return new UIntConstant (ruic.Value >> rshift_val);
870 if ((rlc = left.ConvertToLong ()) != null)
871 return new LongConstant (rlc.Value >> rshift_val);
874 if ((rulc = left.ConvertToULong ()) != null)
875 return new ULongConstant (rulc.Value >> rshift_val);
877 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
880 case Binary.Operator.LogicalAnd:
881 if (left is BoolConstant && right is BoolConstant){
882 return new BoolConstant (
883 ((BoolConstant) left).Value &&
884 ((BoolConstant) right).Value);
888 case Binary.Operator.LogicalOr:
889 if (left is BoolConstant && right is BoolConstant){
890 return new BoolConstant (
891 ((BoolConstant) left).Value ||
892 ((BoolConstant) right).Value);
896 case Binary.Operator.Equality:
897 if (left is BoolConstant && right is BoolConstant){
898 return new BoolConstant (
899 ((BoolConstant) left).Value ==
900 ((BoolConstant) right).Value);
903 if (left is StringConstant && right is StringConstant){
904 return new BoolConstant (
905 ((StringConstant) left).Value ==
906 ((StringConstant) right).Value);
910 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
911 if (left == null || right == null)
915 if (left is DoubleConstant)
916 bool_res = ((DoubleConstant) left).Value ==
917 ((DoubleConstant) right).Value;
918 else if (left is FloatConstant)
919 bool_res = ((FloatConstant) left).Value ==
920 ((FloatConstant) right).Value;
921 else if (left is ULongConstant)
922 bool_res = ((ULongConstant) left).Value ==
923 ((ULongConstant) right).Value;
924 else if (left is LongConstant)
925 bool_res = ((LongConstant) left).Value ==
926 ((LongConstant) right).Value;
927 else if (left is UIntConstant)
928 bool_res = ((UIntConstant) left).Value ==
929 ((UIntConstant) right).Value;
930 else if (left is IntConstant)
931 bool_res = ((IntConstant) left).Value ==
932 ((IntConstant) right).Value;
936 return new BoolConstant (bool_res);
938 case Binary.Operator.Inequality:
939 if (left is BoolConstant && right is BoolConstant){
940 return new BoolConstant (
941 ((BoolConstant) left).Value !=
942 ((BoolConstant) right).Value);
944 if (left is StringConstant && right is StringConstant){
945 return new BoolConstant (
946 ((StringConstant) left).Value !=
947 ((StringConstant) right).Value);
950 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
951 if (left == null || right == null)
955 if (left is DoubleConstant)
956 bool_res = ((DoubleConstant) left).Value !=
957 ((DoubleConstant) right).Value;
958 else if (left is FloatConstant)
959 bool_res = ((FloatConstant) left).Value !=
960 ((FloatConstant) right).Value;
961 else if (left is ULongConstant)
962 bool_res = ((ULongConstant) left).Value !=
963 ((ULongConstant) right).Value;
964 else if (left is LongConstant)
965 bool_res = ((LongConstant) left).Value !=
966 ((LongConstant) right).Value;
967 else if (left is UIntConstant)
968 bool_res = ((UIntConstant) left).Value !=
969 ((UIntConstant) right).Value;
970 else if (left is IntConstant)
971 bool_res = ((IntConstant) left).Value !=
972 ((IntConstant) right).Value;
976 return new BoolConstant (bool_res);
978 case Binary.Operator.LessThan:
979 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
980 if (left == null || right == null)
984 if (left is DoubleConstant)
985 bool_res = ((DoubleConstant) left).Value <
986 ((DoubleConstant) right).Value;
987 else if (left is FloatConstant)
988 bool_res = ((FloatConstant) left).Value <
989 ((FloatConstant) right).Value;
990 else if (left is ULongConstant)
991 bool_res = ((ULongConstant) left).Value <
992 ((ULongConstant) right).Value;
993 else if (left is LongConstant)
994 bool_res = ((LongConstant) left).Value <
995 ((LongConstant) right).Value;
996 else if (left is UIntConstant)
997 bool_res = ((UIntConstant) left).Value <
998 ((UIntConstant) right).Value;
999 else if (left is IntConstant)
1000 bool_res = ((IntConstant) left).Value <
1001 ((IntConstant) right).Value;
1005 return new BoolConstant (bool_res);
1007 case Binary.Operator.GreaterThan:
1008 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1009 if (left == null || right == null)
1013 if (left is DoubleConstant)
1014 bool_res = ((DoubleConstant) left).Value >
1015 ((DoubleConstant) right).Value;
1016 else if (left is FloatConstant)
1017 bool_res = ((FloatConstant) left).Value >
1018 ((FloatConstant) right).Value;
1019 else if (left is ULongConstant)
1020 bool_res = ((ULongConstant) left).Value >
1021 ((ULongConstant) right).Value;
1022 else if (left is LongConstant)
1023 bool_res = ((LongConstant) left).Value >
1024 ((LongConstant) right).Value;
1025 else if (left is UIntConstant)
1026 bool_res = ((UIntConstant) left).Value >
1027 ((UIntConstant) right).Value;
1028 else if (left is IntConstant)
1029 bool_res = ((IntConstant) left).Value >
1030 ((IntConstant) right).Value;
1034 return new BoolConstant (bool_res);
1036 case Binary.Operator.GreaterThanOrEqual:
1037 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1038 if (left == null || right == null)
1042 if (left is DoubleConstant)
1043 bool_res = ((DoubleConstant) left).Value >=
1044 ((DoubleConstant) right).Value;
1045 else if (left is FloatConstant)
1046 bool_res = ((FloatConstant) left).Value >=
1047 ((FloatConstant) right).Value;
1048 else if (left is ULongConstant)
1049 bool_res = ((ULongConstant) left).Value >=
1050 ((ULongConstant) right).Value;
1051 else if (left is LongConstant)
1052 bool_res = ((LongConstant) left).Value >=
1053 ((LongConstant) right).Value;
1054 else if (left is UIntConstant)
1055 bool_res = ((UIntConstant) left).Value >=
1056 ((UIntConstant) right).Value;
1057 else if (left is IntConstant)
1058 bool_res = ((IntConstant) left).Value >=
1059 ((IntConstant) right).Value;
1063 return new BoolConstant (bool_res);
1065 case Binary.Operator.LessThanOrEqual:
1066 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1067 if (left == null || right == null)
1071 if (left is DoubleConstant)
1072 bool_res = ((DoubleConstant) left).Value <=
1073 ((DoubleConstant) right).Value;
1074 else if (left is FloatConstant)
1075 bool_res = ((FloatConstant) left).Value <=
1076 ((FloatConstant) right).Value;
1077 else if (left is ULongConstant)
1078 bool_res = ((ULongConstant) left).Value <=
1079 ((ULongConstant) right).Value;
1080 else if (left is LongConstant)
1081 bool_res = ((LongConstant) left).Value <=
1082 ((LongConstant) right).Value;
1083 else if (left is UIntConstant)
1084 bool_res = ((UIntConstant) left).Value <=
1085 ((UIntConstant) right).Value;
1086 else if (left is IntConstant)
1087 bool_res = ((IntConstant) left).Value <=
1088 ((IntConstant) right).Value;
1092 return new BoolConstant (bool_res);