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 ||
35 oper == Binary.Operator.Exponentiation || oper == Binary.Operator.Division) {
37 // If either side is a double, convert the other to a double
39 if (!(left is DoubleConstant))
40 left = left.ToDouble (loc);
42 if (!(right is DoubleConstant))
43 right = right.ToDouble (loc);
45 } else if (left is FloatConstant || right is FloatConstant) {
47 // If either side is a float, convert the other to a float
49 if (!(left is FloatConstant))
50 left = left.ToFloat (loc);
52 if (!(right is FloatConstant))
53 right = right.ToFloat (loc);
55 } else if (left is ULongConstant || right is ULongConstant){
57 // If either operand is of type ulong, the other operand is
58 // converted to type ulong. or an error ocurrs if the other
59 // operand is of type sbyte, short, int or long
62 Constant match, other;
65 if (left is ULongConstant){
70 if (!(right is ULongConstant))
71 right = right.ToULong (loc);
77 left = left.ToULong (loc);
81 if (other is SByteConstant || other is ShortConstant ||
82 other is IntConstant || other is LongConstant){
83 Binary.Error_OperatorAmbiguous
84 (loc, oper, other.Type, match.Type);
90 } else if (left is LongConstant || right is LongConstant){
92 // If either operand is of type long, the other operand is converted
95 if (!(left is LongConstant))
96 left = left.ToLong (loc);
97 else if (!(right is LongConstant))
98 right = right.ToLong (loc);
100 } else if (left is UIntConstant || right is UIntConstant){
102 // If either operand is of type uint, and the other
103 // operand is of type sbyte, short or int, the operands are
104 // converted to type long.
107 if (left is UIntConstant){
114 if (other is UIntConstant)
117 if (other is SByteConstant || other is ShortConstant ||
118 other is IntConstant){
119 left = left.ToLong (loc);
120 right = right.ToLong (loc);
124 } else if (left is EnumConstant || right is EnumConstant){
126 // If either operand is an enum constant, the other one must
127 // be implicitly convertable to that enum's underlying type.
131 if (left is EnumConstant){
133 match = (EnumConstant) left;
136 match = (EnumConstant) right;
139 bool need_check = (other is EnumConstant) ||
140 ((oper != Binary.Operator.Addition) &&
141 (oper != Binary.Operator.Subtraction));
144 !Expression.ImplicitConversionExists (ec, match, other.Type)) {
145 Expression.Error_CannotConvertImplicit (loc, match.Type, other.Type);
151 if (left is EnumConstant)
152 left = ((EnumConstant) left).Child;
153 if (right is EnumConstant)
154 right = ((EnumConstant) right).Child;
159 // Force conversions to int32
161 if (!(left is IntConstant))
162 left = left.ToInt (loc);
163 if (!(right is IntConstant))
164 right = right.ToInt (loc);
169 static void Error_CompileTimeOverflow (Location loc)
171 Report.Error (220, loc, "The operation overflows at compile time in checked mode");
175 /// Constant expression folder for binary operations.
177 /// Returns null if the expression can not be folded.
179 static public Expression BinaryFold (EmitContext ec, Binary.Operator oper,
180 Constant left, Constant right, Location loc)
183 Type rt = right.Type;
184 Type result_type = null;
188 // Enumerator folding
190 if (rt == lt && left is EnumConstant)
194 // During an enum evaluation, we need to unwrap enumerations
196 if (ec.InEnumContext){
197 if (left is EnumConstant)
198 left = ((EnumConstant) left).Child;
200 if (right is EnumConstant)
201 right = ((EnumConstant) right).Child;
205 Constant result = null;
207 case Binary.Operator.BitwiseOr:
208 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
209 if (left == null || right == null)
212 if (left is IntConstant){
214 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
216 v = new IntConstant (res);
217 if (result_type == null)
220 return new EnumConstant (v, result_type);
221 } else if (left is UIntConstant){
223 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
225 v = new UIntConstant (res);
226 if (result_type == null)
229 return new EnumConstant (v, result_type);
230 } else if (left is LongConstant){
232 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
234 v = new LongConstant (res);
235 if (result_type == null)
238 return new EnumConstant (v, result_type);
239 } else if (left is ULongConstant){
241 ulong res = ((ULongConstant)left).Value |
242 ((ULongConstant)right).Value;
244 v = new ULongConstant (res);
245 if (result_type == null)
248 return new EnumConstant (v, result_type);
252 case Binary.Operator.BitwiseAnd:
253 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
254 if (left == null || right == null)
257 if (left is IntConstant){
259 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
261 v = new IntConstant (res);
262 if (result_type == null)
265 return new EnumConstant (v, result_type);
266 } else if (left is UIntConstant){
268 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
270 v = new UIntConstant (res);
271 if (result_type == null)
274 return new EnumConstant (v, result_type);
275 } else if (left is LongConstant){
277 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
279 v = new LongConstant (res);
280 if (result_type == null)
283 return new EnumConstant (v, result_type);
284 } else if (left is ULongConstant){
286 ulong res = ((ULongConstant)left).Value &
287 ((ULongConstant)right).Value;
289 v = new ULongConstant (res);
290 if (result_type == null)
293 return new EnumConstant (v, result_type);
297 case Binary.Operator.ExclusiveOr:
298 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
299 if (left == null || right == null)
302 if (left is IntConstant){
304 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
306 v = new IntConstant (res);
307 if (result_type == null)
310 return new EnumConstant (v, result_type);
311 } else if (left is UIntConstant){
313 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
315 v = new UIntConstant (res);
316 if (result_type == null)
319 return new EnumConstant (v, result_type);
320 } else if (left is LongConstant){
322 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
324 v = new LongConstant (res);
325 if (result_type == null)
328 return new EnumConstant (v, result_type);
329 } else if (left is ULongConstant){
331 ulong res = ((ULongConstant)left).Value ^
332 ((ULongConstant)right).Value;
334 v = new ULongConstant (res);
335 if (result_type == null)
338 return new EnumConstant (v, result_type);
342 case Binary.Operator.Addition:
343 bool left_is_string = left is StringConstant;
344 bool right_is_string = right is StringConstant;
347 // If both sides are strings, then concatenate, if
348 // one is a string, and the other is not, then defer
349 // to runtime concatenation
352 if (left_is_string || right_is_string){
353 if (left_is_string && right_is_string)
354 return new StringConstant (
355 ((StringConstant) left).Value +
356 ((StringConstant) right).Value);
362 // handle "E operator + (E x, U y)"
363 // handle "E operator + (Y y, E x)"
365 // note that E operator + (E x, E y) is invalid
367 if (left is EnumConstant){
368 if (right is EnumConstant){
371 if (((EnumConstant) left).Child.Type != right.Type)
375 } else if (right is EnumConstant){
376 if (((EnumConstant) right).Child.Type != left.Type)
378 wrap_as = right.Type;
382 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
383 if (left == null || right == null)
387 if (left is DoubleConstant){
390 if (ec.ConstantCheckState)
391 res = checked (((DoubleConstant) left).Value +
392 ((DoubleConstant) right).Value);
394 res = unchecked (((DoubleConstant) left).Value +
395 ((DoubleConstant) right).Value);
397 result = new DoubleConstant (res);
398 } else if (left is FloatConstant){
401 if (ec.ConstantCheckState)
402 res = checked (((FloatConstant) left).Value +
403 ((FloatConstant) right).Value);
405 res = unchecked (((FloatConstant) left).Value +
406 ((FloatConstant) right).Value);
408 result = new FloatConstant (res);
409 } else if (left is ULongConstant){
412 if (ec.ConstantCheckState)
413 res = checked (((ULongConstant) left).Value +
414 ((ULongConstant) right).Value);
416 res = unchecked (((ULongConstant) left).Value +
417 ((ULongConstant) right).Value);
419 result = new ULongConstant (res);
420 } else if (left is LongConstant){
423 if (ec.ConstantCheckState)
424 res = checked (((LongConstant) left).Value +
425 ((LongConstant) right).Value);
427 res = unchecked (((LongConstant) left).Value +
428 ((LongConstant) right).Value);
430 result = new LongConstant (res);
431 } else if (left is UIntConstant){
434 if (ec.ConstantCheckState)
435 res = checked (((UIntConstant) left).Value +
436 ((UIntConstant) right).Value);
438 res = unchecked (((UIntConstant) left).Value +
439 ((UIntConstant) right).Value);
441 result = new UIntConstant (res);
442 } else if (left is IntConstant){
445 if (ec.ConstantCheckState)
446 res = checked (((IntConstant) left).Value +
447 ((IntConstant) right).Value);
449 res = unchecked (((IntConstant) left).Value +
450 ((IntConstant) right).Value);
452 result = new IntConstant (res);
454 throw new Exception ( "Unexepected input: " + left);
456 } catch (OverflowException){
457 Error_CompileTimeOverflow (loc);
461 return new EnumConstant (result, wrap_as);
465 case Binary.Operator.Subtraction:
467 // handle "E operator - (E x, U y)"
468 // handle "E operator - (Y y, E x)"
469 // handle "U operator - (E x, E y)"
472 if (left is EnumConstant){
473 if (right is EnumConstant){
474 if (left.Type == right.Type)
475 wrap_as = TypeManager.EnumToUnderlying (left.Type);
479 if (((EnumConstant) left).Child.Type != right.Type)
483 } else if (right is EnumConstant){
484 if (((EnumConstant) right).Child.Type != left.Type)
486 wrap_as = right.Type;
489 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
490 if (left == null || right == null)
494 if (left is DoubleConstant){
497 if (ec.ConstantCheckState)
498 res = checked (((DoubleConstant) left).Value -
499 ((DoubleConstant) right).Value);
501 res = unchecked (((DoubleConstant) left).Value -
502 ((DoubleConstant) right).Value);
504 result = new DoubleConstant (res);
505 } else if (left is FloatConstant){
508 if (ec.ConstantCheckState)
509 res = checked (((FloatConstant) left).Value -
510 ((FloatConstant) right).Value);
512 res = unchecked (((FloatConstant) left).Value -
513 ((FloatConstant) right).Value);
515 result = new FloatConstant (res);
516 } else if (left is ULongConstant){
519 if (ec.ConstantCheckState)
520 res = checked (((ULongConstant) left).Value -
521 ((ULongConstant) right).Value);
523 res = unchecked (((ULongConstant) left).Value -
524 ((ULongConstant) right).Value);
526 result = new ULongConstant (res);
527 } else if (left is LongConstant){
530 if (ec.ConstantCheckState)
531 res = checked (((LongConstant) left).Value -
532 ((LongConstant) right).Value);
534 res = unchecked (((LongConstant) left).Value -
535 ((LongConstant) right).Value);
537 result = new LongConstant (res);
538 } else if (left is UIntConstant){
541 if (ec.ConstantCheckState)
542 res = checked (((UIntConstant) left).Value -
543 ((UIntConstant) right).Value);
545 res = unchecked (((UIntConstant) left).Value -
546 ((UIntConstant) right).Value);
548 result = new UIntConstant (res);
549 } else if (left is IntConstant){
552 if (ec.ConstantCheckState)
553 res = checked (((IntConstant) left).Value -
554 ((IntConstant) right).Value);
556 res = unchecked (((IntConstant) left).Value -
557 ((IntConstant) right).Value);
559 result = new IntConstant (res);
561 throw new Exception ( "Unexepected input: " + left);
563 } catch (OverflowException){
564 Error_CompileTimeOverflow (loc);
567 return new EnumConstant (result, wrap_as);
571 case Binary.Operator.Multiply:
572 DoConstantNumericPromotions (ec, 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);
651 case Binary.Operator.IntDivision:
652 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
653 if (left == null || right == null)
657 if (left is DoubleConstant) {
658 long left_val, right_val, res;
659 left_val = (long) ((DoubleConstant) left).Value;
660 right_val = (long) ((DoubleConstant) right).Value;
662 if (ec.ConstantCheckState)
663 res = checked (left_val / right_val);
665 res = unchecked (left_val / right_val);
667 return new LongConstant (res);
668 } else if (left is FloatConstant) {
669 long left_val, right_val, res;
670 left_val = (long) ((FloatConstant) left).Value;
671 right_val = (long) ((FloatConstant) right).Value;
673 if (ec.ConstantCheckState)
674 res = checked (left_val / right_val);
676 res = unchecked (left_val / right_val);
678 return new LongConstant (res);
679 } else if (left is DecimalConstant) {
680 long left_val, right_val, res;
681 left_val = (long) ((DecimalConstant) left).Value;
682 right_val = (long) ((DecimalConstant) right).Value;
684 if (ec.ConstantCheckState)
685 res = checked (left_val / right_val);
687 res = unchecked (left_val / right_val);
689 return new LongConstant (res);
690 } else if (left is LongConstant) {
693 if (ec.ConstantCheckState)
694 res = checked (((LongConstant) left).Value /
695 ((LongConstant) right).Value);
697 res = unchecked (((LongConstant) left).Value /
698 ((LongConstant) right).Value);
700 return new LongConstant (res);
704 if (ec.ConstantCheckState)
705 res = checked (((IntConstant) left).Value /
706 ((IntConstant) right).Value);
708 res = unchecked (((IntConstant) left).Value /
709 ((IntConstant) right).Value);
711 return new IntConstant (res);
713 } catch (OverflowException){
714 Error_CompileTimeOverflow (loc);
716 } catch (DivideByZeroException) {
717 Report.Error (30542, loc, "Division by constant zero");
721 case Binary.Operator.Division:
722 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
723 if (left == null || right == null)
729 if (ec.ConstantCheckState)
730 res = checked (((DoubleConstant) left).Value /
731 ((DoubleConstant) right).Value);
733 res = unchecked (((DoubleConstant) left).Value /
734 ((DoubleConstant) right).Value);
736 return new DoubleConstant (res);
737 } catch (OverflowException){
738 Error_CompileTimeOverflow (loc);
740 } catch (DivideByZeroException) {
741 Report.Error (30542, loc, "Division by constant zero");
746 case Binary.Operator.Modulus:
747 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
748 if (left == null || right == null)
752 if (left is DoubleConstant){
755 if (ec.ConstantCheckState)
756 res = checked (((DoubleConstant) left).Value %
757 ((DoubleConstant) right).Value);
759 res = unchecked (((DoubleConstant) left).Value %
760 ((DoubleConstant) right).Value);
762 return new DoubleConstant (res);
763 } else if (left is FloatConstant){
766 if (ec.ConstantCheckState)
767 res = checked (((FloatConstant) left).Value %
768 ((FloatConstant) right).Value);
770 res = unchecked (((FloatConstant) left).Value %
771 ((FloatConstant) right).Value);
773 return new FloatConstant (res);
774 } else if (left is ULongConstant){
777 if (ec.ConstantCheckState)
778 res = checked (((ULongConstant) left).Value %
779 ((ULongConstant) right).Value);
781 res = unchecked (((ULongConstant) left).Value %
782 ((ULongConstant) right).Value);
784 return new ULongConstant (res);
785 } else if (left is LongConstant){
788 if (ec.ConstantCheckState)
789 res = checked (((LongConstant) left).Value %
790 ((LongConstant) right).Value);
792 res = unchecked (((LongConstant) left).Value %
793 ((LongConstant) right).Value);
795 return new LongConstant (res);
796 } else if (left is UIntConstant){
799 if (ec.ConstantCheckState)
800 res = checked (((UIntConstant) left).Value %
801 ((UIntConstant) right).Value);
803 res = unchecked (((UIntConstant) left).Value %
804 ((UIntConstant) right).Value);
806 return new UIntConstant (res);
807 } else if (left is IntConstant){
810 if (ec.ConstantCheckState)
811 res = checked (((IntConstant) left).Value %
812 ((IntConstant) right).Value);
814 res = unchecked (((IntConstant) left).Value %
815 ((IntConstant) right).Value);
817 return new IntConstant (res);
819 throw new Exception ( "Unexepected input: " + left);
821 } catch (OverflowException){
822 Error_CompileTimeOverflow (loc);
826 case Binary.Operator.Exponentiation:
827 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
828 if (left == null || right == null)
831 double powVal = System.Math.Pow(((DoubleConstant) left).Value,
832 ((DoubleConstant) right).Value);
834 return new DoubleConstant(powVal);
837 // There is no overflow checking on left shift
839 case Binary.Operator.LeftShift:
840 IntConstant ic = right.ToInt (loc);
842 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
845 int lshift_val = ic.Value;
848 if ((lic = left.ConvertToInt ()) != null)
849 return new IntConstant (lic.Value << lshift_val);
852 if ((luic = left.ConvertToUInt ()) != null)
853 return new UIntConstant (luic.Value << lshift_val);
856 if ((llc = left.ConvertToLong ()) != null)
857 return new LongConstant (llc.Value << lshift_val);
860 if ((lulc = left.ConvertToULong ()) != null)
861 return new ULongConstant (lulc.Value << lshift_val);
863 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
867 // There is no overflow checking on right shift
869 case Binary.Operator.RightShift:
870 IntConstant sic = right.ToInt (loc);
872 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
875 int rshift_val = sic.Value;
878 if ((ric = left.ConvertToInt ()) != null)
879 return new IntConstant (ric.Value >> rshift_val);
882 if ((ruic = left.ConvertToUInt ()) != null)
883 return new UIntConstant (ruic.Value >> rshift_val);
886 if ((rlc = left.ConvertToLong ()) != null)
887 return new LongConstant (rlc.Value >> rshift_val);
890 if ((rulc = left.ConvertToULong ()) != null)
891 return new ULongConstant (rulc.Value >> rshift_val);
893 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
896 case Binary.Operator.LogicalAnd:
897 if (left is BoolConstant && right is BoolConstant){
898 return new BoolConstant (
899 ((BoolConstant) left).Value &&
900 ((BoolConstant) right).Value);
904 case Binary.Operator.LogicalOr:
905 if (left is BoolConstant && right is BoolConstant){
906 return new BoolConstant (
907 ((BoolConstant) left).Value ||
908 ((BoolConstant) right).Value);
912 case Binary.Operator.Equality:
913 if (left is BoolConstant && right is BoolConstant){
914 return new BoolConstant (
915 ((BoolConstant) left).Value ==
916 ((BoolConstant) right).Value);
919 if (left is StringConstant && right is StringConstant){
920 return new BoolConstant (
921 ((StringConstant) left).Value ==
922 ((StringConstant) right).Value);
926 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
927 if (left == null || right == null)
931 if (left is DoubleConstant)
932 bool_res = ((DoubleConstant) left).Value ==
933 ((DoubleConstant) right).Value;
934 else if (left is FloatConstant)
935 bool_res = ((FloatConstant) left).Value ==
936 ((FloatConstant) right).Value;
937 else if (left is ULongConstant)
938 bool_res = ((ULongConstant) left).Value ==
939 ((ULongConstant) right).Value;
940 else if (left is LongConstant)
941 bool_res = ((LongConstant) left).Value ==
942 ((LongConstant) right).Value;
943 else if (left is UIntConstant)
944 bool_res = ((UIntConstant) left).Value ==
945 ((UIntConstant) right).Value;
946 else if (left is IntConstant)
947 bool_res = ((IntConstant) left).Value ==
948 ((IntConstant) right).Value;
952 return new BoolConstant (bool_res);
954 case Binary.Operator.Inequality:
955 if (left is BoolConstant && right is BoolConstant){
956 return new BoolConstant (
957 ((BoolConstant) left).Value !=
958 ((BoolConstant) right).Value);
960 if (left is StringConstant && right is StringConstant){
961 return new BoolConstant (
962 ((StringConstant) left).Value !=
963 ((StringConstant) right).Value);
966 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
967 if (left == null || right == null)
971 if (left is DoubleConstant)
972 bool_res = ((DoubleConstant) left).Value !=
973 ((DoubleConstant) right).Value;
974 else if (left is FloatConstant)
975 bool_res = ((FloatConstant) left).Value !=
976 ((FloatConstant) right).Value;
977 else if (left is ULongConstant)
978 bool_res = ((ULongConstant) left).Value !=
979 ((ULongConstant) right).Value;
980 else if (left is LongConstant)
981 bool_res = ((LongConstant) left).Value !=
982 ((LongConstant) right).Value;
983 else if (left is UIntConstant)
984 bool_res = ((UIntConstant) left).Value !=
985 ((UIntConstant) right).Value;
986 else if (left is IntConstant)
987 bool_res = ((IntConstant) left).Value !=
988 ((IntConstant) right).Value;
992 return new BoolConstant (bool_res);
994 case Binary.Operator.LessThan:
995 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
996 if (left == null || right == null)
1000 if (left is DoubleConstant)
1001 bool_res = ((DoubleConstant) left).Value <
1002 ((DoubleConstant) right).Value;
1003 else if (left is FloatConstant)
1004 bool_res = ((FloatConstant) left).Value <
1005 ((FloatConstant) right).Value;
1006 else if (left is ULongConstant)
1007 bool_res = ((ULongConstant) left).Value <
1008 ((ULongConstant) right).Value;
1009 else if (left is LongConstant)
1010 bool_res = ((LongConstant) left).Value <
1011 ((LongConstant) right).Value;
1012 else if (left is UIntConstant)
1013 bool_res = ((UIntConstant) left).Value <
1014 ((UIntConstant) right).Value;
1015 else if (left is IntConstant)
1016 bool_res = ((IntConstant) left).Value <
1017 ((IntConstant) right).Value;
1021 return new BoolConstant (bool_res);
1023 case Binary.Operator.GreaterThan:
1024 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1025 if (left == null || right == null)
1029 if (left is DoubleConstant)
1030 bool_res = ((DoubleConstant) left).Value >
1031 ((DoubleConstant) right).Value;
1032 else if (left is FloatConstant)
1033 bool_res = ((FloatConstant) left).Value >
1034 ((FloatConstant) right).Value;
1035 else if (left is ULongConstant)
1036 bool_res = ((ULongConstant) left).Value >
1037 ((ULongConstant) right).Value;
1038 else if (left is LongConstant)
1039 bool_res = ((LongConstant) left).Value >
1040 ((LongConstant) right).Value;
1041 else if (left is UIntConstant)
1042 bool_res = ((UIntConstant) left).Value >
1043 ((UIntConstant) right).Value;
1044 else if (left is IntConstant)
1045 bool_res = ((IntConstant) left).Value >
1046 ((IntConstant) right).Value;
1050 return new BoolConstant (bool_res);
1052 case Binary.Operator.GreaterThanOrEqual:
1053 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1054 if (left == null || right == null)
1058 if (left is DoubleConstant)
1059 bool_res = ((DoubleConstant) left).Value >=
1060 ((DoubleConstant) right).Value;
1061 else if (left is FloatConstant)
1062 bool_res = ((FloatConstant) left).Value >=
1063 ((FloatConstant) right).Value;
1064 else if (left is ULongConstant)
1065 bool_res = ((ULongConstant) left).Value >=
1066 ((ULongConstant) right).Value;
1067 else if (left is LongConstant)
1068 bool_res = ((LongConstant) left).Value >=
1069 ((LongConstant) right).Value;
1070 else if (left is UIntConstant)
1071 bool_res = ((UIntConstant) left).Value >=
1072 ((UIntConstant) right).Value;
1073 else if (left is IntConstant)
1074 bool_res = ((IntConstant) left).Value >=
1075 ((IntConstant) right).Value;
1079 return new BoolConstant (bool_res);
1081 case Binary.Operator.LessThanOrEqual:
1082 DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);
1083 if (left == null || right == null)
1087 if (left is DoubleConstant)
1088 bool_res = ((DoubleConstant) left).Value <=
1089 ((DoubleConstant) right).Value;
1090 else if (left is FloatConstant)
1091 bool_res = ((FloatConstant) left).Value <=
1092 ((FloatConstant) right).Value;
1093 else if (left is ULongConstant)
1094 bool_res = ((ULongConstant) left).Value <=
1095 ((ULongConstant) right).Value;
1096 else if (left is LongConstant)
1097 bool_res = ((LongConstant) left).Value <=
1098 ((LongConstant) right).Value;
1099 else if (left is UIntConstant)
1100 bool_res = ((UIntConstant) left).Value <=
1101 ((UIntConstant) right).Value;
1102 else if (left is IntConstant)
1103 bool_res = ((IntConstant) left).Value <=
1104 ((IntConstant) right).Value;
1108 return new BoolConstant (bool_res);