[m-rev.] [dotnet] diff: support instance methods

Peter Ross peter.ross at miscrit.be
Wed Apr 25 00:05:29 AEST 2001


Hi,


===================================================================


Estimated hours taken: 4

dotnet/intgen/reflect.cs:
    Generate code for instance (non-static) methods.


Diff with -b:
Index: reflect.cs
===================================================================
RCS file: /home/mercury1/repository/dotnet/intgen/reflect.cs,v
retrieving revision 1.11
diff -u -b -r1.11 reflect.cs
--- reflect.cs	2001/04/22 15:29:51	1.11
+++ reflect.cs	2001/04/24 14:02:53
@@ -259,7 +259,7 @@
 	ParameterInfo[] parameters = c.GetParameters();
 
 	Console.Write(":- impure func 'new'");
-	OutputTypeModeParameters(parameters);
+	OutputTypeModeParameters(null, parameters);
 	Console.Write(" = (");
 	OutputTypeNameAsMercuryType(t);
 	Console.Write("::out)");
@@ -276,7 +276,7 @@
 	ParameterInfo[] parameters = c.GetParameters();
 
 	Console.Write(":- pragma foreign_code(\"MC++\", new");
-	OutputNameModeParameters(parameters);
+	OutputNameModeParameters(null, parameters);
 	Console.WriteLine(" = (Object::out),");
 	Console.WriteLine("\t\t[will_not_call_mercury, thread_safe], \"");
 
@@ -311,14 +311,17 @@
 	}
 	ParameterInfo[] parameters = m.GetParameters();
 
-	if (m.IsStatic) {
 		if (is_pred) {
 			Console.Write(":- pred '" + m.Name + "'");
 		} else {
 			Console.Write(":- func '" + m.Name + "'");
 		}
 
-		OutputTypeModeParameters(parameters);
+	if (m.IsStatic) {
+		OutputTypeModeParameters(null, parameters);
+	} else {
+		OutputTypeModeParameters(m.ReflectedType, parameters);
+	}
 
 		if (is_pred) {
 			// don't do anything here.
@@ -328,10 +331,6 @@
 			Console.Write("::out)");
 		}
 		Console.WriteLine(" is det.");
-	} else {
-		Console.WriteLine("% XXX instance methods unimplemented.");
-	}
-		
 }
 
 public static void GenerateImplementationForMethod(Type t,
@@ -346,28 +345,38 @@
 	System.String[] split_type_name;
 	split_type_name = t.FullName.Split(dotnet_seperator.ToCharArray());
 
-	if (m.IsStatic) {
+	Console.Write(":- pragma foreign_code(\"MC++\", '" + m.Name + "'");
 
-		Console.Write(
-			":- pragma foreign_code(\"MC++\", '" + m.Name + "'");
-		OutputNameModeParameters(parameters);
+	if (m.IsStatic) {
+		OutputNameModeParameters(null, parameters);
+	} else {
+		OutputNameModeParameters(m.ReflectedType, parameters);
+	}
 
 		if (!is_pred) {
-			Console.WriteLine(" = (Result::out),");
+		Console.Write(" = (Result::out)");
 		}
+	Console.WriteLine(",");
 
 		Console.WriteLine("\t\t[will_not_call_mercury, thread_safe], \"");
 
+	Console.Write("\t");
+
 		if (!is_pred) {
-			Console.Write("\tResult = ");
+		Console.Write("Result = ");
 		}
 
+	if (m.IsStatic) {
 		Console.Write(split_type_name[0]);
 		for (int i = 1; i < split_type_name.Length; i++) {
 			Console.Write(cpp_seperator);
 			Console.Write(split_type_name[i]);
 		}
 		Console.Write(cpp_seperator);
+	} else {
+		Console.Write("Object->");
+	}
+
 		Console.Write(m.Name);
 		
 		OutputNameParameters(parameters);
@@ -375,11 +384,6 @@
 		OutputByrefAssigments(parameters);
 
 	Console.WriteLine("\").");
-
-
-	} else {
-		Console.WriteLine("% XXX instance methods unimplemented.");
-	}
 }
 
 
@@ -486,11 +490,25 @@
 	}
 	Console.Write(")");
 }
+
+public static void OutputNameModeParameters(Type type,
+		ParameterInfo[] parameters) {
+
+	if (parameters.Length > 0 || type != null) {
+		Console.Write("(");
+	}
 
-public static void OutputNameModeParameters(ParameterInfo[] parameters) {
+	if (type != null)
+	{
+		Console.Write("Object::in");
+
+		if (parameters.Length > 0) {
+			Console.Write(", ");
+		}
+	}
+
 	if (parameters.Length > 0) {
 		int i;
-		Console.Write("(");
 		
 		OutputParameterAsNameMode(parameters[0]);
 		for (i = 1; i < parameters.Length; i++) {
@@ -498,21 +516,41 @@
 				OutputParameterAsNameMode(
 				parameters[i]);
 		}
+	}
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write(")");
 	}
 }
 
 
-public static void OutputTypeModeParameters(ParameterInfo[] parameters) {
-	if (parameters.Length > 0) {
-		int i;
+public static void OutputTypeModeParameters(Type type,
+		ParameterInfo[] parameters) {
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write("(");
+	}
+
+	if (type != null)
+	{
+		OutputTypeNameAsMercuryType(type);
+		Console.Write("::in");
 		
+		if (parameters.Length > 0) {
+			Console.Write(", ");
+		}
+	}
+		
+	if (parameters.Length > 0) {
+		int i;
 		OutputParameterAsTypeMode(parameters[0]);
 		for (i = 1; i < parameters.Length; i++) {
 			Console.Write(", ");
 			OutputParameterAsTypeMode(parameters[i]);
 		}
+	}
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write(")");
 	}
 }

Diff
Index: reflect.cs
===================================================================
RCS file: /home/mercury1/repository/dotnet/intgen/reflect.cs,v
retrieving revision 1.11
diff -u -r1.11 reflect.cs
--- reflect.cs	2001/04/22 15:29:51	1.11
+++ reflect.cs	2001/04/24 13:59:11
@@ -259,7 +259,7 @@
 	ParameterInfo[] parameters = c.GetParameters();
 
 	Console.Write(":- impure func 'new'");
-	OutputTypeModeParameters(parameters);
+	OutputTypeModeParameters(null, parameters);
 	Console.Write(" = (");
 	OutputTypeNameAsMercuryType(t);
 	Console.Write("::out)");
@@ -276,7 +276,7 @@
 	ParameterInfo[] parameters = c.GetParameters();
 
 	Console.Write(":- pragma foreign_code(\"MC++\", new");
-	OutputNameModeParameters(parameters);
+	OutputNameModeParameters(null, parameters);
 	Console.WriteLine(" = (Object::out),");
 	Console.WriteLine("\t\t[will_not_call_mercury, thread_safe], \"");
 
@@ -311,27 +311,26 @@
 	}
 	ParameterInfo[] parameters = m.GetParameters();
 
+	if (is_pred) {
+		Console.Write(":- pred '" + m.Name + "'");
+	} else {
+		Console.Write(":- func '" + m.Name + "'");
+	}
+
 	if (m.IsStatic) {
-		if (is_pred) {
-			Console.Write(":- pred '" + m.Name + "'");
-		} else {
-			Console.Write(":- func '" + m.Name + "'");
-		}
-
-		OutputTypeModeParameters(parameters);
-
-		if (is_pred) {
-			// don't do anything here.
-		} else {
-			Console.Write(" = (");
-			OutputTypeNameAsMercuryType(returntype);
-			Console.Write("::out)");
-		}
-		Console.WriteLine(" is det.");
+		OutputTypeModeParameters(null, parameters);
 	} else {
-		Console.WriteLine("% XXX instance methods unimplemented.");
+		OutputTypeModeParameters(m.ReflectedType, parameters);
 	}
-		
+
+	if (is_pred) {
+		// don't do anything here.
+	} else {
+		Console.Write(" = (");
+		OutputTypeNameAsMercuryType(returntype);
+		Console.Write("::out)");
+	}
+	Console.WriteLine(" is det.");
 }
 
 public static void GenerateImplementationForMethod(Type t,
@@ -346,40 +345,45 @@
 	System.String[] split_type_name;
 	split_type_name = t.FullName.Split(dotnet_seperator.ToCharArray());
 
+	Console.Write(":- pragma foreign_code(\"MC++\", '" + m.Name + "'");
+
 	if (m.IsStatic) {
+		OutputNameModeParameters(null, parameters);
+	} else {
+		OutputNameModeParameters(m.ReflectedType, parameters);
+	}
 
-		Console.Write(
-			":- pragma foreign_code(\"MC++\", '" + m.Name + "'");
-		OutputNameModeParameters(parameters);
+	if (!is_pred) {
+		Console.Write(" = (Result::out)");
+	}
+	Console.WriteLine(",");
 
-		if (!is_pred) {
-			Console.WriteLine(" = (Result::out),");
-		}
+	Console.WriteLine("\t\t[will_not_call_mercury, thread_safe], \"");
 
-		Console.WriteLine("\t\t[will_not_call_mercury, thread_safe], \"");
+	Console.Write("\t");
 
-		if (!is_pred) {
-			Console.Write("\tResult = ");
-		}
+	if (!is_pred) {
+		Console.Write("Result = ");
+	}
 
+	if (m.IsStatic) {
 		Console.Write(split_type_name[0]);
 		for (int i = 1; i < split_type_name.Length; i++) {
 			Console.Write(cpp_seperator);
 			Console.Write(split_type_name[i]);
 		}
 		Console.Write(cpp_seperator);
-		Console.Write(m.Name);
-		
-		OutputNameParameters(parameters);
-		Console.WriteLine(";");
-		OutputByrefAssigments(parameters);
+	} else {
+		Console.Write("Object->");
+	}
 
-	Console.WriteLine("\").");
+	Console.Write(m.Name);
 
+	OutputNameParameters(parameters);
+	Console.WriteLine(";");
+	OutputByrefAssigments(parameters);
 
-	} else {
-		Console.WriteLine("% XXX instance methods unimplemented.");
-	}
+	Console.WriteLine("\").");
 }
 
 
@@ -487,32 +491,66 @@
 	Console.Write(")");
 }
 
-public static void OutputNameModeParameters(ParameterInfo[] parameters) {
+public static void OutputNameModeParameters(Type type,
+		ParameterInfo[] parameters) {
+
+	if (parameters.Length > 0 || type != null) {
+		Console.Write("(");
+	}
+
+	if (type != null)
+	{
+		Console.Write("Object::in");
+
+		if (parameters.Length > 0) {
+			Console.Write(", ");
+		}
+	}
+
 	if (parameters.Length > 0) {
 		int i;
-		Console.Write("(");
-		
+
 		OutputParameterAsNameMode(parameters[0]);
 		for (i = 1; i < parameters.Length; i++) {
 			Console.Write(", ");
 				OutputParameterAsNameMode(
 				parameters[i]);
 		}
+	}
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write(")");
 	}
 }
 
 
-public static void OutputTypeModeParameters(ParameterInfo[] parameters) {
-	if (parameters.Length > 0) {
-		int i;
+public static void OutputTypeModeParameters(Type type,
+		ParameterInfo[] parameters) {
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write("(");
+	}
+
+	if (type != null)
+	{
+		OutputTypeNameAsMercuryType(type);
+		Console.Write("::in");
+
+		if (parameters.Length > 0) {
+			Console.Write(", ");
+		}
+	}
 		
+	if (parameters.Length > 0) {
+		int i;
 		OutputParameterAsTypeMode(parameters[0]);
 		for (i = 1; i < parameters.Length; i++) {
 			Console.Write(", ");
 			OutputParameterAsTypeMode(parameters[i]);
 		}
+	}
+
+	if (parameters.Length > 0 || type != null) {
 		Console.Write(")");
 	}
 }

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list