Quellcode durchsuchen

2001-09-22 Ravi Pratap <[email protected]>

	* expression.cs (OverloadResolve): Improve some more to catch errors 1502 and 1503
	Also take an additional TypeContainer argument.

	* All over : Pass in TypeContainer as argument to OverloadResolve.

	* typemanager.cs (CSharpName): Update to check for the string type and return
	that too.

	* expression.cs (Invocation::FullMethodDesc): New static method to return a string fully describing
	a given method.

svn path=/trunk/mcs/; revision=925
Ravi Pratap M vor 24 Jahren
Ursprung
Commit
8ef4dc5111
4 geänderte Dateien mit 94 neuen und 14 gelöschten Zeilen
  1. 13 0
      mcs/mcs/ChangeLog
  2. 1 1
      mcs/mcs/class.cs
  3. 78 13
      mcs/mcs/expression.cs
  4. 2 0
      mcs/mcs/typemanager.cs

+ 13 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,16 @@
+2001-09-22  Ravi Pratap  <[email protected]>
+
+	* expression.cs (OverloadResolve): Improve some more to catch errors 1502 and 1503
+	Also take an additional TypeContainer argument.
+
+	* All over : Pass in TypeContainer as argument to OverloadResolve.
+
+	* typemanager.cs (CSharpName): Update to check for the string type and return
+	that too.
+
+	* expression.cs (Invocation::FullMethodDesc): New static method to return a string fully describing
+	a given method.
+	
 2001-09-21  Ravi Pratap  <[email protected]>
 
 	* expression.cs (Invocation::OverloadResolve): Re-write to conform more to the spec.

+ 1 - 1
mcs/mcs/class.cs

@@ -1052,7 +1052,7 @@ namespace CIR {
 			}
 			
 			parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (
-				(MethodGroupExpr) parent_constructor_group, argument_list);
+				(MethodGroupExpr) parent_constructor_group, argument_list, tc);
 			
 			if (parent_constructor == null)
 				return false;

+ 78 - 13
mcs/mcs/expression.cs

@@ -12,7 +12,8 @@ namespace CIR {
 	using System;
 	using System.Reflection;
 	using System.Reflection.Emit;
-
+	using System.Text;
+	
 	// <remarks>
 	//   The ExprClass class contains the is used to pass the 
 	//   classification of an expression (value, variable, namespace,
@@ -268,11 +269,10 @@ namespace CIR {
 		{
 			Type expr_type = expr.Type;
 
-			if (expr_type == target_type){
-				Console.WriteLine ("Hey, ConvertImplicit was called with no job to do");
+			if (expr_type == target_type)
 				return expr;
-			}
-
+			
+			
 			//
 			// Step 1: Perform implicit conversions as found on expr.Type
 			//
@@ -692,7 +692,7 @@ namespace CIR {
 				Arguments = new ArrayList ();
 				Arguments.Add (new Argument (expr, Argument.AType.Expression));
 				
-				method = Invocation.OverloadResolve ((MethodGroupExpr) mg, Arguments);
+				method = Invocation.OverloadResolve ((MethodGroupExpr) mg, Arguments, tc);
 				if (method != null)
 					return this;
 			}
@@ -1289,7 +1289,7 @@ namespace CIR {
 				Arguments.Add (new Argument (right, Argument.AType.Expression));
 
 			
-				method = Invocation.OverloadResolve (union, Arguments);
+				method = Invocation.OverloadResolve (union, Arguments, tc);
 				if (method != null) 
 					return this;
 			}
@@ -2195,7 +2195,7 @@ namespace CIR {
 						
 						if (x > 0)
 							continue;
-						else
+						else 
 							break;
 					}
 					
@@ -2234,6 +2234,23 @@ namespace CIR {
 				return 0;
 			
 		}
+
+		public static string FullMethodDesc (MethodBase mb)
+		{
+			StringBuilder sb = new StringBuilder (mb.Name);
+			ParameterData pd = GetParameterData (mb);
+			
+			sb.Append (" (");
+			for (int i = pd.Count; i > 0;) {
+				i--;
+				sb.Append (TypeManager.CSharpName (pd.ParameterType (i)));
+				if (i != 0)
+					sb.Append (",");
+			}
+			
+			sb.Append (")");
+			return sb.ToString ();
+		}
 		
 		// <summary>
 		//   Find the Applicable Function Members (7.4.2.1)
@@ -2248,12 +2265,13 @@ namespace CIR {
 		//            that is the best match of me on Arguments.
 		//
 		// </summary>
-		public static MethodBase OverloadResolve (MethodGroupExpr me, ArrayList Arguments)
+		public static MethodBase OverloadResolve (MethodGroupExpr me, ArrayList Arguments, TypeContainer tc)
 		{
 			ArrayList afm = new ArrayList ();
 			int best_match_idx = -1;
 			MethodBase method = null;
-
+			int argument_count;
+			
 			for (int i = me.Methods.Length; i > 0; ){
 				i--;
 				MethodBase candidate  = me.Methods [i];
@@ -2269,9 +2287,56 @@ namespace CIR {
 				}
 			}
 			
+			if (best_match_idx != -1)
+				return method;
+
+			// Now we see if we can at least find a method with the same number of arguments
+			// and then try doing implicit conversion on the arguments
+
+			if (Arguments == null)
+				argument_count = 0;
+			else
+				argument_count = Arguments.Count;
+
+			ParameterData pd = null;
+			
+			for (int i = me.Methods.Length; i > 0;) {
+				i--;
+				MethodBase mb = me.Methods [i];
+				pd = GetParameterData (mb);
+
+				if (pd.Count == argument_count) {
+					best_match_idx = i;
+					method = me.Methods [best_match_idx];
+					break;
+				} else
+					continue;
+			}
+
 			if (best_match_idx == -1)
 				return null;
 
+			// And now convert implicitly, each argument to the required type
+			
+			pd = GetParameterData (method);
+
+			for (int j = argument_count; j > 0;) {
+				j--;
+				Argument a = (Argument) Arguments [j];
+
+				Expression conv = ConvertImplicit (a.Expr, pd.ParameterType (j));
+
+				if (conv == null) {
+					tc.RootContext.Report.Error (1502,
+					       "The best overloaded match for method '" + FullMethodDesc (method) +
+					       "' has some invalid arguments");
+					tc.RootContext.Report.Error (1503, "Argument " + (j+1) +
+					       " : Cannot convert from '" + TypeManager.CSharpName (a.Expr.Type)
+					       + "' to '" + TypeManager.CSharpName (pd.ParameterType (j)) + "'");
+					return null;
+				}
+			}
+			
 			return method;
 		}
 
@@ -2304,11 +2369,11 @@ namespace CIR {
 				}
 			}
 
-			method = OverloadResolve ((MethodGroupExpr) this.expr, Arguments);
+			method = OverloadResolve ((MethodGroupExpr) this.expr, Arguments, tc);
 
 			if (method == null){
 				tc.RootContext.Report.Error (-6, Location,
-				"Figure out error: Can not find a good function for this argument list");
+				       "Could not find any applicable function for this argument list");
 				return null;
 			}
 
@@ -2439,7 +2504,7 @@ namespace CIR {
 				}
 			}
 
-			method = Invocation.OverloadResolve ((MethodGroupExpr) ml, Arguments);
+			method = Invocation.OverloadResolve ((MethodGroupExpr) ml, Arguments, tc);
 
 			if (method == null) {
 				tc.RootContext.Report.Error (-6,

+ 2 - 0
mcs/mcs/typemanager.cs

@@ -147,6 +147,8 @@ public class TypeManager {
 			return "byte";
 		else if (t == short_type)
 			return "short";
+		else if (t == System.Type.GetType ("System.String"))
+			return "string";
 		else
 			return t.FullName;
 	}