Author: sudha
Date: 2005-03-09 23:07:51 -0500 (Wed, 09 Mar 2005)
New Revision: 41627

Modified:
   trunk/mcs/mbas/ChangeLog
   trunk/mcs/mbas/expression.cs
   trunk/mcs/mbas/mb-parser.jay
Log:
Support for 'AndAlso' and 'OrElse' operators


Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog    2005-03-10 02:14:31 UTC (rev 41626)
+++ trunk/mcs/mbas/ChangeLog    2005-03-10 04:07:51 UTC (rev 41627)
@@ -1,3 +1,8 @@
+2005-03-10 Satya Sudha K <[EMAIL PROTECTED]>
+       * mb-parser.jay :
+       * expression.cs :
+                       Support for 'AndAlso' and 'OrElse' operator
+
 2005-03-09 Manjula GHM <[EMAIL PROTECTED]>
        *mb-parser.jay :
        *expression.cs :

Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs        2005-03-10 02:14:31 UTC (rev 41626)
+++ trunk/mcs/mbas/expression.cs        2005-03-10 04:07:51 UTC (rev 41627)
@@ -1013,7 +1013,6 @@
                }
        }
 
-       
        /// <summary>
        ///   Implementation of the 'is' operator.
        /// </summary>
@@ -1116,7 +1115,6 @@
                }                               
        }
 
-
        /// <summary>
        ///   Implementation of the 'as' operator.
        /// </summary>
@@ -1941,7 +1939,7 @@
                        if (oper == Operator.LeftShift || oper == 
Operator.RightShift)
                                return true;
                        if (l == TypeManager.bool_type && r == 
TypeManager.bool_type) {
-                               if (IsBitwiseOperator (oper) || 
IsRelationalOperator (oper)) 
+                               if (IsBitwiseOperator (oper) || 
IsRelationalOperator (oper) || IsLogicalOperator (oper)) 
                                        return true;
                                if (IsArithmaticOperator (oper) && oper != 
Operator.Division) {
                                        type = TypeManager.int32_type;
@@ -1965,7 +1963,14 @@
                                }
                        }
 
-                       if ((l == TypeManager.double_type || r == 
TypeManager.double_type) ||
+                       if (IsLogicalOperator (oper)) {
+                               if (l == TypeManager.decimal_type)
+                                       conv_left_as = TypeManager.bool_type;
+                               else if (r == TypeManager.decimal_type)
+                                       conv_right_as = TypeManager.bool_type;
+                               else 
+                                       return true;
+                       } else if ((l == TypeManager.double_type || r == 
TypeManager.double_type) ||
                            (oper == Operator.Division && 
                            !(l == TypeManager.decimal_type || r == 
TypeManager.decimal_type))) {
                                //
@@ -2096,6 +2101,16 @@
                                oper == Operator.Modulus);
                }
 
+               bool IsShiftOperator (Binary.Operator oper) {
+                       return (oper == Operator.LeftShift ||
+                               oper == Operator.RightShift);
+               }
+
+               bool IsLogicalOperator (Binary.Operator oper) {
+                       return (oper == Operator.LogicalOr ||
+                               oper == Operator.LogicalAnd);
+               }
+
                bool IsBitwiseOperator (Binary.Operator oper) {
                        return (oper == Operator.BitwiseOr ||
                                oper == Operator.BitwiseAnd ||
@@ -2130,11 +2145,6 @@
                                }
                        }
 
-                       if (oper == Operator.LogicalAnd) 
-                               oper = Operator.BitwiseAnd;
-                       if (oper == Operator.LogicalOr) 
-                               oper = Operator.BitwiseOr;
-
                        if (TypeManager.IsEnumType (l)) 
                                l = TypeManager.EnumToUnderlying (l);
                        if (TypeManager.IsEnumType (r)) 
@@ -2168,9 +2178,7 @@
                                l = left.Type;
                                r = right.Type;
 
-
                                if (l == TypeManager.object_type && r == 
TypeManager.object_type) {
-       
                                        string fqn = null;
                                        switch (oper) {
                                        case Operator.Addition :
@@ -2218,7 +2226,6 @@
                                                eclass = ExprClass.Value;
                                                type = TypeManager.bool_type;
                                                return this;
-                                               break;
                                        }
                        
                                        if (fqn == null) {
@@ -2357,6 +2364,8 @@
                                                conv_right_as = 
TypeManager.int32_type;
                                                type = TypeManager.int64_type;
        
+                                       } else if ( IsLogicalOperator (oper)) {
+                                               type = conv_right_as = 
conv_left_as = TypeManager.bool_type;
                                        } else if ( IsBitwiseOperator (oper)) {
        
                                                if (other_type == 
TypeManager.bool_type) {
@@ -2574,6 +2583,8 @@
                                }
                        }
 
+                       if (IsLogicalOperator (oper))
+                               type = TypeManager.bool_type;
                        if (IsBitwiseOperator (oper)) {
                                if (l == r) {
                                        if (l == TypeManager.byte_type ||
@@ -2637,7 +2648,8 @@
                        Type l = left.Type;
                        Expression etmp = ResolveOperator (ec);
                        // if the operands are of type byte/short, convert the 
result back to short/byte
-                       if (l == TypeManager.short_type || l == 
TypeManager.byte_type) {
+                       if ((l == TypeManager.short_type || l == 
TypeManager.byte_type) &&
+                           (IsArithmaticOperator (oper) || IsBitwiseOperator 
(oper) || IsShiftOperator (oper))) {
                                Expression conv_exp = ConvertImplicit (ec, 
etmp, left.Type, loc);
                                if (conv_exp != null)
                                        return conv_exp;
@@ -2785,6 +2797,7 @@
                {
                        ILGenerator ig = ec.ig;
                        Type l = left.Type;
+                       Type r = right.Type;
                        //Type r = right.Type;
                        OpCode opcode;
 
@@ -2810,25 +2823,59 @@
                        // Handle short-circuit operators differently
                        // than the rest
                        //
-                       if (oper == Operator.LogicalAnd){
+                       if (IsLogicalOperator (oper)) {
                                Label load_zero = ig.DefineLabel ();
+                               Label load_one = ig.DefineLabel ();
                                Label end = ig.DefineLabel ();
                                
                                left.Emit (ec);
-                               ig.Emit (OpCodes.Brfalse, load_zero);
+                               if (l != TypeManager.bool_type) {
+                                       if (l == TypeManager.int64_type) {
+                                               ec.ig.Emit (OpCodes.Ldc_I8, 0L);
+                                               ec.ig.Emit (OpCodes.Cgt_Un);
+                                       } else if (l == TypeManager.float_type) 
{
+                                               ec.ig.Emit (OpCodes.Ldc_R4, 
0.0F);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                       } else if (l == 
TypeManager.double_type) {
+                                               ec.ig.Emit (OpCodes.Ldc_R8, 
0.0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                       } else  {
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Cgt_Un);
+                                       }
+                               }
+                               if (oper == Operator.LogicalAnd) 
+                                       ig.Emit (OpCodes.Brfalse, load_zero);
+                               else 
+                                       ig.Emit (OpCodes.Brtrue, load_one);
+                               
                                right.Emit (ec);
-                               ig.Emit (OpCodes.Br, end);
+                               if (r != TypeManager.bool_type) {
+                                       if (r == TypeManager.int64_type) {
+                                               ec.ig.Emit (OpCodes.Ldc_I8, 0L);
+                                               ec.ig.Emit (OpCodes.Cgt_Un);
+                                       } else if (r == TypeManager.float_type) 
{
+                                               ec.ig.Emit (OpCodes.Ldc_R4, 
0.0F);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                       } else if (r == 
TypeManager.double_type) {
+                                               ec.ig.Emit (OpCodes.Ldc_R8, 
0.0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Ceq);
+                                       } else  {
+                                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                                               ec.ig.Emit (OpCodes.Cgt_Un);
+                                       }
+                               }
+                               ig.Emit (OpCodes.Brtrue, load_one);
                                ig.MarkLabel (load_zero);
                                ig.Emit (OpCodes.Ldc_I4_0);
-                               ig.MarkLabel (end);
-                               return;
-                       } else if (oper == Operator.LogicalOr){
-                               Label load_one = ig.DefineLabel ();
-                               Label end = ig.DefineLabel ();
-                               
-                               left.Emit (ec);
-                               ig.Emit (OpCodes.Brtrue, load_one);
-                               right.Emit (ec);
                                ig.Emit (OpCodes.Br, end);
                                ig.MarkLabel (load_one);
                                ig.Emit (OpCodes.Ldc_I4_1);

Modified: trunk/mcs/mbas/mb-parser.jay
===================================================================
--- trunk/mcs/mbas/mb-parser.jay        2005-03-10 02:14:31 UTC (rev 41626)
+++ trunk/mcs/mbas/mb-parser.jay        2005-03-10 04:07:51 UTC (rev 41627)
@@ -4596,7 +4596,7 @@
        : negation_expression
        | conditional_and_expression AND negation_expression
          {
-               $$ = new Binary (Binary.Operator.LogicalAnd,
+               $$ = new Binary (Binary.Operator.BitwiseAnd,
                                 (Expression) $1, (Expression) $3, 
lexer.Location);
          }
        | conditional_and_expression ANDALSO negation_expression
@@ -4610,7 +4610,7 @@
        : conditional_and_expression
        | conditional_or_expression OR conditional_and_expression
          {
-               $$ = new Binary (Binary.Operator.LogicalOr,
+               $$ = new Binary (Binary.Operator.BitwiseOr,
                                 (Expression) $1, (Expression) $3, 
lexer.Location);
          }
        | conditional_or_expression ORELSE conditional_and_expression

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to