[m-rev.] [dotnet] diff: fix namespaces bugs.

Tyson Dowd trd at cs.mu.OZ.AU
Fri Apr 13 17:46:00 AEST 2001


Hi,

Pete and I worked on this solution together, although Pete was the one
who found my stupid bug and actually wrote this code.  This code remains
largely untested, but since I am without a network connected windows box, 
it will be easier to test it if I check it in now.

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


Estimated hours taken: 1
Branches: dotnet-foreign

compiler/mlds_to_il.m:
	In the module foo.m, all the code is now placed into a type called
	mercury_code in the namespace foo, rather then in they type foo and
	no namespace.  This avoids problems where you cannot have a type and
	namespace at the top level with the same name.                              
	Also fix a bug where we matching on a list of length two rather then
	the first element of the list.        

compiler/mlds_to_ilasm.m:
	Reenable the namespace support for the MC++ code.
	Note that we need to generate code like
	namespace parent {
	  namespace child__c_code {
	    __gc public class mercury_code {
	    }
	  }
	}
	to match up with the convention currently output by mlds_to_il
	for calls to these predicates.


Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.15.4.7
diff -u -r1.15.4.7 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/04/11 14:54:33	1.15.4.7
+++ compiler/mlds_to_il.m	2001/04/12 15:49:19
@@ -2056,7 +2056,7 @@
 	SymName = mlds_module_name_to_sym_name(MldsModuleName),
 	sym_name_to_class_name(SymName, ClassName),
 	( 
-		ClassName = ["mercury", _]
+		ClassName = ["mercury" | _]
 	->
 		AssemblyName = "mercury"
 	;
@@ -2067,7 +2067,7 @@
 :- mode sym_name_to_class_name(in, out) is det.
 sym_name_to_class_name(SymName, Ids) :-
 	sym_name_to_class_name_2(SymName, Ids0),
-	list__reverse(Ids0, Ids).
+	list__reverse(["mercury_code" | Ids0], Ids).
 
 :- pred sym_name_to_class_name_2(sym_name, list(ilds__id)).
 :- mode sym_name_to_class_name_2(in, out) is det.
Index: compiler/mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.8.4.5
diff -u -r1.8.4.5 mlds_to_ilasm.m
--- compiler/mlds_to_ilasm.m	2001/04/11 14:37:39	1.8.4.5
+++ compiler/mlds_to_ilasm.m	2001/04/12 15:49:31
@@ -172,8 +172,8 @@
 
 	{ MLDS = mlds(ModuleName, ForeignCode, _Imports, Defns) },
 	{ prog_out__sym_name_to_string(ModuleName, ModuleNameStr) },
-%	{ ClassName = mlds_module_name_to_class_name(
-%		mercury_module_name_to_mlds(ModuleName)) },
+	{ ClassName = mlds_module_name_to_class_name(
+		mercury_module_name_to_mlds(ModuleName)) },
 
 	io__nl,
 	io__write_strings([
@@ -199,17 +199,22 @@
 	generate_foreign_header_code(mercury_module_name_to_mlds(ModuleName),
 		ForeignCode),
 
-%	{ Namespace = get_class_namespace(ClassName) },
+	{ Namespace0 = get_class_namespace(ClassName) },
+	{ list__reverse(Namespace0) = [Head | Tail] ->
+		Namespace = list__reverse([Head ++ "__c_code" | Tail])
+	;
+		Namespace = Namespace0
+	},
+
+	io__write_list(Namespace, "\n", 
+		(pred(N::in, di, uo) is det -->
+			io__format("namespace %s {", [s(N)])
+	)),
 
-%	io__write_list(Namespace, "\n", 
-%		(pred(N::in, di, uo) is det -->
-%			io__format("namespace %s {", [s(N)])
-%	)),
-
 	io__write_strings([
-		"\n__gc public class ",
-			string__replace_all(ModuleNameStr, ":", "__"),
-			"__c_code\n",
+		"\n__gc public class mercury_code",
+			% string__replace_all(ModuleNameStr, ":", "__"),
+			% "__c_code\n",
 		"{\n",
 		"public:\n"]),
 
@@ -228,10 +233,10 @@
 	io__write_string("};\n"),
 
 		% Close the namespace braces.
-%	io__write_list(Namespace, "\n", 
-%		(pred(_N::in, di, uo) is det -->
-%			io__write_string("}")
-%	)),
+	io__write_list(Namespace, "\n", 
+		(pred(_N::in, di, uo) is det -->
+			io__write_string("}")
+	)),
 
 
 	io__nl.


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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