2002-03-13 Ravi Pratap <ravi@ximian.com>
authorRavi Pratap M <ravi@mono-cvs.ximian.com>
Wed, 13 Mar 2002 17:30:04 +0000 (17:30 -0000)
committerRavi Pratap M <ravi@mono-cvs.ximian.com>
Wed, 13 Mar 2002 17:30:04 +0000 (17:30 -0000)
* ecore.cs (StandardConversionExists): Modify to take an Expression
as the first parameter. Ensure we do null -> reference type conversion
checking.

* Everywhere : update calls accordingly, making use of MyEmptyExpr to store
temporary Expression objects.

svn path=/trunk/mcs/; revision=3087

mcs/mcs/ChangeLog
mcs/mcs/ecore.cs
mcs/mcs/expression.cs

index 69dd75129cb9b0e0f63097f205629c94b938da8c..09914a5dc3795e88a9fc3b00f4c6d005953910d6 100755 (executable)
@@ -1,3 +1,11 @@
+2002-03-13  Ravi Pratap  <ravi@ximian.com>
+
+       * ecore.cs (StandardConversionExists): Modify to take an Expression
+       as the first parameter. Ensure we do null -> reference type conversion
+       checking.
+
+       * Everywhere : update calls accordingly, making use of MyEmptyExpr to store
+       temporary Expression objects.
 
 Wed Mar 13 12:32:40 CET 2002 Paolo Molaro <lupus@ximian.com>
 
@@ -81,7 +89,6 @@ Wed Mar 13 12:32:40 CET 2002 Paolo Molaro <lupus@ximian.com>
        * attribute.cs (ApplyAttributes): Recognize the MarshalAs attribute 
        on parameters and accordingly set the marshalling info.
        
-
 2002-03-09  Miguel de Icaza  <miguel@ximian.com>
 
        * class.cs: Optimizing slightly by removing redundant code after
index 2ca8429c828857a10a83d9a2e77884accf9eaeee..c8f2b2d36f35767ecedc92c9f93bf5e1c191dca1 100755 (executable)
@@ -596,10 +596,15 @@ namespace Mono.CSharp {
                                        if (expr_type.GetArrayRank () == target_type.GetArrayRank ()) {
 
                                                Type expr_element_type = expr_type.GetElementType ();
+
+                                               if (MyEmptyExpr == null)
+                                                       MyEmptyExpr = new EmptyExpression ();
+                                               
+                                               MyEmptyExpr.SetType (expr_element_type);
                                                Type target_element_type = target_type.GetElementType ();
 
                                                if (!expr_element_type.IsValueType && !target_element_type.IsValueType)
-                                                       if (StandardConversionExists (expr_element_type,
+                                                       if (StandardConversionExists (MyEmptyExpr,
                                                                                      target_element_type))
                                                                return new EmptyCast (expr, target_type);
                                        }
@@ -831,8 +836,10 @@ namespace Mono.CSharp {
                ///  Determines if a standard implicit conversion exists from
                ///  expr_type to target_type
                /// </summary>
-               public static bool StandardConversionExists (Type expr_type, Type target_type)
+               public static bool StandardConversionExists (Expression expr, Type target_type)
                {
+                       Type expr_type = expr.Type;
+                       
                        if (expr_type == target_type)
                                return true;
 
@@ -953,7 +960,7 @@ namespace Mono.CSharp {
                                return true;
                                
                        } else {
-                               // Please remember that all code below actuall comes
+                               // Please remember that all code below actually comes
                                // from ImplicitReferenceConversion so make sure code remains in sync
                                
                                // from any class-type S to any interface-type T.
@@ -973,10 +980,15 @@ namespace Mono.CSharp {
                                        if (expr_type.GetArrayRank () == target_type.GetArrayRank ()) {
                                                
                                                Type expr_element_type = expr_type.GetElementType ();
+
+                                               if (MyEmptyExpr == null)
+                                                       MyEmptyExpr = new EmptyExpression ();
+                                               
+                                               MyEmptyExpr.SetType (expr_element_type);
                                                Type target_element_type = target_type.GetElementType ();
                                                
                                                if (!expr_element_type.IsValueType && !target_element_type.IsValueType)
-                                                       if (StandardConversionExists (expr_element_type,
+                                                       if (StandardConversionExists (MyEmptyExpr,
                                                                                      target_element_type))
                                                                return true;
                                        }
@@ -998,8 +1010,9 @@ namespace Mono.CSharp {
                                                return true;
                                
                                // from the null type to any reference-type.
-                               // FIXME : How do we do this ?
-
+                               if (expr is NullLiteral && !target_type.IsValueType)
+                                       return true;
+                               
                        }
 
                        return false;
@@ -1037,11 +1050,14 @@ namespace Mono.CSharp {
                                ParameterData pd = Invocation.GetParameterData (mb);
                                Type param_type = pd.ParameterType (0);
 
-                               if (StandardConversionExists (source_type, param_type)) {
+                               Expression source = new EmptyExpression (source_type);
+                               Expression param = new EmptyExpression (param_type);
+
+                               if (StandardConversionExists (source, param_type)) {
                                        if (best == null)
                                                best = param_type;
                                        
-                                       if (StandardConversionExists (param_type, best))
+                                       if (StandardConversionExists (param, best))
                                                best = param_type;
                                }
                        }
@@ -1063,12 +1079,14 @@ namespace Mono.CSharp {
                                
                                MethodInfo mi = (MethodInfo) me.Methods [i];
                                Type ret_type = mi.ReturnType;
+
+                               Expression ret = new EmptyExpression (ret_type);
                                
-                               if (StandardConversionExists (ret_type, target)) {
+                               if (StandardConversionExists (ret, target)) {
                                        if (best == null)
                                                best = ret_type;
 
-                                       if (!StandardConversionExists (ret_type, best))
+                                       if (!StandardConversionExists (ret, best))
                                                best = ret_type;
                                }
                                
index 87317c3d03514e065785765db7b6b645100bb3a2..fa83190ca50376947f89cd134f640cb285f3c0f0 100755 (executable)
@@ -2920,8 +2920,11 @@ namespace Mono.CSharp {
                                        return 0;
                        }
 
-                       if (StandardConversionExists (p, q) == true &&
-                           StandardConversionExists (q, p) == false)
+                       Expression p_tmp = new EmptyExpression (p);
+                       Expression q_tmp = new EmptyExpression (q);
+                       
+                       if (StandardConversionExists (p_tmp, q) == true &&
+                           StandardConversionExists (q_tmp, p) == false)
                                return 1;
 
                        if (p == TypeManager.sbyte_type)
@@ -3174,7 +3177,7 @@ namespace Mono.CSharp {
                                if (a_mod == p_mod) {
                                        
                                        if (a_mod == Parameter.Modifier.NONE)
-                                               if (!StandardConversionExists (a.Type, pd.ParameterType (i)))
+                                               if (!StandardConversionExists (a.Expr, pd.ParameterType (i)))
                                                        return false;
                                                                                
                                        if (a_mod == Parameter.Modifier.REF ||
@@ -3191,7 +3194,7 @@ namespace Mono.CSharp {
                        for (int i = pd_count - 1; i < arg_count; i++) {
                                Argument a = (Argument) arguments [i];
                                
-                               if (!StandardConversionExists (a.Type, element_type))
+                               if (!StandardConversionExists (a.Expr, element_type))
                                        return false;
                        }
                        
@@ -3229,7 +3232,7 @@ namespace Mono.CSharp {
                                if (a_mod == p_mod) {
                                        
                                        if (a_mod == Parameter.Modifier.NONE)
-                                               if (!StandardConversionExists (a.Type, pd.ParameterType (i)))
+                                               if (!StandardConversionExists (a.Expr, pd.ParameterType (i)))
                                                        return false;
                                        
                                        if (a_mod == Parameter.Modifier.REF ||
@@ -3331,10 +3334,10 @@ namespace Mono.CSharp {
                        // Now we see if we can at least find a method with the same number of arguments
                        //
                        ParameterData pd;
-                       int method_count = 0;
+                       int method_count = 0;
 
                        if (best_match_idx == -1) {
-                               
+
                                for (int i = me.Methods.Length; i > 0;) {
                                        i--;
                                        MethodBase mb = me.Methods [i];
@@ -3352,7 +3355,6 @@ namespace Mono.CSharp {
                        if (method == null)
                                return null;
 
-
                        //
                        // Now check that there are no ambiguities i.e the selected method
                        // should be better than all the others