[m-rev.] [dotnet] diff: option handling

Peter Ross peter.ross at miscrit.be
Wed Apr 25 01:28:33 AEST 2001


Hi,


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


Estimated hours taken: 1

dotnet/intgen/reflect.cs:
    Add option handling code.
    The following options are now accepted:
        --types-only:   only output the foreign_type declarations.
        --type,-t:      only output data related to the specified type.


Index: reflect.cs
===================================================================
RCS file: /home/mercury1/repository/dotnet/intgen/reflect.cs,v
retrieving revision 1.12
diff -u -r1.12 reflect.cs
--- reflect.cs	2001/04/24 14:04:00	1.12
+++ reflect.cs	2001/04/24 15:22:31
@@ -12,19 +12,41 @@
 
 public static void Main(string[] args) {
 
-	if (args.Length > 0) {
-		Assembly asm = Assembly.Load(args[0]);
+	string	assembly_str = "";
+	string	type_str = "";
+	bool	types_only = false;
+
+	for (int i = 0; i < args.Length; i++) {
+		switch (args[i]) {
+		case "--types-only":
+			types_only = true;
+			break;
+
+		case "--type":
+		case "-t":
+			type_str = args[++i];
+			break;
+
+		default:
+			assembly_str = args[i];
+		}
+	}
+
+	if (assembly_str != "") {
+		Assembly asm = Assembly.Load(assembly_str);
 		Type[] types;
 
-		if (args.Length > 1) {
+		if (type_str != "") {
 			Type[] t = new Type[1];
-			t[0] = asm.GetType(args[1]);
+			t[0] = asm.GetType(type_str);
 			if (t[0] != null) {
 				types = t;
 			} else {
-				Console.WriteLine("Error: type not found.");
+				Console.WriteLine("Error: type '" + type_str +
+						"' not found.");
 				Console.WriteLine(
-					"Usage: reflect assembly [type]");
+					"Usage: reflect [--types-only] " +
+					"[--type type] assembly");
 
 				return;
 			}
@@ -32,16 +54,21 @@
 			types = asm.GetExportedTypes();
 		}
 
-		GenerateInterfaceForAssembly(asm, types, args[0]);
+		GenerateInterfaceForAssembly(asm, types,
+				assembly_str, types_only);
 
 	} else {
-		Console.WriteLine("Usage: reflect assembly [type]");
+		Console.WriteLine("Usage: reflect [--types-only]" +
+				" [--type type] assembly");
 		return;
 	}
 
 	return;
 }
 
+//---------------------------------------------------------------------------//
+
+
 	// :- module 'AssemblyName'
 	// :- include_module 'TypeName'.
 	// :- pragma foreign_type('TypeName',
@@ -61,7 +88,7 @@
 	// :- end_module 'AssemblyName__TypeName'.
 	// :- end_module 'AssemblyName'.
 public static void GenerateInterfaceForAssembly(Assembly asm, Type[] types,
-		string assemblyname)
+		string assemblyname, bool types_only)
 {
 	String module = assemblyname.Replace('.', '_') + "_mercury";
 
@@ -78,13 +105,15 @@
 	Console.WriteLine(":- interface.");
 
 	foreach (Type t in types) {
-		GeneratePragmaForeignType(t, assemblyname);
+		GeneratePragmaForeignType(t, assemblyname, types_only);
 	}
 
 	Console.WriteLine(":- implementation.");
 
-	foreach (Type t in types) {
-		GenerateInterfaceForType(t, assemblyname);
+	if (!types_only) {
+		foreach (Type t in types) {
+			GenerateInterfaceForType(t, assemblyname);
+		}
 	}
 
 	Console.Write(":- end_module '");
@@ -96,16 +125,19 @@
 //---------------------------------------------------------------------------//
 
 	// Output the pragma foreign_type declaration.
-public static void GeneratePragmaForeignType(Type t, string assemblyname)
+public static void GeneratePragmaForeignType(Type t, string assemblyname,
+		bool types_only)
 {
 	System.String module = "m" + t.Name.ToString();
 	System.String[] split_assembly_name;
 
 	split_assembly_name = t.FullName.Split(dotnet_seperator.ToCharArray());
 
-	Console.Write(":- include_module '");
-	Console.Write(module);
-	Console.WriteLine("'.");
+	if (!types_only) {
+		Console.Write(":- include_module '");
+		Console.Write(module);
+		Console.WriteLine("'.");
+	}
 
 	Console.Write(":- pragma foreign_type('");
 	Console.Write(t.FullName);

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