[m-rev.] [dotnet] diff: get namespaces working better

Tyson Dowd trd at cs.mu.OZ.AU
Thu Apr 12 00:54:49 AEST 2001


Hi,

This change is just for the dotnet-foreign branch at the moment.

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


Estimated hours taken: 2
Branches: dotnet-foreign

compiler/ilasm.m:
compiler/ilds.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
    Handle submodules better by putting a .namespace around the
    generated class. 
    Also handle submodule assembly references properly by generating
    the assembly name of a namespace properly.
    Comment out the handling of namespaces at the MC++ level -- this is
    causing some problems and isn't really buying us much at the moment.

    (still to do on this change is get the external assembly references
    generated correctly for the case where a submodule contains c_code).
    


Index: ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.5.4.2
diff -u -r1.5.4.2 ilasm.m
--- ilasm.m	2001/04/11 10:09:05	1.5.4.2
+++ ilasm.m	2001/04/11 14:31:46
@@ -309,11 +309,15 @@
 	ilasm__write_list(Contents, "\n", output_classdecl, Info2, Info),
 	io__write_string("\n}").
 ilasm__output_decl(namespace(DottedName, Contents), Info0, Info) --> 
-	io__write_string(".namespace "),
-	output_dotted_name(DottedName),
-	io__write_string(" {\n"),
-	output(Contents, Info0, Info),
-	io__write_string("}\n").
+	( { DottedName \= [] } ->
+		io__write_string(".namespace "),
+		output_dotted_name(DottedName),
+		io__write_string(" {\n"),
+		output(Contents, Info0, Info),
+		io__write_string("}\n")
+	;
+		output(Contents, Info0, Info)
+	).
 ilasm__output_decl(method(MethodHead, MethodDecls), Info0, Info) --> 
 	io__write_string(".method "),
 	output_methodhead(MethodHead, Info0, Info1),
Index: ilds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilds.m,v
retrieving revision 1.2.4.1
diff -u -r1.2.4.1 ilds.m
--- ilds.m	2001/04/11 10:09:06	1.2.4.1
+++ ilds.m	2001/04/11 14:31:47
@@ -340,6 +340,10 @@
 
 :- func get_class_namespace(ilds__class_name) = ilds__namespace_qual_name.
 
+	% Get the non-namespace portion of a class name.
+
+:- func get_class_suffix(ilds__class_name) = ilds__id.
+
 	% Add an extra identifier to the end of an IL class name, e.g.
 	% append Foo to [mercury]mercury.runtime to make
 	% [mercury]mercury.runtime.Foo
@@ -351,6 +355,16 @@
 
 :- import_module error_util.
 
+get_class_suffix(structured_name(_, FullName)) = SuffixName :-
+	( 
+		list__last(FullName, Last)
+	->
+		SuffixName = Last
+	;
+			% This class has no name whatsoever.
+		unexpected(this_file, "get_class_namespace: class has no name")
+	).
+
 get_class_namespace(structured_name(_, FullName)) = NamespaceName :-
 	( 
 		list__last(FullName, Last),
@@ -359,7 +373,7 @@
 		NamespaceName0 = NamespaceName
 	;
 			% This class has no name whatsoever.
-		unexpected(this_file, "get_class_namespace: list__drop failed")
+		unexpected(this_file, "get_class_namespace: class has no name")
 	).
 
 append_class_name(structured_name(Assembly, ClassName), ExtraClass) =
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.15.4.5
diff -u -r1.15.4.5 mlds_to_il.m
--- mlds_to_il.m	2001/04/11 11:16:13	1.15.4.5
+++ mlds_to_il.m	2001/04/11 14:31:49
@@ -233,15 +233,21 @@
 		% The declarations in this class.
 	MethodDecls = [AllocDoneField, CCtor | ClassDecls],
 
+	SimpleClassName = get_class_suffix(ClassName),
+	NamespaceName = get_class_namespace(ClassName),
+
 		% The class that corresponds to this MLDS module.
-	MainClass = [class([public], AssemblyName, extends_nothing,
+	MainClass = [class([public], SimpleClassName, extends_nothing,
 			implements([]), MethodDecls)],
+	MainNamespace = [namespace(NamespaceName, MainClass)],
 
 		% A namespace to contain all the other declarations that
-		% are created as a result of this MLDS code.
-	MainNamespace = [namespace([AssemblyName], OtherDecls)],
+		% are created as a result of this MLDS code (currently
+		% this is not much).
+	OtherNamespace = [namespace([AssemblyName], OtherDecls)],
 	ILAsm = list__condense(
-		[ExternAssemblies, ThisAssembly, MainClass, MainNamespace]).
+		[ExternAssemblies, ThisAssembly, MainNamespace,
+			OtherNamespace]).
 
 %-----------------------------------------------------------------------------
 
@@ -2049,10 +2055,12 @@
 		structured_name(AssemblyName, ClassName) :-
 	SymName = mlds_module_name_to_sym_name(MldsModuleName),
 	sym_name_to_class_name(SymName, ClassName),
-	( ClassName = [A0 | _] ->
-		AssemblyName = A0
+	( 
+		ClassName = ["mercury", _]
+	->
+		AssemblyName = "mercury"
 	;
-		AssemblyName = ""
+		mlds_to_il__sym_name_to_string(SymName, AssemblyName)
 	).
 
 :- pred sym_name_to_class_name(sym_name, list(ilds__id)).
Index: mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.8.4.4
diff -u -r1.8.4.4 mlds_to_ilasm.m
--- mlds_to_ilasm.m	2001/04/11 11:16:14	1.8.4.4
+++ mlds_to_ilasm.m	2001/04/11 14:31:50
@@ -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,12 +199,12 @@
 	generate_foreign_header_code(mercury_module_name_to_mlds(ModuleName),
 		ForeignCode),
 
-	{ Namespace = get_class_namespace(ClassName) },
+%	{ Namespace = get_class_namespace(ClassName) },
 
-	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 ",
@@ -228,10 +228,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