2 // cfold.cs: Constant Folding
\r
5 // Miguel de Icaza (miguel@ximian.com)
\r
7 // (C) 2002 Ximian, Inc.
\r
12 namespace Mono.CSharp {
\r
14 public class ConstantFold {
\r
17 // Performs the numeric promotions on the left and right expresions
\r
18 // and desposits the results on `lc' and `rc'.
\r
20 // On success, the types of `lc' and `rc' on output will always match,
\r
21 // and the pair will be one of:
\r
30 static void DoConstantNumericPromotions (Binary.Operator oper,
\r
31 ref Constant left, ref Constant right,
\r
34 if (left is DoubleConstant || right is DoubleConstant){
\r
36 // If either side is a double, convert the other to a double
\r
38 if (!(left is DoubleConstant))
\r
39 left = left.ToDouble (loc);
\r
41 if (!(right is DoubleConstant))
\r
42 right = right.ToDouble (loc);
\r
44 } else if (left is FloatConstant || right is FloatConstant) {
\r
46 // If either side is a float, convert the other to a float
\r
48 if (!(left is FloatConstant))
\r
49 left = left.ToFloat (loc);
\r
51 if (!(right is FloatConstant))
\r
52 right = right.ToFloat (loc);
\r
54 } else if (left is ULongConstant || right is ULongConstant){
\r
56 // If either operand is of type ulong, the other operand is
\r
57 // converted to type ulong. or an error ocurrs if the other
\r
58 // operand is of type sbyte, short, int or long
\r
60 Constant match, other;
\r
62 if (left is ULongConstant){
\r
65 if (!(right is ULongConstant))
\r
66 right = right.ToULong (loc);
\r
70 left = left.ToULong (loc);
\r
74 if (other is SByteConstant || other is ShortConstant ||
\r
75 other is IntConstant || other is LongConstant){
\r
76 Binary.Error_OperatorAmbiguous
\r
77 (loc, oper, other.Type, match.Type);
\r
83 } else if (left is LongConstant || right is LongConstant){
\r
85 // If either operand is of type long, the other operand is converted
\r
88 if (!(left is LongConstant))
\r
89 left = left.ToLong (loc);
\r
90 else if (!(right is LongConstant))
\r
91 right = right.ToLong (loc);
\r
93 } else if (left is UIntConstant || right is UIntConstant){
\r
95 // If either operand is of type uint, and the other
\r
96 // operand is of type sbyte, short or int, othe operands are
\r
97 // converted to type long.
\r
99 if (!(left is UIntConstant))
\r
100 left = left.ToUInt (loc);
\r
101 else if (!(right is UIntConstant))
\r
102 right = right.ToUInt (loc);
\r
106 // Force conversions to int32
\r
108 if (!(left is IntConstant))
\r
109 left = left.ToInt (loc);
\r
110 if (!(right is IntConstant))
\r
111 right = right.ToInt (loc);
\r
116 static void Error_CompileTimeOverflow (Location loc)
\r
118 Report.Error (220, loc, "The operation overflows at compile time in checked mode");
\r
122 /// Constant expression folder for binary operations.
\r
124 /// Returns null if the expression can not be folded.
\r
126 static public Expression BinaryFold (EmitContext ec, Binary.Operator oper,
\r
127 Constant left, Constant right, Location loc)
\r
129 Type lt = left.Type;
\r
130 Type rt = right.Type;
\r
131 Type result_type = null;
\r
135 // Enumerator folding
\r
137 if (rt == lt && left is EnumConstant)
\r
141 case Binary.Operator.BitwiseOr:
\r
142 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
143 if (left == null || right == null)
\r
146 if (left is IntConstant){
\r
148 int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
\r
150 v = new IntConstant (res);
\r
151 if (result_type == null)
\r
154 return new EnumConstant (v, result_type);
\r
155 } else if (left is UIntConstant){
\r
157 uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
\r
159 v = new UIntConstant (res);
\r
160 if (result_type == null)
\r
163 return new EnumConstant (v, result_type);
\r
164 } else if (left is LongConstant){
\r
166 long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
\r
168 v = new LongConstant (res);
\r
169 if (result_type == null)
\r
172 return new EnumConstant (v, result_type);
\r
173 } else if (left is ULongConstant){
\r
175 ulong res = ((ULongConstant)left).Value |
\r
176 ((ULongConstant)right).Value;
\r
178 v = new ULongConstant (res);
\r
179 if (result_type == null)
\r
182 return new EnumConstant (v, result_type);
\r
186 case Binary.Operator.BitwiseAnd:
\r
187 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
188 if (left == null || right == null)
\r
191 if (left is IntConstant){
\r
193 int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
\r
195 v = new IntConstant (res);
\r
196 if (result_type == null)
\r
199 return new EnumConstant (v, result_type);
\r
200 } else if (left is UIntConstant){
\r
202 uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
\r
204 v = new UIntConstant (res);
\r
205 if (result_type == null)
\r
208 return new EnumConstant (v, result_type);
\r
209 } else if (left is LongConstant){
\r
211 long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
\r
213 v = new LongConstant (res);
\r
214 if (result_type == null)
\r
217 return new EnumConstant (v, result_type);
\r
218 } else if (left is ULongConstant){
\r
220 ulong res = ((ULongConstant)left).Value &
\r
221 ((ULongConstant)right).Value;
\r
223 v = new ULongConstant (res);
\r
224 if (result_type == null)
\r
227 return new EnumConstant (v, result_type);
\r
231 case Binary.Operator.ExclusiveOr:
\r
232 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
233 if (left == null || right == null)
\r
236 if (left is IntConstant){
\r
238 int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
\r
240 v = new IntConstant (res);
\r
241 if (result_type == null)
\r
244 return new EnumConstant (v, result_type);
\r
245 } else if (left is UIntConstant){
\r
247 uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
\r
249 v = new UIntConstant (res);
\r
250 if (result_type == null)
\r
253 return new EnumConstant (v, result_type);
\r
254 } else if (left is LongConstant){
\r
256 long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
\r
258 v = new LongConstant (res);
\r
259 if (result_type == null)
\r
262 return new EnumConstant (v, result_type);
\r
263 } else if (left is ULongConstant){
\r
265 ulong res = ((ULongConstant)left).Value ^
\r
266 ((ULongConstant)right).Value;
\r
268 v = new ULongConstant (res);
\r
269 if (result_type == null)
\r
272 return new EnumConstant (v, result_type);
\r
276 case Binary.Operator.Addition:
\r
277 bool left_is_string = left is StringConstant;
\r
278 bool right_is_string = right is StringConstant;
\r
281 // If both sides are strings, then concatenate, if
\r
282 // one is a string, and the other is not, then defer
\r
283 // to runtime concatenation
\r
285 if (left_is_string || right_is_string){
\r
286 if (left_is_string && right_is_string)
\r
287 return new StringConstant (
\r
288 ((StringConstant) left).Value +
\r
289 ((StringConstant) right).Value);
\r
294 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
295 if (left == null || right == null)
\r
299 if (left is DoubleConstant){
\r
302 if (ec.ConstantCheckState)
\r
303 res = checked (((DoubleConstant) left).Value +
\r
304 ((DoubleConstant) right).Value);
\r
306 res = unchecked (((DoubleConstant) left).Value +
\r
307 ((DoubleConstant) right).Value);
\r
309 return new DoubleConstant (res);
\r
310 } else if (left is FloatConstant){
\r
313 if (ec.ConstantCheckState)
\r
314 res = checked (((FloatConstant) left).Value +
\r
315 ((FloatConstant) right).Value);
\r
317 res = unchecked (((FloatConstant) left).Value +
\r
318 ((FloatConstant) right).Value);
\r
320 return new FloatConstant (res);
\r
321 } else if (left is ULongConstant){
\r
324 if (ec.ConstantCheckState)
\r
325 res = checked (((ULongConstant) left).Value +
\r
326 ((ULongConstant) right).Value);
\r
328 res = unchecked (((ULongConstant) left).Value +
\r
329 ((ULongConstant) right).Value);
\r
331 return new ULongConstant (res);
\r
332 } else if (left is LongConstant){
\r
335 if (ec.ConstantCheckState)
\r
336 res = checked (((LongConstant) left).Value +
\r
337 ((LongConstant) right).Value);
\r
339 res = unchecked (((LongConstant) left).Value +
\r
340 ((LongConstant) right).Value);
\r
342 return new LongConstant (res);
\r
343 } else if (left is UIntConstant){
\r
346 if (ec.ConstantCheckState)
\r
347 res = checked (((UIntConstant) left).Value +
\r
348 ((UIntConstant) right).Value);
\r
350 res = unchecked (((UIntConstant) left).Value +
\r
351 ((UIntConstant) right).Value);
\r
353 return new UIntConstant (res);
\r
354 } else if (left is IntConstant){
\r
357 if (ec.ConstantCheckState)
\r
358 res = checked (((IntConstant) left).Value +
\r
359 ((IntConstant) right).Value);
\r
361 res = unchecked (((IntConstant) left).Value +
\r
362 ((IntConstant) right).Value);
\r
364 return new IntConstant (res);
\r
366 throw new Exception ( "Unexepected input: " + left);
\r
368 } catch (OverflowException){
\r
369 Error_CompileTimeOverflow (loc);
\r
373 case Binary.Operator.Subtraction:
\r
374 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
375 if (left == null || right == null)
\r
379 if (left is DoubleConstant){
\r
382 if (ec.ConstantCheckState)
\r
383 res = checked (((DoubleConstant) left).Value -
\r
384 ((DoubleConstant) right).Value);
\r
386 res = unchecked (((DoubleConstant) left).Value -
\r
387 ((DoubleConstant) right).Value);
\r
389 return new DoubleConstant (res);
\r
390 } else if (left is FloatConstant){
\r
393 if (ec.ConstantCheckState)
\r
394 res = checked (((FloatConstant) left).Value -
\r
395 ((FloatConstant) right).Value);
\r
397 res = unchecked (((FloatConstant) left).Value -
\r
398 ((FloatConstant) right).Value);
\r
400 return new FloatConstant (res);
\r
401 } else if (left is ULongConstant){
\r
404 if (ec.ConstantCheckState)
\r
405 res = checked (((ULongConstant) left).Value -
\r
406 ((ULongConstant) right).Value);
\r
408 res = unchecked (((ULongConstant) left).Value -
\r
409 ((ULongConstant) right).Value);
\r
411 return new ULongConstant (res);
\r
412 } else if (left is LongConstant){
\r
415 if (ec.ConstantCheckState)
\r
416 res = checked (((LongConstant) left).Value -
\r
417 ((LongConstant) right).Value);
\r
419 res = unchecked (((LongConstant) left).Value -
\r
420 ((LongConstant) right).Value);
\r
422 return new LongConstant (res);
\r
423 } else if (left is UIntConstant){
\r
426 if (ec.ConstantCheckState)
\r
427 res = checked (((UIntConstant) left).Value -
\r
428 ((UIntConstant) right).Value);
\r
430 res = unchecked (((UIntConstant) left).Value -
\r
431 ((UIntConstant) right).Value);
\r
433 return new UIntConstant (res);
\r
434 } else if (left is IntConstant){
\r
437 if (ec.ConstantCheckState)
\r
438 res = checked (((IntConstant) left).Value -
\r
439 ((IntConstant) right).Value);
\r
441 res = unchecked (((IntConstant) left).Value -
\r
442 ((IntConstant) right).Value);
\r
444 return new IntConstant (res);
\r
446 throw new Exception ( "Unexepected input: " + left);
\r
448 } catch (OverflowException){
\r
449 Error_CompileTimeOverflow (loc);
\r
453 case Binary.Operator.Multiply:
\r
454 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
455 if (left == null || right == null)
\r
459 if (left is DoubleConstant){
\r
462 if (ec.ConstantCheckState)
\r
463 res = checked (((DoubleConstant) left).Value *
\r
464 ((DoubleConstant) right).Value);
\r
466 res = unchecked (((DoubleConstant) left).Value *
\r
467 ((DoubleConstant) right).Value);
\r
469 return new DoubleConstant (res);
\r
470 } else if (left is FloatConstant){
\r
473 if (ec.ConstantCheckState)
\r
474 res = checked (((FloatConstant) left).Value *
\r
475 ((FloatConstant) right).Value);
\r
477 res = unchecked (((FloatConstant) left).Value *
\r
478 ((FloatConstant) right).Value);
\r
480 return new FloatConstant (res);
\r
481 } else if (left is ULongConstant){
\r
484 if (ec.ConstantCheckState)
\r
485 res = checked (((ULongConstant) left).Value *
\r
486 ((ULongConstant) right).Value);
\r
488 res = unchecked (((ULongConstant) left).Value *
\r
489 ((ULongConstant) right).Value);
\r
491 return new ULongConstant (res);
\r
492 } else if (left is LongConstant){
\r
495 if (ec.ConstantCheckState)
\r
496 res = checked (((LongConstant) left).Value *
\r
497 ((LongConstant) right).Value);
\r
499 res = unchecked (((LongConstant) left).Value *
\r
500 ((LongConstant) right).Value);
\r
502 return new LongConstant (res);
\r
503 } else if (left is UIntConstant){
\r
506 if (ec.ConstantCheckState)
\r
507 res = checked (((UIntConstant) left).Value *
\r
508 ((UIntConstant) right).Value);
\r
510 res = unchecked (((UIntConstant) left).Value *
\r
511 ((UIntConstant) right).Value);
\r
513 return new UIntConstant (res);
\r
514 } else if (left is IntConstant){
\r
517 if (ec.ConstantCheckState)
\r
518 res = checked (((IntConstant) left).Value *
\r
519 ((IntConstant) right).Value);
\r
521 res = unchecked (((IntConstant) left).Value *
\r
522 ((IntConstant) right).Value);
\r
524 return new IntConstant (res);
\r
526 throw new Exception ( "Unexepected input: " + left);
\r
528 } catch (OverflowException){
\r
529 Error_CompileTimeOverflow (loc);
\r
533 case Binary.Operator.Division:
\r
534 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
535 if (left == null || right == null)
\r
539 if (left is DoubleConstant){
\r
542 if (ec.ConstantCheckState)
\r
543 res = checked (((DoubleConstant) left).Value /
\r
544 ((DoubleConstant) right).Value);
\r
546 res = unchecked (((DoubleConstant) left).Value /
\r
547 ((DoubleConstant) right).Value);
\r
549 return new DoubleConstant (res);
\r
550 } else if (left is FloatConstant){
\r
553 if (ec.ConstantCheckState)
\r
554 res = checked (((FloatConstant) left).Value /
\r
555 ((FloatConstant) right).Value);
\r
557 res = unchecked (((FloatConstant) left).Value /
\r
558 ((FloatConstant) right).Value);
\r
560 return new FloatConstant (res);
\r
561 } else if (left is ULongConstant){
\r
564 if (ec.ConstantCheckState)
\r
565 res = checked (((ULongConstant) left).Value /
\r
566 ((ULongConstant) right).Value);
\r
568 res = unchecked (((ULongConstant) left).Value /
\r
569 ((ULongConstant) right).Value);
\r
571 return new ULongConstant (res);
\r
572 } else if (left is LongConstant){
\r
575 if (ec.ConstantCheckState)
\r
576 res = checked (((LongConstant) left).Value /
\r
577 ((LongConstant) right).Value);
\r
579 res = unchecked (((LongConstant) left).Value /
\r
580 ((LongConstant) right).Value);
\r
582 return new LongConstant (res);
\r
583 } else if (left is UIntConstant){
\r
586 if (ec.ConstantCheckState)
\r
587 res = checked (((UIntConstant) left).Value /
\r
588 ((UIntConstant) right).Value);
\r
590 res = unchecked (((UIntConstant) left).Value /
\r
591 ((UIntConstant) right).Value);
\r
593 return new UIntConstant (res);
\r
594 } else if (left is IntConstant){
\r
597 if (ec.ConstantCheckState)
\r
598 res = checked (((IntConstant) left).Value /
\r
599 ((IntConstant) right).Value);
\r
601 res = unchecked (((IntConstant) left).Value /
\r
602 ((IntConstant) right).Value);
\r
604 return new IntConstant (res);
\r
606 throw new Exception ( "Unexepected input: " + left);
\r
608 } catch (OverflowException){
\r
609 Error_CompileTimeOverflow (loc);
\r
613 case Binary.Operator.Modulus:
\r
614 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
615 if (left == null || right == null)
\r
619 if (left is DoubleConstant){
\r
622 if (ec.ConstantCheckState)
\r
623 res = checked (((DoubleConstant) left).Value %
\r
624 ((DoubleConstant) right).Value);
\r
626 res = unchecked (((DoubleConstant) left).Value %
\r
627 ((DoubleConstant) right).Value);
\r
629 return new DoubleConstant (res);
\r
630 } else if (left is FloatConstant){
\r
633 if (ec.ConstantCheckState)
\r
634 res = checked (((FloatConstant) left).Value %
\r
635 ((FloatConstant) right).Value);
\r
637 res = unchecked (((FloatConstant) left).Value %
\r
638 ((FloatConstant) right).Value);
\r
640 return new FloatConstant (res);
\r
641 } else if (left is ULongConstant){
\r
644 if (ec.ConstantCheckState)
\r
645 res = checked (((ULongConstant) left).Value %
\r
646 ((ULongConstant) right).Value);
\r
648 res = unchecked (((ULongConstant) left).Value %
\r
649 ((ULongConstant) right).Value);
\r
651 return new ULongConstant (res);
\r
652 } else if (left is LongConstant){
\r
655 if (ec.ConstantCheckState)
\r
656 res = checked (((LongConstant) left).Value %
\r
657 ((LongConstant) right).Value);
\r
659 res = unchecked (((LongConstant) left).Value %
\r
660 ((LongConstant) right).Value);
\r
662 return new LongConstant (res);
\r
663 } else if (left is UIntConstant){
\r
666 if (ec.ConstantCheckState)
\r
667 res = checked (((UIntConstant) left).Value %
\r
668 ((UIntConstant) right).Value);
\r
670 res = unchecked (((UIntConstant) left).Value %
\r
671 ((UIntConstant) right).Value);
\r
673 return new UIntConstant (res);
\r
674 } else if (left is IntConstant){
\r
677 if (ec.ConstantCheckState)
\r
678 res = checked (((IntConstant) left).Value %
\r
679 ((IntConstant) right).Value);
\r
681 res = unchecked (((IntConstant) left).Value %
\r
682 ((IntConstant) right).Value);
\r
684 return new IntConstant (res);
\r
686 throw new Exception ( "Unexepected input: " + left);
\r
688 } catch (OverflowException){
\r
689 Error_CompileTimeOverflow (loc);
\r
694 // There is no overflow checking on left shift
\r
696 case Binary.Operator.LeftShift:
\r
697 IntConstant ic = right.ToInt (loc);
\r
699 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
\r
702 int lshift_val = ic.Value;
\r
705 if ((lic = left.ConvertToInt ()) != null)
\r
706 return new IntConstant (lic.Value << lshift_val);
\r
709 if ((luic = left.ConvertToUInt ()) != null)
\r
710 return new UIntConstant (luic.Value << lshift_val);
\r
713 if ((llc = left.ConvertToLong ()) != null)
\r
714 return new LongConstant (llc.Value << lshift_val);
\r
716 ULongConstant lulc;
\r
717 if ((lulc = left.ConvertToULong ()) != null)
\r
718 return new ULongConstant (lulc.Value << lshift_val);
\r
720 Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);
\r
724 // There is no overflow checking on right shift
\r
726 case Binary.Operator.RightShift:
\r
727 IntConstant sic = right.ToInt (loc);
\r
729 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
\r
732 int rshift_val = sic.Value;
\r
735 if ((ric = left.ConvertToInt ()) != null)
\r
736 return new IntConstant (ric.Value >> rshift_val);
\r
739 if ((ruic = left.ConvertToUInt ()) != null)
\r
740 return new UIntConstant (ruic.Value >> rshift_val);
\r
743 if ((rlc = left.ConvertToLong ()) != null)
\r
744 return new LongConstant (rlc.Value >> rshift_val);
\r
746 ULongConstant rulc;
\r
747 if ((rulc = left.ConvertToULong ()) != null)
\r
748 return new ULongConstant (rulc.Value >> rshift_val);
\r
750 Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
\r
753 case Binary.Operator.LogicalAnd:
\r
754 if (left is BoolConstant && right is BoolConstant){
\r
755 return new BoolConstant (
\r
756 ((BoolConstant) left).Value &&
\r
757 ((BoolConstant) right).Value);
\r
761 case Binary.Operator.LogicalOr:
\r
762 if (left is BoolConstant && right is BoolConstant){
\r
763 return new BoolConstant (
\r
764 ((BoolConstant) left).Value ||
\r
765 ((BoolConstant) right).Value);
\r
769 case Binary.Operator.Equality:
\r
770 if (left is BoolConstant && right is BoolConstant){
\r
771 return new BoolConstant (
\r
772 ((BoolConstant) left).Value ==
\r
773 ((BoolConstant) right).Value);
\r
776 if (left is StringConstant && right is StringConstant){
\r
777 return new BoolConstant (
\r
778 ((StringConstant) left).Value ==
\r
779 ((StringConstant) right).Value);
\r
783 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
784 if (left == null || right == null)
\r
788 if (left is DoubleConstant)
\r
789 bool_res = ((DoubleConstant) left).Value ==
\r
790 ((DoubleConstant) right).Value;
\r
791 else if (left is FloatConstant)
\r
792 bool_res = ((FloatConstant) left).Value ==
\r
793 ((FloatConstant) right).Value;
\r
794 else if (left is ULongConstant)
\r
795 bool_res = ((ULongConstant) left).Value ==
\r
796 ((ULongConstant) right).Value;
\r
797 else if (left is LongConstant)
\r
798 bool_res = ((LongConstant) left).Value ==
\r
799 ((LongConstant) right).Value;
\r
800 else if (left is UIntConstant)
\r
801 bool_res = ((UIntConstant) left).Value ==
\r
802 ((UIntConstant) right).Value;
\r
803 else if (left is IntConstant)
\r
804 bool_res = ((IntConstant) left).Value ==
\r
805 ((IntConstant) right).Value;
\r
809 return new BoolConstant (bool_res);
\r
811 case Binary.Operator.Inequality:
\r
812 if (left is BoolConstant && right is BoolConstant){
\r
813 return new BoolConstant (
\r
814 ((BoolConstant) left).Value !=
\r
815 ((BoolConstant) right).Value);
\r
817 if (left is StringConstant && right is StringConstant){
\r
818 return new BoolConstant (
\r
819 ((StringConstant) left).Value !=
\r
820 ((StringConstant) right).Value);
\r
823 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
824 if (left == null || right == null)
\r
828 if (left is DoubleConstant)
\r
829 bool_res = ((DoubleConstant) left).Value !=
\r
830 ((DoubleConstant) right).Value;
\r
831 else if (left is FloatConstant)
\r
832 bool_res = ((FloatConstant) left).Value !=
\r
833 ((FloatConstant) right).Value;
\r
834 else if (left is ULongConstant)
\r
835 bool_res = ((ULongConstant) left).Value !=
\r
836 ((ULongConstant) right).Value;
\r
837 else if (left is LongConstant)
\r
838 bool_res = ((LongConstant) left).Value !=
\r
839 ((LongConstant) right).Value;
\r
840 else if (left is UIntConstant)
\r
841 bool_res = ((UIntConstant) left).Value !=
\r
842 ((UIntConstant) right).Value;
\r
843 else if (left is IntConstant)
\r
844 bool_res = ((IntConstant) left).Value !=
\r
845 ((IntConstant) right).Value;
\r
849 return new BoolConstant (bool_res);
\r
851 case Binary.Operator.LessThan:
\r
852 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
853 if (left == null || right == null)
\r
857 if (left is DoubleConstant)
\r
858 bool_res = ((DoubleConstant) left).Value <
\r
859 ((DoubleConstant) right).Value;
\r
860 else if (left is FloatConstant)
\r
861 bool_res = ((FloatConstant) left).Value <
\r
862 ((FloatConstant) right).Value;
\r
863 else if (left is ULongConstant)
\r
864 bool_res = ((ULongConstant) left).Value <
\r
865 ((ULongConstant) right).Value;
\r
866 else if (left is LongConstant)
\r
867 bool_res = ((LongConstant) left).Value <
\r
868 ((LongConstant) right).Value;
\r
869 else if (left is UIntConstant)
\r
870 bool_res = ((UIntConstant) left).Value <
\r
871 ((UIntConstant) right).Value;
\r
872 else if (left is IntConstant)
\r
873 bool_res = ((IntConstant) left).Value <
\r
874 ((IntConstant) right).Value;
\r
878 return new BoolConstant (bool_res);
\r
880 case Binary.Operator.GreaterThan:
\r
881 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
882 if (left == null || right == null)
\r
886 if (left is DoubleConstant)
\r
887 bool_res = ((DoubleConstant) left).Value >
\r
888 ((DoubleConstant) right).Value;
\r
889 else if (left is FloatConstant)
\r
890 bool_res = ((FloatConstant) left).Value >
\r
891 ((FloatConstant) right).Value;
\r
892 else if (left is ULongConstant)
\r
893 bool_res = ((ULongConstant) left).Value >
\r
894 ((ULongConstant) right).Value;
\r
895 else if (left is LongConstant)
\r
896 bool_res = ((LongConstant) left).Value >
\r
897 ((LongConstant) right).Value;
\r
898 else if (left is UIntConstant)
\r
899 bool_res = ((UIntConstant) left).Value >
\r
900 ((UIntConstant) right).Value;
\r
901 else if (left is IntConstant)
\r
902 bool_res = ((IntConstant) left).Value >
\r
903 ((IntConstant) right).Value;
\r
907 return new BoolConstant (bool_res);
\r
909 case Binary.Operator.GreaterThanOrEqual:
\r
910 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
911 if (left == null || right == null)
\r
915 if (left is DoubleConstant)
\r
916 bool_res = ((DoubleConstant) left).Value >=
\r
917 ((DoubleConstant) right).Value;
\r
918 else if (left is FloatConstant)
\r
919 bool_res = ((FloatConstant) left).Value >=
\r
920 ((FloatConstant) right).Value;
\r
921 else if (left is ULongConstant)
\r
922 bool_res = ((ULongConstant) left).Value >=
\r
923 ((ULongConstant) right).Value;
\r
924 else if (left is LongConstant)
\r
925 bool_res = ((LongConstant) left).Value >=
\r
926 ((LongConstant) right).Value;
\r
927 else if (left is UIntConstant)
\r
928 bool_res = ((UIntConstant) left).Value >=
\r
929 ((UIntConstant) right).Value;
\r
930 else if (left is IntConstant)
\r
931 bool_res = ((IntConstant) left).Value >=
\r
932 ((IntConstant) right).Value;
\r
936 return new BoolConstant (bool_res);
\r
938 case Binary.Operator.LessThanOrEqual:
\r
939 DoConstantNumericPromotions (oper, ref left, ref right, loc);
\r
940 if (left == null || right == null)
\r
944 if (left is DoubleConstant)
\r
945 bool_res = ((DoubleConstant) left).Value <=
\r
946 ((DoubleConstant) right).Value;
\r
947 else if (left is FloatConstant)
\r
948 bool_res = ((FloatConstant) left).Value <=
\r
949 ((FloatConstant) right).Value;
\r
950 else if (left is ULongConstant)
\r
951 bool_res = ((ULongConstant) left).Value <=
\r
952 ((ULongConstant) right).Value;
\r
953 else if (left is LongConstant)
\r
954 bool_res = ((LongConstant) left).Value <=
\r
955 ((LongConstant) right).Value;
\r
956 else if (left is UIntConstant)
\r
957 bool_res = ((UIntConstant) left).Value <=
\r
958 ((UIntConstant) right).Value;
\r
959 else if (left is IntConstant)
\r
960 bool_res = ((IntConstant) left).Value <=
\r
961 ((IntConstant) right).Value;
\r
965 return new BoolConstant (bool_res);
\r