[m-rev.] [dotnet] diff: output pragma foreign_type

Peter Ross peter.ross at miscrit.be
Tue Apr 10 19:17:31 AEST 2001


Hi,

This is the diff for a tool that Tyson and I are working on to
automatically generate an interface between .NET libraries and Mercury.


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


Estimated hours taken: 1

dotnet/intgen/reflect.cs:
    Generate the pragma foreign_type declaration.


Index: reflect.cs
===================================================================
RCS file: /home/mercury1/repository/dotnet/intgen/reflect.cs,v
retrieving revision 1.2
diff -u -r1.2 reflect.cs
--- reflect.cs	2001/04/10 08:10:40	1.2
+++ reflect.cs	2001/04/10 09:08:11
@@ -6,6 +6,8 @@
 public class MyReflect {
 
 static AssemblyName CurrentAssembly;
+const String mercury_seperator = "__";
+const String dotnet_seperator = ".";
 
 public static void Main(string[] args) {
 
@@ -30,15 +32,16 @@
 
 
 	if (typename == "") {
+            // XXX Should we only loop over the exported types!
 		Type[] types = asm.GetTypes();
 
 		foreach (Type t in types) {
-			GenerateInterfaceForType(t);
+			GenerateInterfaceForType(t, assemblyname);
 		}
 	} else {
 		Type type = asm.GetType(typename);
 		if (type != null) {
-			GenerateInterfaceForType(type);
+			GenerateInterfaceForType(type, assemblyname);
 		} else {
 			Console.WriteLine("Error: type not found.");
 			Console.WriteLine("Usage: reflect assembly [type]");
@@ -65,7 +68,8 @@
 	// ].
 	// :- end_module 'TypeName'.
 
-public static void GenerateInterfaceForType(Type t) {
+public static void GenerateInterfaceForType(Type t, string assemblyname) {
+
 	Console.Write("\t% type " + t.FullName + "\n");
 
 	Console.Write(":- module '");
@@ -76,6 +80,8 @@
 
 	Console.WriteLine("\n:- interface.\n");
 	
+	GeneratePragmaForeignType(t, assemblyname);
+
 	foreach (MemberInfo m in members) {
 		GenerateInterfaceForMember(m);
 		Console.WriteLine();
@@ -84,6 +90,26 @@
 	Console.WriteLine("\n:- implementation.\n");
 
 
+}
+
+	// Output the pragma foreign_type declaration.
+public static void GeneratePragmaForeignType(Type t, string assemblyname)
+{
+	System.String[] split_assembly_name;
+
+	split_assembly_name = t.FullName.Split(dotnet_seperator.ToCharArray());
+
+	Console.Write(":- pragma foreign_type('");
+	Console.Write(t.FullName);
+	Console.Write("', '");
+	Console.Write(split_assembly_name[0]);
+	for (int i = 1; i < split_assembly_name.Length; i++) {
+		Console.Write(mercury_seperator);
+		Console.Write(split_assembly_name[i]);
+	}
+	Console.Write("', \"");
+	Console.Write(assemblyname);
+	Console.WriteLine("\").");
 }
 
 public static void GenerateInterfaceForMember(MemberInfo m) {

--------------------------------------------------------------------------
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