Author: sudha
Date: 2005-04-21 05:50:37 -0400 (Thu, 21 Apr 2005)
New Revision: 43386

Modified:
   trunk/mcs/mbas/ChangeLog
   trunk/mcs/mbas/ecore.cs
   trunk/mcs/mbas/expression.cs
   trunk/mcs/mbas/mb-parser.jay
   trunk/mcs/mbas/statement.cs
Log:
        * ecore.cs :
                Fixed object to bool/float/double conversions
                Fixed numeric <--> Enum conversions
        * statement.cs :
        * expression.cs :
        * mb-parser.jay :
                (Initial) Support for 'LateGet'



Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog    2005-04-21 08:39:59 UTC (rev 43385)
+++ trunk/mcs/mbas/ChangeLog    2005-04-21 09:50:37 UTC (rev 43386)
@@ -1,3 +1,11 @@
+2005-04-21 Satya Sudha K <[EMAIL PROTECTED]>
+       * ecore.cs :
+               Fixed object to bool/float/double conversions
+               Fixed numeric <--> Enum conversions 
+       * statement.cs :
+       * expression.cs :
+       * mb-parser.jay :
+               (Initial) Support for 'LateGet'
 
 2005-04-18 Manjula GHM <[EMAIL PROTECTED]>
        * mb-parser.jay:
@@ -2,3 +10,3 @@
                Support expressions for Directives
-2005-04-12 Satya Sudha K <[EMAIL PROTECTED]>
+2005-04-19 Satya Sudha K <[EMAIL PROTECTED]>
        * ecore.cs :

Modified: trunk/mcs/mbas/ecore.cs
===================================================================
--- trunk/mcs/mbas/ecore.cs     2005-04-21 08:39:59 UTC (rev 43385)
+++ trunk/mcs/mbas/ecore.cs     2005-04-21 09:50:37 UTC (rev 43386)
@@ -1757,7 +1757,7 @@
                        
                        if (e != null)
                                return e;
-                               
+
                        e = NarrowingConversion (ec, expr, target_type, loc);
                        if (e != null)
                                return e;                               
@@ -1805,7 +1805,16 @@
                static public bool NarrowingConversionExists (EmitContext ec, 
Expression expr, Type target_type)
                {
                        Type expr_type = expr.Type;
+                       if (expr_type.IsSubclassOf (TypeManager.enum_type))
+                               expr_type = TypeManager.EnumToUnderlying 
(expr_type);
+       
+                       if (target_type.IsSubclassOf (TypeManager.enum_type))
+                               target_type = TypeManager.EnumToUnderlying 
(target_type);
 
+
+                       if (expr_type == target_type)
+                               return true;
+
                        if (target_type == TypeManager.sbyte_type){
                                //
                                // To sbyte from short, int, long, float, 
double.
@@ -1920,6 +1929,15 @@
                {
                        Type expr_type = expr.Type;
 
+                       if (expr_type.IsSubclassOf (TypeManager.enum_type))
+                               expr_type = TypeManager.EnumToUnderlying 
(expr_type);
+       
+                       if (target_type.IsSubclassOf (TypeManager.enum_type))
+                               target_type = TypeManager.EnumToUnderlying 
(target_type);
+
+                       if (expr_type == target_type)
+                               return expr;
+
                        if (target_type == TypeManager.sbyte_type){
                                //
                                // To sbyte from short, int, long, float, 
double.
@@ -2216,6 +2234,16 @@
                                        // Ok, this *is* broken
                                        e = RTConversionExpression(ec, 
"ByteType.FromObject", expr, loc);
                                        break;  
+                               case TypeCode.Boolean:  
+                                       switch (src_type) {                     
                        
+                                               case TypeCode.String:           
                
+                                                       e = 
RTConversionExpression(ec, "BooleanType.FromString", expr, loc);
+                                                       break;          
+                                               case TypeCode.Object:           
                
+                                                       e = 
RTConversionExpression(ec, "BooleanType.FromObject", expr, loc);
+                                                       break;                  
                                                                
+                                       }
+                                       break;
                                case TypeCode.DateTime: 
                                        switch (src_type) {                     
                        
                                                case TypeCode.String:           
                
@@ -2299,6 +2327,10 @@
                                                                  Type 
target_type, Location loc)
                {
                        Type expr_type = expr.Type;
+
+                       if (expr_type.IsSubclassOf (TypeManager.enum_type))
+                               expr_type = TypeManager.EnumToUnderlying 
(expr_type);
+
                        Expression e;
 
                        if (expr is NullLiteral) {

Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs        2005-04-21 08:39:59 UTC (rev 43385)
+++ trunk/mcs/mbas/expression.cs        2005-04-21 09:50:37 UTC (rev 43386)
@@ -2615,6 +2615,13 @@
                        left = left.Resolve (ec);
                        right = right.Resolve (ec);
 
+                       if (left is Invocation) {
+                               ((Invocation) left).IsRetvalRequired = true;
+                       }
+                       if (right is Invocation) {
+                               ((Invocation) right).IsRetvalRequired = true;
+                       }
+
                        if (left == null || right == null)
                                return null;
 
@@ -3557,6 +3564,7 @@
                public Expression expr;
                MethodBase method = null;
                bool is_base;
+               bool is_latebinding;
                bool is_left_hand; // Needed for late bound calls
                bool is_retval_required; // Needed for late bound calls
                static Hashtable method_parameter_cache;
@@ -3578,6 +3586,7 @@
                {
                        this.expr = expr;
                        this.is_retval_required = false;
+                       this.is_left_hand = false;
                        Arguments = arguments;
                        loc = l;
                        CompareName = new MemberFilter (compare_name_filter);
@@ -3598,6 +3607,15 @@
                        }
                }
 
+               public bool IsLateBinding {
+                       get {
+                               return is_latebinding;
+                       }
+                       set {
+                               is_latebinding = value;
+                       }
+               }
+
                /// <summary>
                ///   Returns the Parameters (a ParameterData interface) for the
                ///   Method 'mb'
@@ -3855,12 +3873,13 @@
                                (a_mod == Parameter.Modifier.NONE && p_mod == 
Parameter.Modifier.PARAMS)) {
                                if (a_mod == Parameter.Modifier.NONE) {
                                        if (! WideningConversionExists (a.Expr, 
ptype) ) {
+
                                                if (! NarrowingConversionExists 
(ec, a.Expr, ptype) )
                                                        return 
ConversionType.None;
                                                else
                                                        return 
ConversionType.Narrowing;
                                        } else
-                                                       return 
ConversionType.Widening;
+                                               return ConversionType.Widening;
                                }
                                
                                if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
@@ -4422,8 +4441,11 @@
                                if (expr is MemberAccess) {
                                        MemberAccess m = expr as MemberAccess;
                                        if (m.Expr.Type == 
TypeManager.object_type) {
-                                               StatementSequence etmp = new 
StatementSequence (ec.CurrentBlock, loc, expr, Arguments);
+                                               StatementSequence etmp = new 
StatementSequence (ec.CurrentBlock, 
+                                                                               
loc, expr, Arguments, 
+                                                                               
is_retval_required, is_left_hand);
                                                
etmp.GenerateLateBindingStatements();
+                                               this.is_latebinding = true;
                                                return etmp.Resolve (ec);
                                        }
                                }
@@ -4886,8 +4908,9 @@
                        //
                        if (method is MethodInfo){
                                Type ret = ((MethodInfo)method).ReturnType;
-                               if (TypeManager.TypeToCoreType (ret) != 
TypeManager.void_type)
+                               if ((TypeManager.TypeToCoreType (ret) != 
TypeManager.void_type) && !this.is_latebinding) {
                                        ec.ig.Emit (OpCodes.Pop);
+                               }
                        }
                }
        }

Modified: trunk/mcs/mbas/mb-parser.jay
===================================================================
--- trunk/mcs/mbas/mb-parser.jay        2005-04-21 08:39:59 UTC (rev 43385)
+++ trunk/mcs/mbas/mb-parser.jay        2005-04-21 09:50:37 UTC (rev 43386)
@@ -276,7 +276,6 @@
                TokenizerController tokenizerController;
                IfElseStateMachine ifElseStateMachine;
 
-
                
                public class IfElseStateMachine {
                        
@@ -4363,11 +4362,15 @@
 argument
        : expression
          {
-               $$ = new Argument ((Expression) $1, Argument.AType.Expression);
+               Expression expr = (Expression) $1;
+               expr = SetValueRequiredFlag (expr);
+               $$ = new Argument (expr, Argument.AType.Expression);
          }
        | BYREF variable_reference
          {
-               $$ = new Argument ((Expression) $2, Argument.AType.Ref);
+               Expression expr = (Expression) $2;
+               expr = SetValueRequiredFlag (expr);
+               $$ = new Argument (expr, Argument.AType.Ref);
          }
        | /* empty */
          {
@@ -4375,7 +4378,9 @@
          }
        | ADDRESSOF expression
          {
-               $$ = new Argument ((Expression) $2, Argument.AType.AddressOf);
+               Expression expr = (Expression) $2;
+               expr = SetValueRequiredFlag (expr);
+               $$ = new Argument (expr, Argument.AType.AddressOf);
          }
        ;
 
@@ -4634,64 +4639,72 @@
 assignment_expression
        : prefixed_unary_expression ASSIGN _mark_ expression
          { 
-               $$ = new Assign ((Expression) $1, (Expression) $4, 
(Location)$3);
+               Expression expr = SetValueRequiredFlag ((Expression) $4);
+               $$ = new Assign ((Expression) $1, expr, (Location)$3);
          }
        | prefixed_unary_expression OP_EXP ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
 
                $$ = new CompoundAssign (
-                       Binary.Operator.Exponentiation, (Expression) $1, 
(Expression) $5, l);
+                       Binary.Operator.Exponentiation, (Expression) $1, expr, 
l);
          }
        | prefixed_unary_expression STAR ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
-
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.Multiply, (Expression) $1, (Expression) 
$5, l);
+                       Binary.Operator.Multiply, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression DIV ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
 
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.Division, (Expression) $1, (Expression) 
$5, l);
+                       Binary.Operator.Division, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression PLUS ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
 
                $$ = new CompoundAssign (
-                       Binary.Operator.Addition, (Expression) $1, (Expression) 
$5, l);
+                       Binary.Operator.Addition, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression MINUS ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
 
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.Subtraction, (Expression) $1, 
(Expression) $5, l);
+                       Binary.Operator.Subtraction, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression OP_SHIFT_LEFT ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
 
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.LeftShift, (Expression) $1, 
(Expression) $5, l);
+                       Binary.Operator.LeftShift, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression OP_SHIFT_RIGHT ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
 
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.RightShift, (Expression) $1, 
(Expression) $5, l);
+                       Binary.Operator.RightShift, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression OP_CONCAT ASSIGN _mark_ expression
          {
                Location l = (Location)$4;
 
                // FIXME should be strings only
+               Expression expr = SetValueRequiredFlag ((Expression) $5);
                $$ = new CompoundAssign (
-                       Binary.Operator.Addition, (Expression) $1, (Expression) 
$5, l);
+                       Binary.Operator.Addition, (Expression) $1, expr, l);
          }
        | prefixed_unary_expression ASSIGN ADDRESSOF _mark_ expression
          { 
@@ -4710,7 +4723,12 @@
        ;
 
 boolean_expression
-       : expression
+       : expression 
+        {
+               Expression expr = (Expression) $1;
+               expr = SetValueRequiredFlag (expr);
+               $$ = expr;
+        }
        ;
 
 type
@@ -4796,7 +4814,6 @@
         }
        ;       
                
-
 pp_directive
        : HASH IDENTIFIER OPEN_PARENS LITERAL_STRING COMMA LITERAL_INTEGER 
CLOSE_PARENS _mark_ EOL
          { 
@@ -5571,6 +5588,15 @@
        }
 }
 
+static Expression SetValueRequiredFlag (Expression expr) {
+       if (expr is Invocation) {
+               Invocation e = (Invocation) expr;
+               e.IsRetvalRequired = true;
+               expr = e;
+       }
+       return expr;
+}
+
 static bool AlwaysAccept (MemberInfo m, object filterCriteria) {
        return true;
 }

Modified: trunk/mcs/mbas/statement.cs
===================================================================
--- trunk/mcs/mbas/statement.cs 2005-04-21 08:39:59 UTC (rev 43385)
+++ trunk/mcs/mbas/statement.cs 2005-04-21 09:50:37 UTC (rev 43386)
@@ -615,7 +615,8 @@
                                ((ExpressionStatement) expr).EmitStatement (ec);
                        else {
                                expr.Emit (ec);
-                               ig.Emit (OpCodes.Pop);
+                               if (! (expr is StatementSequence))
+                                       ig.Emit (OpCodes.Pop);
                        }
 
                        return false;
@@ -3332,11 +3333,21 @@
                Block stmtBlock;
                ArrayList args;
                Expression expr;
+               bool isRetValRequired;
+               bool isLeftHandSide;
 
                public StatementSequence (Block parent, Location loc, 
Expression expr) 
                        : this (parent, loc, expr, null)
                { }
 
+               public StatementSequence (Block parent, Location loc, 
Expression expr, ArrayList a,
+                                         bool isRetValRequired, bool 
isLeftHandSide) 
+                       : this (parent, loc, expr, a)
+               {
+                       this.isRetValRequired = isRetValRequired;
+                       this.isLeftHandSide = isLeftHandSide;
+               }
+
                public StatementSequence (Block parent, Location loc, 
Expression expr, ArrayList a) 
                {
                        stmtBlock = new Block (parent);
@@ -3344,7 +3355,9 @@
                        this.expr = expr;
                        stmtBlock.IsLateBindingRequired = true;
                        this.loc = loc;
+                       this.isRetValRequired = this.isLeftHandSide = false;
                }
+
                public Block StmtBlock {
                        get {
                                return stmtBlock;
@@ -3422,8 +3435,18 @@
                                invocationArgs.Add (new Argument 
(NullLiteral.Null, Argument.AType.Expression));
                        }
 
-                       Expression etmp = Parser.DecomposeQI 
("Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall", loc);
+                       Expression etmp = null;
+                       if (isLeftHandSide) {
+                               // LateSet
+                       } else if (isRetValRequired) {
+                               // Late Get
+                               etmp = Parser.DecomposeQI 
("Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet", loc);
+                       }  else {
+                               etmp = Parser.DecomposeQI 
("Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall", loc);
+                       }
+
                        Invocation inv_stmt = new Invocation (etmp, 
invocationArgs, Location.Null);
+                       inv_stmt.IsLateBinding = true;
                        stmtBlock.AddStatement (new StatementExpression 
((ExpressionStatement) inv_stmt, loc));
 
                        for (int i = 0; i< argCount; i ++) {
@@ -3446,7 +3469,7 @@
                public override void Emit (EmitContext ec)
                {
                        stmtBlock.Emit (ec);
-                       ec.ig.Emit (OpCodes.Ldloc_0);
+                       //ec.ig.Emit (OpCodes.Ldloc_0);
                }
        }
 

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

Reply via email to