[m-rev.] uppercase Java type names

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Aug 2 18:27:54 AEST 2004


Estimated hours taken: 24
Branches: main

Some work towards getting the "browser" directory to build in grade java.

In particular, this is a step towards fixing a problem in the Java
back-end with sub-modules.  When compiling code that uses sub-modules,
we run up against a Java restriction that a class which is in a package
is not allowed to have the same name as the package.  The work-around
is to use names starting with an uppercase letter for Java class names,
and names starting with a lower-case letter for Java package names.

XXX This diff is a partial step: it uses names starting with an
uppercase letter for Java class names that correspond to Mercury types.
It does not yet use an uppercase letter for Java classes that correspond
to Mercury modules.

XXX With this diff, we just flip the case of the initial letter,
which just works around the problem by avoiding the clashing cases,
rather than eliminating them.  We should use a more complicated mangling
that eliminates the problem completely, e.g. map lowercase Mercury names
to uppercase, map uppercase Mercury names to "U_" followed by the name.

compiler/mlds_to_java.m:
	Output type names with an initial uppercase letter.

compiler/mlds.m:
	Add a new enumeration type qual_kind, with values type_qual
	and module_qual.
	Add a qual_kind field to the fully_qualified_type type.
	Add a qual_kind argument to the append_class_qualifier function,
	and if the qual_kind is module_qual, adjust the case of the
	qualifier appropriately for the back-end.

compiler/ml*.m:
compiler/rtti_to_mlds.m:
	Fill in the new qual_kind field, and pass qual_kind to
	append_class_qualifier.

library/builtin.m:
library/private_builtin.m:
library/type_desc.m:
library/io.m:
library/rtti_implementation.m:
	Use type names with an initial uppercase letter.

browser/Mmakefile:
	Work around problems where Java compilers don't like the file names
	generated by mmc for code using sub-modules.

	For IL and Java, build with --allow-stubs --no-warn-stubs.

browser/declarative_execution.m:
	Give a Java definition for the "proc_layout" type.
	This is needed to avoid compilation errors in grade java.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: browser/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/Mmakefile,v
retrieving revision 1.39
diff -u -d -r1.39 Mmakefile
--- browser/Mmakefile	17 Feb 2004 23:44:52 -0000	1.39
+++ browser/Mmakefile	2 Aug 2004 07:51:52 -0000
@@ -58,12 +58,24 @@
 MLLIBS +=	$(SOCKET_LIBRARY) $(NSL_LIBRARY) $(DL_LIBRARY)	\
 		$(READLINE_LIBRARIES)
 
+JAVACFLAGS = -classpath $(LIBRARY_DIR)
+
 MTAGS	=	$(SCRIPTS_DIR)/mtags
 
 LN	=	ln
 
 #-----------------------------------------------------------------------------#
 
+# The IL and Java implementations of the standard library are not yet complete,
+# so we need to pass `--allow-stubs' to get them to compile.
+# Since the standard library is compiled with `--halt-at-warn',
+# we also need `--no-warn-stubs'.
+ifneq ("$(filter il% java%,$(GRADE))","")
+MCFLAGS += --allow-stubs --no-warn-stubs
+endif
+
+#-----------------------------------------------------------------------------#
+
 # Stuff for Windows DLLS using gnu-win32
 
 ifeq ($(USE_DLLS),yes)
@@ -183,6 +195,39 @@
 .PHONY: dates
 dates:
 	touch $($(BROWSER_LIB_NAME).dates) $($(MDBCOMP_LIB_NAME).dates)
+
+#-----------------------------------------------------------------------------#
+
+#
+# Some Java compilers require the Java source files to be put in directories
+# which match their package names.  But the Mercury compiler generates them
+# with the package name prefixed to the file name with a ".", not a "/".
+# So we copy the Java source files to where the Java compiler expects them to be.
+#
+# XXX This is a hack.  We ought to change the Mercury compiler so that it generates
+# the Java files with the right names in the first place.
+#
+
+mdb/%.java: mdb.%.java
+	[ -d mdb ] || mkdir mdb
+	cp $< $@
+
+mdbcomp/%.java: mdbcomp.%.java
+	[ -d mdbcomp ] || mkdir mdbcomp
+	cp $< $@
+
+RENAMED_JAVAS = $($(BROWSER_LIB_NAME).javas:mdb.%.java=mdb/%.java) \
+	$($(MDBCOMP_LIB_NAME).javas:mdbcomp.%.java=mdbcomp/%.java)
+
+RENAMED_CLASSES = $($(BROWSER_LIB_NAME).classes:mdb.%.class=mdb/%.class) \
+	$($(MDBCOMP_LIB_NAME).classes:mdbcomp.%.class=mdbcomp/%.class)
+
+.PHONY: javas
+javas: $(RENAMED_JAVAS)
+
+.PHONY: classes
+classes: $(RENAMED_JAVAS)
+	$(JAVAC) $(ALL_JAVACFLAGS) -d $(classes_subdir) $(RENAMED_JAVAS)
 
 #-----------------------------------------------------------------------------#
 
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.26
diff -u -d -r1.26 declarative_execution.m
--- browser/declarative_execution.m	21 Jul 2004 07:25:11 -0000	1.26
+++ browser/declarative_execution.m	2 Aug 2004 08:06:54 -0000
@@ -399,6 +399,7 @@
 
 :- pragma foreign_type("C", proc_layout, "const MR_Proc_Layout *",
 	[can_pass_as_mercury_type, stable]).
+:- pragma foreign_type("Java", proc_layout, "Object", []). % stub only
 
 get_proc_id_from_layout(Layout) = ProcId :-
 	( proc_layout_is_uci(Layout) ->
Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.46
diff -u -d -r1.46 ml_call_gen.m
--- compiler/ml_call_gen.m	23 Mar 2004 10:52:07 -0000	1.46
+++ compiler/ml_call_gen.m	26 Jul 2004 07:55:47 -0000
@@ -653,7 +653,7 @@
 	ml_gen_pred_label(ModuleInfo, PredId, ProcId, PredLabel, PredModule),
 	ml_gen_proc_params(PredId, ProcId, Params, !Info),
 	Signature = mlds__get_func_signature(Params),
-	QualifiedProcLabel = qual(PredModule, PredLabel - ProcId),
+	QualifiedProcLabel = qual(PredModule, module_qual, PredLabel - ProcId),
 	CodeAddrRval = const(code_addr_const(proc(QualifiedProcLabel,
 		Signature))).
 
Index: compiler/ml_closure_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_closure_gen.m,v
retrieving revision 1.28
diff -u -d -r1.28 ml_closure_gen.m
--- compiler/ml_closure_gen.m	14 Jun 2004 04:16:17 -0000	1.28
+++ compiler/ml_closure_gen.m	26 Jul 2004 07:56:29 -0000
@@ -232,7 +232,7 @@
 		ClosureArgDefns ++ [ClosureLayoutDefn],
 	module_info_name(ModuleInfo, ModuleName),
 	MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
-	ClosureLayoutRval = lval(var(qual(MLDS_ModuleName, Name),
+	ClosureLayoutRval = lval(var(qual(MLDS_ModuleName, module_qual, Name),
 		ClosureLayoutType)).
 
 :- pred ml_gen_closure_proc_id(module_info::in, prog_context::in,
@@ -462,7 +462,8 @@
 		Defns = [Defn],
 		module_info_name(ModuleInfo, ModuleName),
 		MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
-		MLDS_Rval = lval(var(qual(MLDS_ModuleName, TvarVectorName),
+		MLDS_Rval = lval(var(
+			qual(MLDS_ModuleName, module_qual, TvarVectorName),
 			ArrayType))
 	).
 
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.143
diff -u -d -r1.143 ml_code_gen.m
--- compiler/ml_code_gen.m	6 Jul 2004 04:18:49 -0000	1.143
+++ compiler/ml_code_gen.m	26 Jul 2004 07:57:27 -0000
@@ -946,7 +946,7 @@
 	ml_gen_proc_label(ModuleInfo, PredId, ProcId, Name, ModuleName),
 	FuncParams = ml_gen_proc_params(ModuleInfo, PredId, ProcId),
 	MLDS_Context = mlds__make_context(ProgContext),
-	Defn = ml_pragma_export(C_Name, qual(ModuleName, Name),
+	Defn = ml_pragma_export(C_Name, qual(ModuleName, module_qual, Name),
 		FuncParams, MLDS_Context).
 
 %-----------------------------------------------------------------------------%
@@ -2521,7 +2521,7 @@
 			var(SuccessIndicatorVarName),
 			mlds__native_bool_type,
 			no_initializer, no, MLDSContext),
-		SuccessIndicatorLval = var(qual(MLDSModuleName,
+		SuccessIndicatorLval = var(qual(MLDSModuleName, module_qual,
 			SuccessIndicatorVarName), mlds__native_bool_type),
 		SuccessIndicatorStatement = ml_gen_assign(SucceededLval,
 			lval(SuccessIndicatorLval), Context),
@@ -2661,7 +2661,7 @@
 	MLDSType = mercury_type_to_mlds_type(ModuleInfo, Type),
 
 	VarName = ml_gen_var_name(VarSet, Var),
-	QualVarName = qual(MLDSModuleName, VarName),
+	QualVarName = qual(MLDSModuleName, module_qual, VarName),
 	(
 		IsByRef = yes,
 		OutputVarLval = mem_ref(lval(var(QualVarName, MLDSType)),
@@ -2673,7 +2673,7 @@
 
 	MaybeNameMode = yes(UserVarNameString - _),
 	NonMangledVarName = mlds__var_name(UserVarNameString, no),
-	QualLocalVarName= qual(MLDSModuleName, NonMangledVarName),
+	QualLocalVarName= qual(MLDSModuleName, module_qual, NonMangledVarName),
 	LocalVarLval = var(QualLocalVarName, MLDSType),
 
 	Statement = ml_gen_assign(OutputVarLval, lval(LocalVarLval), Context).
@@ -2709,7 +2709,7 @@
 	;
 		MLDSType = mercury_type_to_mlds_type(
 			ModuleInfo, Type),
-		QualVarName = qual(MLDSModuleName, VarName),
+		QualVarName = qual(MLDSModuleName, module_qual, VarName),
 		Initializer = init_obj(
 			lval(var(QualVarName, MLDSType)))
 	),
@@ -2944,7 +2944,7 @@
 	ml_gen_info_get_proc_id(Info, ProcId),
 	ml_gen_proc_label(ModuleInfo, PredId, ProcId, Name, Module),
 	HashDefine = [raw_target_code("#define MR_PROC_LABEL ", []),
-		name(qual(Module, Name)),
+		name(qual(Module, module_qual, Name)),
 		raw_target_code("\n", [])].
 
 :- func get_target_code_attributes(foreign_language,
@@ -3200,7 +3200,8 @@
 		module_info_name(ModuleInfo, ModuleName),
 		MLDSModuleName = mercury_module_name_to_mlds(ModuleName),
 		NonMangledVarName = mlds__var_name(ArgName, no),
-		QualLocalVarName = qual(MLDSModuleName, NonMangledVarName),
+		QualLocalVarName = qual(MLDSModuleName, module_qual,
+			NonMangledVarName),
 		% XXX MLDSType is the incorrect type for this variable.
 		% It should have the Java foreign language representation
 		% of that type. Unfortunately this is not easily expressed
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.83
diff -u -d -r1.83 ml_code_util.m
--- compiler/ml_code_util.m	20 Jul 2004 16:06:38 -0000	1.83
+++ compiler/ml_code_util.m	26 Jul 2004 07:59:11 -0000
@@ -1364,7 +1364,7 @@
 		),
 		Signature = mlds__func_signature(ArgTypes, [])
 	),
-	ProcLabel = qual(PredModule, PredLabel - ProcId),
+	ProcLabel = qual(PredModule, module_qual, PredLabel - ProcId),
 	FuncLabelRval = const(code_addr_const(internal(ProcLabel,
 		FuncLabel, Signature))).
 
@@ -1502,8 +1502,8 @@
 		mercury_private_builtin_module(PrivateBuiltin),
 		MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin),
 		ml_gen_type(Info, Type, MLDS_Type),
-		Lval = var(qual(MLDS_Module, var_name("dummy_var", no)),
-			MLDS_Type)
+		Lval = var(qual(MLDS_Module, module_qual,
+			var_name("dummy_var", no)), MLDS_Type)
 	;
 		ml_gen_info_get_varset(Info, VarSet),
 		VarName = ml_gen_var_name(VarSet, Var),
@@ -1576,7 +1576,8 @@
 ml_gen_var_lval(Info, VarName, VarType, QualifiedVarLval) :-
 	ml_gen_info_get_module_name(Info, ModuleName),
 	MLDS_Module = mercury_module_name_to_mlds(ModuleName),
-	QualifiedVarLval = var(qual(MLDS_Module, VarName), VarType).
+	QualifiedVarLval = var(qual(MLDS_Module, module_qual, VarName),
+		VarType).
 
 	% Generate a declaration for an MLDS variable, given its HLDS type.
 	%
@@ -1932,7 +1933,8 @@
 	InnerFuncParams0 = func_params(InnerArgs0, Rets),
 	InnerArgRvals = list__map(
 		(func(mlds__argument(Data, Type, _GC) )
-				= lval(var(qual(MLDS_Module, VarName), Type)) :-
+				= lval(var(qual(MLDS_Module, module_qual,
+					VarName), Type)) :-
 			( Data = data(var(VarName0)) ->
 				VarName = VarName0
 			;
@@ -1947,8 +1949,8 @@
 	PassedContGCTraceCode = no,
 	PassedContArg = mlds__argument(data(var(PassedContVarName)),
 		InnerFuncArgType, PassedContGCTraceCode),
-	InnerFuncRval = lval(var(qual(MLDS_Module, PassedContVarName),
-		InnerFuncArgType)),
+	InnerFuncRval = lval(var(qual(MLDS_Module, module_qual,
+		PassedContVarName), InnerFuncArgType)),
 	InnerFuncParams = func_params([PassedContArg | InnerArgs0],
 			Rets),
 
@@ -1968,7 +1970,8 @@
 			defined_here(_), _))
 	->
 		% We call the proxy function.
-		QualProcLabel = qual(MLDS_Module, PredLabel - ProcId),
+		QualProcLabel = qual(MLDS_Module, module_qual,
+			PredLabel - ProcId),
 		ProxyFuncRval = const(code_addr_const(
 			internal(QualProcLabel, SeqNum, ProxySignature))),
 
@@ -2262,7 +2265,7 @@
 	ProcId = hlds_pred__initial_proc_id,
 	mercury_private_builtin_module(PredModule),
 	MLDS_Module = mercury_module_name_to_mlds(PredModule),
-	Proc = qual(MLDS_Module, Pred - ProcId),
+	Proc = qual(MLDS_Module, module_qual, Pred - ProcId),
 	CPointerType = mercury_type(c_pointer_type, user_ctor_type,
 		non_foreign_type(c_pointer_type)),
 	ArgTypes = [mlds__pseudo_type_info_type, CPointerType],
@@ -2477,8 +2480,8 @@
 		% atomic_statement occurs, rather than at the
 		% local variable declaration.
 		%
-		VarLval = mlds__var(qual(!.Fixup ^ module_name, VarName),
-			VarType),
+		VarLval = mlds__var(qual(!.Fixup ^ module_name, module_qual,
+				VarName), VarType),
 		PtrRval = mlds__unop(cast(PointerType), mem_addr(VarLval)),
 		list__map_foldl(
 			init_field_n(PointerType, PtrRval, Context),
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.65
diff -u -d -r1.65 ml_elim_nested.m
--- compiler/ml_elim_nested.m	20 Feb 2004 02:39:57 -0000	1.65
+++ compiler/ml_elim_nested.m	2 Aug 2004 02:32:35 -0000
@@ -535,7 +535,7 @@
 		% stack chain pointer at any `try_commit' statements.
 		%
 		ElimInfo0 = elim_info_init(Action, ModuleName,
-			OuterVars, EnvTypeName, EnvPtrTypeName),
+			OuterVars, EnvTypeName, EnvPtrTypeName, Globals),
 		Params0 = mlds__func_params(Arguments0, RetValues),
 		ml_maybe_add_args(Arguments0, FuncBody0, ModuleName,
 			Context, ElimInfo0, ElimInfo1),
@@ -768,14 +768,15 @@
 		% struct:
 		%	env_ptr->foo = foo;
 		%
-		QualVarName = qual(ModuleName, VarName),
-		EnvModuleName = ml_env_module_name(ClassType),
+		QualVarName = qual(ModuleName, mlds__module_qual, VarName),
+		EnvModuleName = ml_env_module_name(ClassType,
+			ElimInfo ^ elim_info_globals),
 		FieldNameString = ml_var_name_to_string(VarName),
-		FieldName = named_field(qual(EnvModuleName, FieldNameString),
-			EnvPtrTypeName),
+		FieldName = named_field(qual(EnvModuleName, mlds__type_qual,
+			FieldNameString), EnvPtrTypeName),
 		Tag = yes(0),
 		EnvPtrName = env_name_base(ElimInfo ^ action) ++ "_ptr",
-		EnvPtr = lval(var(qual(ModuleName,
+		EnvPtr = lval(var(qual(ModuleName, mlds__module_qual,
 				mlds__var_name(EnvPtrName, no)),
 			EnvPtrTypeName)),
 		EnvArgLval = field(Tag, EnvPtr, FieldName, FieldType,
@@ -805,8 +806,8 @@
 	;
 		EnvTypeKind = mlds__struct
 	),
-	EnvTypeName = class_type(qual(ModuleName, EnvClassName), 0,
-		EnvTypeKind).
+	EnvTypeName = class_type(qual(ModuleName, module_qual, EnvClassName),
+		0, EnvTypeKind).
 
 	% Create the environment struct type,
 	% the declaration of the environment variable,
@@ -920,7 +921,7 @@
 	% declare the `env_ptr' var, and
 	% initialize the `env_ptr' with the address of `env'
 	%
-	EnvVar = qual(ModuleName, EnvVarName),
+	EnvVar = qual(ModuleName, module_qual, EnvVarName),
 
 	%
 	% generate code to initialize the environment pointer,
@@ -960,7 +961,8 @@
 	%	struct foo_frame *frame;
 	%	frame = (struct foo_frame *) this_frame;
 	%
-	ThisFrameName = qual(ModuleName, var_name("this_frame", no)),
+	ThisFrameName = qual(ModuleName, module_qual,
+		var_name("this_frame", no)),
 	ThisFrameRval = lval(var(ThisFrameName,
 		mlds__generic_type)),
 	CastThisFrameRval = unop(cast(mlds__ptr_type(EnvTypeName)),
@@ -1038,7 +1040,7 @@
 	%	 stack_chain = frame_ptr;
 	%
 	EnvPtrTypeName = ml_make_env_ptr_type(Globals, EnvTypeName),
-	EnvPtr = lval(var(qual(ModuleName,
+	EnvPtr = lval(var(qual(ModuleName, module_qual,
 			mlds__var_name("frame_ptr", no)),
 		EnvPtrTypeName)),
 	AssignToStackChain = assign(StackChain, EnvPtr),
@@ -1074,7 +1076,7 @@
 		NewSeqNum = SeqNum + 100000,
 		GCTraceFuncName = function(PredLabel, ProcId, yes(NewSeqNum),
 			PredId),
-		ProcLabel = qual(PredModule, PredLabel - ProcId),
+		ProcLabel = qual(PredModule, module_qual, PredLabel - ProcId),
 		GCTraceFuncAddr = internal(ProcLabel, NewSeqNum, Signature)
 	;
 		error("gen_gc_trace_func: not a function")
@@ -1179,10 +1181,10 @@
 	(
 		DefnBody0 = mlds__function(PredProcId, Params,
 			defined_here(FuncBody0), Attributes),
-		statement_contains_var(FuncBody0, qual(ModuleName,
+		statement_contains_var(FuncBody0, qual(ModuleName, module_qual,
 			var(mlds__var_name("env_ptr", no))))
 	->
-		EnvPtrVal = lval(var(qual(ModuleName,
+		EnvPtrVal = lval(var(qual(ModuleName, module_qual,
 				mlds__var_name("env_ptr_arg", no)),
 				mlds__generic_env_ptr_type)),
 		EnvPtrVarType = ml_make_env_ptr_type(Globals, TypeName),
@@ -1254,7 +1256,7 @@
 	% (note that the caller of this routine is responsible
 	% for inserting a cast in <EnvPtrVal> if needed).
 	%
-	EnvPtrVar = qual(ModuleName, EnvPtrVarName),
+	EnvPtrVar = qual(ModuleName, module_qual, EnvPtrVarName),
 	AssignEnvPtr = assign(var(EnvPtrVar, EnvPtrVarType), EnvPtrVal),
 	InitEnvPtr = mlds__statement(atomic(AssignEnvPtr), Context).
 
@@ -1305,8 +1307,8 @@
 ml_stack_chain_var = StackChain :-
 	mercury_private_builtin_module(PrivateBuiltin),
 	MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin),
-	StackChain = var(qual(MLDS_Module, var_name("stack_chain", no)),
-		ml_stack_chain_type).
+	StackChain = var(qual(MLDS_Module, module_qual,
+		var_name("stack_chain", no)), ml_stack_chain_type).
 
 	% the type of the `stack_chain' pointer, i.e. `void *'.
 :- func ml_stack_chain_type = mlds__type.
@@ -1715,7 +1717,7 @@
 				Defn1 = mlds__defn(Name, Context, Flags0,
 					DefnBody1),
 				VarLval = var(qual(!.Info ^ module_name,
-					VarName), Type),
+					module_qual, VarName), Type),
 				InitStatements = [mlds__statement(
 					atomic(assign(VarLval, Rval)),
 					Context)]
@@ -1791,7 +1793,7 @@
 
 ml_need_to_hoist(ModuleName, DataName,
 		FollowingDefns, FollowingStatements) :-
-	QualDataName = qual(ModuleName, DataName),
+	QualDataName = qual(ModuleName, module_qual, DataName),
 	(
 		list__member(FollowingDefn, FollowingDefns)
 	;
@@ -2000,12 +2002,13 @@
 	elim_info::in, elim_info::out) is det.
 
 fixup_var(ThisVar, ThisVarType, Lval, !Info) :-
-	ThisVar = qual(ThisVarModuleName, ThisVarName),
+	ThisVar = qual(ThisVarModuleName, QualKind, ThisVarName),
 	ModuleName = elim_info_get_module_name(!.Info),
 	Locals = elim_info_get_local_data(!.Info),
 	ClassType = elim_info_get_env_type_name(!.Info),
 	EnvPtrVarType = elim_info_get_env_ptr_type_name(!.Info),
 	Action = !.Info ^ action,
+	Globals = !.Info ^ elim_info_globals,
 	(
 		%
 		% Check for references to local variables
@@ -2021,12 +2024,13 @@
 			),
 		solutions(IsLocalVar, [FieldType])
 	->
-		EnvPtr = lval(var(qual(ModuleName,
+		EnvPtr = lval(var(qual(ModuleName, QualKind,
 			mlds__var_name(env_name_base(Action) ++ "_ptr", no)),
 			EnvPtrVarType)),
-		EnvModuleName = ml_env_module_name(ClassType),
+		EnvModuleName = ml_env_module_name(ClassType, Globals),
 		ThisVarFieldName = ml_var_name_to_string(ThisVarName),
-		FieldName = named_field(qual(EnvModuleName, ThisVarFieldName),
+		FieldName = named_field(
+			qual(EnvModuleName, type_qual, ThisVarFieldName),
 			EnvPtrVarType),
 		Tag = yes(0),
 		Lval = field(Tag, EnvPtr, FieldName, FieldType, EnvPtrVarType)
@@ -2061,7 +2065,7 @@
 % 		list__member(Var, Locals),
 % 		Var = mlds__defn(data(var(ThisVarName)), _, _, _)
 % 	->
-% 		Env = var(qual(ModuleName, "env")),
+% 		Env = var(qual(ModuleName, module_qual, "env")),
 % 		FieldName = named_field(ThisVar),
 % 		Tag = yes(0),
 % 		Lval = field(Tag, mem_addr(Env), FieldName)
@@ -2075,7 +2079,7 @@
 % 		ThisVarModuleName = ModuleName,
 % 		outervar_member(ThisVarName, OuterVars, 1, Depth)
 % 	->
-% 		EnvPtrName = qual(ModuleName, "env_ptr"),
+% 		EnvPtrName = qual(ModuleName, module_qual, "env_ptr"),
 % 		EnvPtr = lval(var(EnvPtrName)),
 % 		Lval = make_envptr_ref(Depth, EnvPtr, EnvPtrName, ThisVar)
 % 	;
@@ -2116,12 +2120,13 @@
 % 		Lval = make_envptr_ref(Depth - 1, NewEnvPtr, EnvPtrVar, Var)
 % 	).
 
-:- func ml_env_module_name(mlds__type) = mlds_module_name.
+:- func ml_env_module_name(mlds__type, globals) = mlds_module_name.
 
-ml_env_module_name(ClassType) = EnvModuleName :-
-	( ClassType = class_type(qual(ClassModule, ClassName), Arity, _Kind) ->
+ml_env_module_name(ClassType, Globals) = EnvModuleName :-
+	( ClassType = class_type(ClassModuleName, Arity, _Kind) ->
+		ClassModuleName = qual(ClassModule, QualKind, ClassName),
 		EnvModuleName = mlds__append_class_qualifier(ClassModule,
-			ClassName, Arity)
+			QualKind, Globals, ClassName, Arity)
 	;
 		error("ml_env_module_name: ClassType is not a class")
 	).
@@ -2451,7 +2456,7 @@
 	mlds__statement.
 
 gen_save_stack_chain_var(MLDS_Module, Id, Context) = SaveStatement :-
-	SavedStackChain = var(qual(MLDS_Module,
+	SavedStackChain = var(qual(MLDS_Module, module_qual,
 		ml_saved_stack_chain_name(Id)), ml_stack_chain_type),
 	Assignment = assign(SavedStackChain, lval(ml_stack_chain_var)),
 	SaveStatement = mlds__statement(atomic(Assignment), Context).
@@ -2462,7 +2467,7 @@
 	mlds__statement.
 
 gen_restore_stack_chain_var(MLDS_Module, Id, Context) = RestoreStatement :-
-	SavedStackChain = var(qual(MLDS_Module,
+	SavedStackChain = var(qual(MLDS_Module, module_qual,
 		ml_saved_stack_chain_name(Id)), ml_stack_chain_type),
 	Assignment = assign(ml_stack_chain_var, lval(SavedStackChain)),
 	RestoreStatement = mlds__statement(atomic(Assignment), Context).
@@ -2521,7 +2526,9 @@
 
 				% A counter used to number the local variables
 				% used to save the stack chain
-			saved_stack_chain_counter :: counter
+			saved_stack_chain_counter :: counter,
+
+			elim_info_globals :: globals
 	).
 
 	% The lists of local variables for
@@ -2530,11 +2537,12 @@
 :- type outervars == list(list(mlds__defn)).
 
 :- func elim_info_init(action, mlds_module_name, outervars,
-	mlds__type, mlds__type) = elim_info.
+	mlds__type, mlds__type, globals) = elim_info.
 
-elim_info_init(Action, ModuleName, OuterVars, EnvTypeName, EnvPtrTypeName) =
+elim_info_init(Action, ModuleName, OuterVars, EnvTypeName, EnvPtrTypeName,
+		Globals) =
 	elim_info(Action, ModuleName, OuterVars, [], [],
-		EnvTypeName, EnvPtrTypeName, counter__init(0)).
+		EnvTypeName, EnvPtrTypeName, counter__init(0), Globals).
 
 :- func elim_info_get_module_name(elim_info) = mlds_module_name.
 :- func elim_info_get_outer_vars(elim_info) = outervars.
Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.26
diff -u -d -r1.26 ml_optimize.m
--- compiler/ml_optimize.m	19 Mar 2004 10:19:22 -0000	1.26
+++ compiler/ml_optimize.m	26 Jul 2004 09:36:04 -0000
@@ -218,7 +218,7 @@
 	(
 		globals__lookup_bool_option(OptInfo ^ globals,
 			optimize_tailcalls, yes),
-		can_optimize_tailcall(qual(OptInfo ^ module_name,
+		can_optimize_tailcall(qual(OptInfo ^ module_name, module_qual,
 			OptInfo ^ entity_name), Stmt0)
 	->
 		CommentStatement = statement(
@@ -251,7 +251,7 @@
 		% the --target asm back-end, whereas generating the
 		% appropriate MLDS instructions does.
 		%
-		FuncRval = const(code_addr_const(proc(qual(ModName,
+		FuncRval = const(code_addr_const(proc(qual(ModName, module_qual,
                         pred(predicate, _DefnModName, PredName, _Arity,
 				_CodeModel, _NonOutputFunc) - _ProcId),
 			_FuncSignature))),
@@ -320,7 +320,8 @@
 		%
 		Name = data(var(VarName))
 	->
-		QualVarName = qual(OptInfo ^ module_name, VarName),
+		QualVarName = qual(OptInfo ^ module_name, module_qual,
+			VarName),
 		(
 			%
 			% don't bother assigning a variable to itself
@@ -356,7 +357,7 @@
 			VarName = mlds__var_name(VarNameStr, MaybeNum),
 			TempName = mlds__var_name(VarNameStr ++ "__tmp_copy",
 				MaybeNum),
-			QualTempName = qual(OptInfo ^ module_name,
+			QualTempName = qual(OptInfo ^ module_name, module_qual,
 				TempName),
 			Initializer = no_initializer,
 			% We don't need to trace the temporary variables
@@ -406,7 +407,8 @@
 		stmt_contains_statement(Stmt0, Call),
 		Call = mlds__statement(CallStmt, _),
 		can_optimize_tailcall(
-			qual(OptInfo ^ module_name, OptInfo ^ entity_name),
+			qual(OptInfo ^ module_name, module_qual,
+				OptInfo ^ entity_name),
 			CallStmt)
 	->
 		Comment = atomic(comment("tailcall optimized into a loop")),
@@ -599,8 +601,8 @@
 		!.Statements = [AssignStatement | !:Statements],
 		AssignStatement = statement(atomic(assign(LHS, RHS)), _),
 		LHS = var(ThisVar, _ThisType),
-		ThisVar = qual(Qualifier, VarName),
-		ThisData = qual(Qualifier, var(VarName)),
+		ThisVar = qual(Qualifier, QualKind, VarName),
+		ThisData = qual(Qualifier, QualKind, var(VarName)),
 		Qualifier = OptInfo ^ module_name,
 		list__takewhile(isnt(var_defn(VarName)), !.Defns,
 			_PrecedingDefns, [_VarDefn | FollowingDefns]),
@@ -616,7 +618,8 @@
 			list__member(OtherDefn, FollowingDefns),
 			OtherDefn = mlds__defn(data(OtherVarName),
 				_, _, data(_Type, OtherInitializer, _GC)),
-			( rval_contains_var(RHS, qual(Qualifier, OtherVarName))
+			( rval_contains_var(RHS,
+				qual(Qualifier, QualKind, OtherVarName))
 			; initializer_contains_var(OtherInitializer, ThisData)
 			)
 		)
@@ -744,7 +747,7 @@
 	DefnBody = mlds__data(_Type, Initializer, _MaybeGCTraceCode),
 
 	% ... with a known initial value.
-	QualVarName = qual(OptInfo ^ module_name, VarName),
+	QualVarName = qual(OptInfo ^ module_name, module_qual, VarName),
 	(
 		Initializer = init_obj(Rval)
 	;
@@ -855,8 +858,8 @@
 		% Statement0.  Only if we are sure that Statement0
 		% can't modify the variable's value is it safe to go
 		% on and look for the initial value in Statements0.
-		VarName = qual(Mod, UnqualVarName),
-		DataName = qual(Mod, var(UnqualVarName)),
+		VarName = qual(Mod, QualKind, UnqualVarName),
+		DataName = qual(Mod, QualKind, var(UnqualVarName)),
 		\+ statement_contains_var(Statement0, DataName),
 		\+ (
 			statement_contains_statement(Statement0, Label),
@@ -878,8 +881,8 @@
 		% delete the assignment, by replacing it with an empty block
 		Stmt = block([], [])
 	; Stmt0 = block(Defns0, SubStatements0) ->
-		Var = qual(Mod, UnqualVarName),
-		Data = qual(Mod, var(UnqualVarName)),
+		Var = qual(Mod, QualKind, UnqualVarName),
+		Data = qual(Mod, QualKind, var(UnqualVarName)),
 		\+ defns_contains_var(Defns0, Data),
 		find_initial_val_in_statements(Var, Rval,
 			SubStatements0, SubStatements),
Index: compiler/ml_tailcall.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.22
diff -u -d -r1.22 ml_tailcall.m
--- compiler/ml_tailcall.m	5 Apr 2004 05:07:41 -0000	1.22
+++ compiler/ml_tailcall.m	26 Jul 2004 08:10:27 -0000
@@ -486,7 +486,8 @@
 	; Const = data_addr_const(DataAddr) ->
 		DataAddr = data_addr(ModuleName, DataName),
 		( DataName = var(VarName) ->
-			\+ var_is_local(qual(ModuleName, VarName), Locals)
+			\+ var_is_local(qual(ModuleName, module_qual,
+				VarName), Locals)
 		;
 			true
 		)
@@ -510,7 +511,7 @@
 var_is_local(Var, Locals) :-
 		% XXX we ignore the ModuleName --
 		% that is safe, but overly conservative
-	Var = qual(_ModuleName, VarName),
+	Var = qual(_ModuleName, _QualKind, VarName),
 	some [Local] (
 		locals_member(Local, Locals),
 		Local = data(var(VarName))
@@ -533,7 +534,7 @@
 	),
 		% XXX we ignore the ModuleName --
 		% that is safe, but might be overly conservative
-	QualifiedProcLabel = qual(_ModuleName, ProcLabel),
+	QualifiedProcLabel = qual(_ModuleName, _QualKind, ProcLabel),
 	ProcLabel = PredLabel - ProcId,
 	some [Local] (
 		locals_member(Local, Locals),
@@ -623,7 +624,7 @@
 		CodeAddr = internal(QualProcLabel, SeqNum, _Sig),
 		MaybeSeqNum = yes(SeqNum)
 	),
-	QualProcLabel = qual(CallerModule, PredLabel - ProcId),
+	QualProcLabel = qual(CallerModule, module_qual, PredLabel - ProcId),
 	CallerFuncName = function(PredLabel, ProcId, MaybeSeqNum, _PredId),
 	% if so, construct an appropriate warning
 	Warning = tailcall_warning(PredLabel, ProcId, Context).
Index: compiler/ml_type_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.36
diff -u -d -r1.36 ml_type_gen.m
--- compiler/ml_type_gen.m	19 Mar 2004 10:19:22 -0000	1.36
+++ compiler/ml_type_gen.m	2 Aug 2004 02:36:56 -0000
@@ -172,7 +172,8 @@
 	MLDS_Context = mlds__make_context(Context),
 
 	% generate the class name
-	ml_gen_type_name(TypeCtor, qual(_, MLDS_ClassName), MLDS_ClassArity),
+	ml_gen_type_name(TypeCtor, QualifiedClassName, MLDS_ClassArity),
+	QualifiedClassName = qual(_, _, MLDS_ClassName),
 
 	% generate the class members
 	ValueMember = ml_gen_enum_value_member(Context),
@@ -333,9 +334,11 @@
 	ml_gen_type_name(TypeCtor, QualBaseClassName, BaseClassArity),
 	BaseClassId = mlds__class_type(QualBaseClassName, BaseClassArity,
 		mlds__class),
-	QualBaseClassName = qual(BaseClassModuleName, BaseClassName),
+	QualBaseClassName = qual(BaseClassModuleName, QualKind, BaseClassName),
+	module_info_globals(ModuleInfo, Globals),
 	BaseClassQualifier = mlds__append_class_qualifier(
-		BaseClassModuleName, BaseClassName, BaseClassArity),
+		BaseClassModuleName, QualKind, Globals,
+		BaseClassName, BaseClassArity),
 
 	(
 		%
@@ -378,7 +381,6 @@
 			TagMembers = TagMembers0,
 			TagClassId = BaseClassId
 		;
-			module_info_globals(ModuleInfo, Globals),
 			globals__get_target(Globals, Target),
 			ml_gen_secondary_tag_class(MLDS_Context,
 				BaseClassQualifier, BaseClassId, TagMembers0,
@@ -523,7 +525,7 @@
 	% Note: the secondary tag class is nested inside the
 	% base class for this type.
 	UnqualClassName = "tag_type",
-	ClassName = qual(BaseClassQualifier, UnqualClassName),
+	ClassName = qual(BaseClassQualifier, type_qual, UnqualClassName),
 	ClassArity = 0,
 	SecondaryTagClassId = mlds__class_type(ClassName, ClassArity,
 		mlds__class),
@@ -656,15 +658,16 @@
 				CtorClassType = BaseClassId,
 				CtorClassQualifier = BaseClassQualifier
 			;
-				CtorClassType = mlds__class_type(qual(
-					BaseClassQualifier, UnqualCtorName),
+				CtorClassType = mlds__class_type(
+					qual(BaseClassQualifier, type_qual,
+						UnqualCtorName),
 					CtorArity, mlds__class),
 				CtorClassQualifier =
 				    mlds__append_class_qualifier(
-					BaseClassQualifier, UnqualCtorName,
-					CtorArity)
+					BaseClassQualifier, type_qual,
+					Globals, UnqualCtorName, CtorArity)
 			),
-			CtorFunction = gen_constructor_function(Target,
+			CtorFunction = gen_constructor_function(Globals,
 				BaseClassId, CtorClassType, CtorClassQualifier,
 				SecondaryTagClassId, MaybeSecTagVal, Members,
 				MLDS_Context),
@@ -681,7 +684,7 @@
 				),
 				Members \= []
 			->
-				ZeroArgCtor = gen_constructor_function(Target,
+				ZeroArgCtor = gen_constructor_function(Globals,
 					BaseClassId, CtorClassType,
 					CtorClassQualifier,
 					SecondaryTagClassId, no, [],
@@ -770,22 +773,23 @@
 target_requires_module_qualified_params(java)    = yes.
 target_requires_module_qualified_params(asm)	 = no.
 
-:- func gen_constructor_function(compilation_target, mlds__class_id,
+:- func gen_constructor_function(globals, mlds__class_id,
 	mlds__type, mlds_module_name, mlds__class_id, maybe(int), mlds__defns,
 	mlds__context) = mlds__defn.
 
-gen_constructor_function(Target, BaseClassId, ClassType, ClassQualifier,
+gen_constructor_function(Globals, BaseClassId, ClassType, ClassQualifier,
 		SecondaryTagClassId, MaybeTag, Members, Context) = CtorDefn :-
 	Args = list__map(make_arg, Members),
 	ReturnValues = [],
 
+	globals__get_target(Globals, Target),
 	InitMembers0 = list__map(gen_init_field(Target, BaseClassId,
 			ClassType, ClassQualifier), Members),
 	(
 		MaybeTag = yes(TagVal)
 	->
 		InitTag = gen_init_tag(ClassType, SecondaryTagClassId, TagVal,
-			Context),
+			Context, Globals),
 		InitMembers = [InitTag | InitMembers0]
 	;
 		InitMembers = InitMembers0
@@ -839,18 +843,18 @@
 	(
 		target_requires_module_qualified_params(Target) = yes
 	->
-		( BaseClassId = mlds__class_type(qual(ModuleName, _), _, _) ->
-			QualVarName = qual(ModuleName, VarName)
+		( BaseClassId = mlds__class_type(qual(ModuleName, _, _), _, _) ->
+			QualVarName = qual(ModuleName, module_qual, VarName)
 		;
 			unexpected(this_file,
 				"gen_init_field: invalid BaseClassId")
 		)
 	;
-		QualVarName = qual(ClassQualifier, VarName)
+		QualVarName = qual(ClassQualifier, type_qual, VarName)
 	),
 	Param = mlds__lval(mlds__var(QualVarName, Type)),
 	Field = mlds__field(yes(0), self(ClassType),
-			named_field(qual(ClassQualifier, Name),
+			named_field(qual(ClassQualifier, type_qual, Name),
 				mlds__ptr_type(ClassType)),
 				% XXX we should use ClassType rather than
 				% BaseClassId here.  But doing so breaks the
@@ -860,14 +864,16 @@
 	Statement = mlds__statement(atomic(assign(Field, Param)), Context).
 
 	% Generate "this->data_tag = <TagVal>;".
-:- func gen_init_tag(mlds__type, mlds__class_id, int, mlds__context)
+:- func gen_init_tag(mlds__type, mlds__class_id, int, mlds__context, globals)
 	= mlds__statement.
 
-gen_init_tag(ClassType, SecondaryTagClassId, TagVal, Context) = Statement :-
+gen_init_tag(ClassType, SecondaryTagClassId, TagVal, Context, Globals)
+		= Statement :-
 	( SecondaryTagClassId = mlds__class_type(TagClass, TagArity, _) ->
-		TagClass = qual(BaseClassQualifier, TagClassName),
+		TagClass = qual(BaseClassQualifier, QualKind, TagClassName),
 		TagClassQualifier = mlds__append_class_qualifier(
-				BaseClassQualifier, TagClassName, TagArity)
+			BaseClassQualifier, QualKind, Globals,
+			TagClassName, TagArity)
 	;
 		unexpected(this_file,
 				"gen_init_tag: class_id should be a class")
@@ -876,7 +882,7 @@
 	Type = mlds__native_int_type,
 	Val = const(int_const(TagVal)),
 	Field = mlds__field(yes(0), self(ClassType),
-			named_field(qual(TagClassQualifier, Name),
+			named_field(qual(TagClassQualifier, type_qual, Name),
 				mlds__ptr_type(SecondaryTagClassId)),
 			Type, ClassType),
 	Statement = mlds__statement(atomic(assign(Field, Val)), Context).
@@ -937,7 +943,7 @@
 % Miscellaneous helper routines.
 %
 
-ml_gen_type_name(Name - Arity, qual(MLDS_Module, TypeName), Arity) :-
+ml_gen_type_name(Name - Arity, QualifiedTypeName, Arity) :-
 	(
 		Name = qualified(ModuleName, TypeName)
 	;
@@ -946,7 +952,8 @@
 		Name = unqualified(TypeName),
 		mercury_public_builtin_module(ModuleName)
 	),
-	MLDS_Module = mercury_module_name_to_mlds(ModuleName).
+	MLDS_Module = mercury_module_name_to_mlds(ModuleName),
+	QualifiedTypeName = qual(MLDS_Module, module_qual, TypeName).
 
 	% For interoperability, we ought to generate an `==' member
 	% for types which have a user-defined equality, if the target
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.76
diff -u -d -r1.76 ml_unify_gen.m
--- compiler/ml_unify_gen.m	14 Jun 2004 04:16:18 -0000	1.76
+++ compiler/ml_unify_gen.m	2 Aug 2004 04:50:05 -0000
@@ -368,7 +368,8 @@
 			HighLevelData),
 		UsesBaseClass = (ml_tag_uses_base_class(Tag) -> yes ; no),
 		ConstType = get_type_for_cons_id(MLDS_VarType,
-			UsesBaseClass, yes(ConsId), HighLevelData),
+			UsesBaseClass, yes(ConsId), HighLevelData,
+			Globals),
 		ml_gen_static_const_addr(!.Info, Var, ConstType,
 			ConstAddrRval),
 		( TagVal = 0 ->
@@ -476,11 +477,12 @@
 ml_gen_reserved_address(ModuleInfo, reserved_object(TypeCtor, QualCtorName,
 		CtorArity), _Type) = Rval :-
 	( QualCtorName = qualified(ModuleName, CtorName) ->
+		module_info_globals(ModuleInfo, Globals),
 		MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
 		TypeCtor = TypeName - TypeArity,
 		unqualify_name(TypeName, UnqualTypeName),
 		MLDS_TypeName = mlds__append_class_qualifier(MLDS_ModuleName,
-			UnqualTypeName, TypeArity),
+			module_qual, Globals, UnqualTypeName, TypeArity),
 		Name = ml_format_reserved_object_name(CtorName, CtorArity),
 		Rval0 = const(data_addr_const(
 			data_addr(MLDS_TypeName, var(Name)))),
@@ -496,13 +498,13 @@
 		% the JIT probably doesn't optimize downcasts).
 		% So we only do it if the back-end requires it.
 	  	%
-		module_info_globals(ModuleInfo, Globals),
 		globals__get_target(Globals, Target),
 		( target_supports_inheritence(Target) = yes ->
 			Rval = Rval0
 		;
 			MLDS_Type = mlds__ptr_type(mlds__class_type(
-				qual(MLDS_ModuleName, UnqualTypeName),
+				qual(MLDS_ModuleName, module_qual,
+					UnqualTypeName),
 				TypeArity, mlds__class)),
 			Rval = unop(cast(MLDS_Type), Rval0)
 		)
@@ -704,7 +706,7 @@
 		ml_gen_static_const_name(Var, ConstName, !Info),
 		UsesBaseClass = (MaybeCtorName = yes(_) -> no ; yes),
 		ConstType = get_type_for_cons_id(MLDS_Type, UsesBaseClass,
-			MaybeConsId, HighLevelData),
+			MaybeConsId, HighLevelData, Globals),
 		% XXX if the secondary tag is in a base class, then ideally its
 		% initializer should be wrapped in `init_struct([init_obj(X)])'
 		% rather than just `init_obj(X)' -- the fact that we don't
@@ -804,11 +806,11 @@
 
 	% Return the MLDS type suitable for constructing a constant static
 	% ground term with the specified cons_id.
-:- func get_type_for_cons_id(mlds__type, bool, maybe(cons_id), bool)
+:- func get_type_for_cons_id(mlds__type, bool, maybe(cons_id), bool, globals)
 	= mlds__type.
 
-get_type_for_cons_id(MLDS_Type, UsesBaseClass, MaybeConsId, HighLevelData)
-		= ConstType :-
+get_type_for_cons_id(MLDS_Type, UsesBaseClass, MaybeConsId, HighLevelData,
+		Globals) = ConstType :-
 	(
 		HighLevelData = no,
 		ConstType = mlds__array_type(mlds__generic_type)
@@ -852,11 +854,12 @@
 			% (since the derived class will also be nested
 			% inside the base class).
 			unqualify_name(CtorSymName, CtorName),
-			QualTypeName = qual(MLDS_Module, TypeName),
+			QualTypeName = qual(MLDS_Module, _QualKind, TypeName),
 			ClassQualifier = mlds__append_class_qualifier(
-				MLDS_Module, TypeName, TypeArity),
+				MLDS_Module, module_qual, Globals,
+				TypeName, TypeArity),
 			ConstType = mlds__class_type(
-				qual(ClassQualifier, CtorName),
+				qual(ClassQualifier, type_qual, CtorName),
 				CtorArity, mlds__class)
 		;
 			% Convert mercury_types for user-defined types
@@ -1197,7 +1200,7 @@
 		ConsId = ctor_id(ConsName, 0),
 		ModuleName = mercury_module_name_to_mlds(unqualified(""))
 	),
-	QualifiedConsId = qual(ModuleName, ConsId).
+	QualifiedConsId = qual(ModuleName, module_qual, ConsId).
 
 	% Create a list of rvals for the arguments
 	% for a construction unification.  For each argument which
@@ -1575,7 +1578,8 @@
 			->
 				unqualify_name(ConsName, UnqualConsName),
 				FieldId = ml_gen_field_id(VarType, Tag,
-					UnqualConsName, ConsArity, FieldName)
+					UnqualConsName, ConsArity, FieldName,
+					Globals)
 			;
 				error("ml_gen_unify_args: invalid cons_id")
 			)
@@ -1860,13 +1864,15 @@
 	;
 		error("ml_gen_hl_tag_field_id: invalid type")
 	),
-	ml_gen_type_name(TypeCtor, qual(MLDS_Module, TypeName), TypeArity),
+	ml_gen_type_name(TypeCtor, QualifiedTypeName, TypeArity),
+	QualifiedTypeName = qual(MLDS_Module, TypeQualKind, TypeName),
 
 	% Figure out whether this type has constructors both
 	% with and without secondary tags.  If so, then the
 	% secondary tag field is in a class "tag_type" that is
 	% derived from the base class for this type,
 	% rather than in the base class itself.
+	module_info_globals(ModuleInfo, Globals),
 	module_info_types(ModuleInfo, TypeTable),
 	TypeDefn = map__lookup(TypeTable, TypeCtor),
 	hlds_data__get_type_defn_body(TypeDefn, TypeDefnBody),
@@ -1883,11 +1889,14 @@
 			))
 		->
 			ClassQualifier = mlds__append_class_qualifier(
-				MLDS_Module, TypeName, TypeArity),
+				MLDS_Module, module_qual, Globals,
+				TypeName, TypeArity),
+			ClassQualKind = TypeQualKind,
 			ClassName = "tag_type",
 			ClassArity = 0
 		;
 			ClassQualifier = MLDS_Module,
+			ClassQualKind = module_qual,
 			ClassName = TypeName,
 			ClassArity = TypeArity
 		)
@@ -1896,23 +1905,23 @@
 	),
 
 	% Put it all together
-	QualClassName = qual(ClassQualifier, ClassName),
+	QualClassName = qual(ClassQualifier, ClassQualKind, ClassName),
 	ClassPtrType = mlds__ptr_type(mlds__class_type(
 		QualClassName, ClassArity, mlds__class)),
 	FieldQualifier = mlds__append_class_qualifier(
-		ClassQualifier, ClassName, ClassArity),
-	QualifiedFieldName = qual(FieldQualifier, FieldName),
+		ClassQualifier, ClassQualKind, Globals, ClassName, ClassArity),
+	QualifiedFieldName = qual(FieldQualifier, type_qual, FieldName),
 	FieldId = named_field(QualifiedFieldName, ClassPtrType).
 
 :- func ml_gen_field_id(prog_type, cons_tag, mlds__class_name, arity,
-	mlds__field_name) = mlds__field_id.
+	mlds__field_name, globals) = mlds__field_id.
 
-ml_gen_field_id(Type, Tag, ConsName, ConsArity, FieldName) = FieldId :-
+ml_gen_field_id(Type, Tag, ConsName, ConsArity, FieldName, Globals) = FieldId :-
 	( type_to_ctor_and_args(Type, TypeCtor, _) ->
 		ml_gen_type_name(TypeCtor, QualTypeName, TypeArity),
-		QualTypeName = qual(MLDS_Module, TypeName),
+		QualTypeName = qual(MLDS_Module, QualKind, TypeName),
 		TypeQualifier = mlds__append_class_qualifier(
-			MLDS_Module, TypeName, TypeArity),
+			MLDS_Module, QualKind, Globals, TypeName, TypeArity),
 
 		( ml_tag_uses_base_class(Tag) ->
 			% in this case, there's only one functor for the type
@@ -1920,16 +1929,20 @@
 			% and so the class name is determined by the type name
 			ClassPtrType = mlds__ptr_type(mlds__class_type(
 				QualTypeName, TypeArity, mlds__class)),
-			QualifiedFieldName = qual(TypeQualifier, FieldName)
+			QualifiedFieldName = qual(TypeQualifier, type_qual,
+				FieldName)
 		;
 			% in this case, the class name is determined by the
 			% constructor
-			QualConsName = qual(TypeQualifier, ConsName),
+			QualConsName = qual(TypeQualifier, type_qual,
+				ConsName),
 			ClassPtrType = mlds__ptr_type(mlds__class_type(
 				QualConsName, ConsArity, mlds__class)),
 			FieldQualifier = mlds__append_class_qualifier(
-				TypeQualifier, ConsName, ConsArity),
-			QualifiedFieldName = qual(FieldQualifier, FieldName)
+				TypeQualifier, type_qual, Globals,
+				ConsName, ConsArity),
+			QualifiedFieldName = qual(FieldQualifier, type_qual,
+				FieldName)
 		),
 		FieldId = named_field(QualifiedFieldName, ClassPtrType)
 	;
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.30
diff -u -d -r1.30 ml_util.m
--- compiler/ml_util.m	20 Feb 2004 02:39:58 -0000	1.30
+++ compiler/ml_util.m	26 Jul 2004 08:39:13 -0000
@@ -182,9 +182,9 @@
 		CodeAddr = internal(QualifiedProcLabel, SeqNum, _Sig),
 		MaybeSeqNum = yes(SeqNum)
 	),
-	QualifiedProcLabel = qual(ModuleName, PredLabel - ProcId),
+	QualifiedProcLabel = qual(ModuleName, module_qual, PredLabel - ProcId),
 	% check that the module name matches
-	Name = qual(ModuleName, FuncName),
+	Name = qual(ModuleName, module_qual, FuncName),
 	% check that the PredLabel, ProcId, and MaybeSeqNum match
 	FuncName = function(PredLabel, ProcId, MaybeSeqNum, _),
 
@@ -432,8 +432,8 @@
 target_code_component_contains_var(target_code_output(Lval), Name) :-
 	lval_contains_var(Lval, Name).
 target_code_component_contains_var(name(EntityName), DataName) :-
-	EntityName = qual(ModuleName, data(UnqualDataName)),
-	DataName = qual(ModuleName, UnqualDataName),
+	EntityName = qual(ModuleName, QualKind, data(UnqualDataName)),
+	DataName = qual(ModuleName, QualKind, UnqualDataName),
 	% this is a place where we can succeed
 	true.
 
@@ -571,7 +571,7 @@
 rval_contains_var(const(Const), QualDataName) :-
 	Const = data_addr_const(DataAddr),
 	DataAddr = data_addr(ModuleName, DataName),
-	QualDataName = qual(ModuleName, DataName),
+	QualDataName = qual(ModuleName, _QualKind, DataName),
 	% this is a place where we can succeed
 	true.
 rval_contains_var(unop(_Op, Rval), Name) :-
@@ -591,8 +591,8 @@
 	rval_contains_var(Rval, Name).
 lval_contains_var(mem_ref(Rval, _Type), Name) :-
 	rval_contains_var(Rval, Name).
-lval_contains_var(var(qual(ModuleName, Name), _Type),
-		qual(ModuleName, var(Name))) :-
+lval_contains_var(var(qual(ModuleName, QualKind, Name), _Type),
+		qual(ModuleName, QualKind, var(Name))) :-
 	% this is another place where we can succeed
 	true.
 
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.113
diff -u -d -r1.113 mlds.m
--- compiler/mlds.m	14 Jun 2004 04:16:19 -0000	1.113
+++ compiler/mlds.m	2 Aug 2004 05:41:27 -0000
@@ -221,7 +221,8 @@
 
 % 2. Packages.
 %
-% MLDS packages should be mapped directly to target packages, if possible.
+% MLDS packages should be mapped directly to the corresponding notion
+% in the target language, if possible.
 % If the target doesn't have a notion of packages, then they should be
 % mapped to names of the form "foo.bar.baz" or if dots are not allowed
 % then to "foo__bar__baz".
@@ -349,14 +350,17 @@
 %
 :- type mlds
 	---> mlds(
-			% The Mercury module name.
+			% The original Mercury module name.
 		name		:: mercury_module_name,
 
 			% Code defined in some other language, e.g.  for
 			% `pragma c_header_code', etc.
 		foreign_code	:: map(foreign_language, mlds__foreign_code),
 
+			%
 			% The MLDS code itself
+			%
+
 			% Packages/classes to import
 		toplevel_imports :: mlds__imports,
 
@@ -380,6 +384,7 @@
 	--->	user_visible_interface
 	;	compiler_visible_interface.
 
+% An mlds__import specifies  FIXME
 % Currently an import just gives the name of the package to be imported.
 % This might perhaps need to be expanded to cater to different kinds of
 % imports, e.g. imports with wild-cards ("import java.lang.*").
@@ -430,8 +435,10 @@
 % Given an MLDS module name (e.g. `foo.bar'), append another class qualifier
 % (e.g. for a class `baz'), and return the result (e.g. `foo.bar.baz').
 % The `arity' argument specifies the arity of the class.
-:- func mlds__append_class_qualifier(mlds_module_name, mlds__class_name,
-		arity) = mlds_module_name.
+% The qual_kind argument specifies the qualifier kind of the module_name
+% argument.
+:- func mlds__append_class_qualifier(mlds_module_name, mlds__qual_kind,
+		globals, mlds__class_name, arity) = mlds_module_name.
 
 % Append a wrapper class qualifier to the module name and leave the
 % package name unchanged.
@@ -467,10 +474,16 @@
 % If the target language has restrictions on what names can be used
 % in identifiers, then it is the responsibility of the target language
 % generator to mangle these names accordingly.
-:- type mlds__fully_qualified_name(T)
-	---> 	qual(mlds_module_name, T).
 :- type mlds__qualified_entity_name
 	==	mlds__fully_qualified_name(mlds__entity_name).
+:- type mlds__fully_qualified_name(T)
+	--->	qual(mlds_module_name, mlds__qual_kind, T).
+% For the Java back-end, we need to distinguish between module qualifiers
+% and type qualifiers, because type names get the case of their initial 
+% letter inverted (i.e. lowercase => uppercase).
+:- type mlds__qual_kind
+	--->	module_qual
+	;	type_qual.
 
 :- type mlds__entity_name
 	--->	type(mlds__class_name, arity)	% Name, arity.
@@ -1707,6 +1720,16 @@
 		).
 
 %-----------------------------------------------------------------------------%
+
+	% Invert the case of the first letter of the string.
+	% This is used for the Java back-end.
+:- func flip_initial_case(string) = string.
+
+	% Invert the case of the first letter of the last component of
+	% a (possibly) qualified name.  This is used for the Java back-end.
+:- func flip_initial_case_of_final_part(sym_name) = sym_name.
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -1717,7 +1740,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 
-:- import_module int, term, string, require.
+:- import_module char, int, term, string, require.
 
 %-----------------------------------------------------------------------------%
 
@@ -1839,7 +1862,7 @@
 
 %-----------------------------------------------------------------------------%
 
-% A mercury module name consists of two parts.  One part is the package
+% An MLDS module name consists of two parts.  One part is the package
 % which the module name is defined in, and the other part is the actual
 % module name.  For example the module name System.XML could be defined
 % in the package XML.
@@ -1879,8 +1902,22 @@
 
 mlds_module_name_to_package_name(Module) = Module ^ package_name.
 
-mlds__append_class_qualifier(name(Package, Module), ClassName, ClassArity) =
-		name(Package, qualified(Module, ClassQualifier)) :-
+mlds__append_class_qualifier(name(Package, Module), QualKind, Globals,
+			ClassName, ClassArity) =
+		name(Package, qualified(AdjustedModule, ClassQualifier)) :-
+	%
+	% For the Java back-end, we flip the initial case of an type
+	% qualifiers, in order to match the usual Java conventions.
+	%
+	(
+		globals__get_target(Globals, CompilationTarget),
+		CompilationTarget = java,
+	  	QualKind = type_qual
+	->
+		AdjustedModule = flip_initial_case_of_final_part(Module)
+	;
+		AdjustedModule = Module
+	),
 	string__format("%s_%d", [s(ClassName), i(ClassArity)],
 		ClassQualifier).
 
@@ -1890,6 +1927,26 @@
 	= name(Package, qualified(Module, Name)).
 
 wrapper_class_name = "mercury_code".
+
+flip_initial_case_of_final_part(unqualified(Name)) =
+	unqualified(flip_initial_case(Name)).
+flip_initial_case_of_final_part(qualified(Qual, Name)) =
+	qualified(Qual, flip_initial_case(Name)).
+
+	% Invert the case of the first letter of the string.
+flip_initial_case(S0) = S :-
+	( string__first_char(S0, First0, Rest) ->
+		( char__is_upper(First0) ->
+			First = char__to_lower(First0)
+		; char__is_lower(First0) ->
+			First = char__to_upper(First0)
+		;
+			First = First0
+		),
+		string__first_char(S, First, Rest)
+	;
+		S = S0
+	).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.165
diff -u -d -r1.165 mlds_to_c.m
--- compiler/mlds_to_c.m	20 Jul 2004 16:06:39 -0000	1.165
+++ compiler/mlds_to_c.m	2 Aug 2004 04:10:43 -0000
@@ -483,7 +483,7 @@
 mlds_output_init_fn_defns(ModuleName, FuncDefns, TypeCtorInfoDefns, !IO) :-
 	output_init_fn_name(ModuleName, "", !IO),
 	io__write_string("\n{\n", !IO),
-	io_get_globals(Globals, !IO),
+	globals__io_get_globals(Globals, !IO),
 	(
 		need_to_init_entries(Globals),
 		FuncDefns \= []
@@ -562,7 +562,8 @@
 mlds_output_calls_to_init_entry(ModuleName, [FuncDefn | FuncDefns], !IO) :-
 	FuncDefn = mlds__defn(EntityName, _, _, _),
 	io__write_string("\tMR_init_entry(", !IO),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName), !IO),
+	mlds_output_fully_qualified_name(
+		qual(ModuleName, module_qual, EntityName), !IO),
 	io__write_string(");\n", !IO),
 	mlds_output_calls_to_init_entry(ModuleName, FuncDefns, !IO).
 
@@ -577,7 +578,8 @@
 		[TypeCtorInfoDefn | TypeCtorInfoDefns], !IO) :-
 	TypeCtorInfoDefn = mlds__defn(EntityName, _, _, _),
 	io__write_string("\tMR_register_type_ctor_info(&", !IO),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName), !IO),
+	mlds_output_fully_qualified_name(
+		qual(ModuleName, module_qual, EntityName), !IO),
 	io__write_string(");\n", !IO),
 	mlds_output_calls_to_register_tci(ModuleName, TypeCtorInfoDefns, !IO).
 
@@ -706,7 +708,7 @@
 mlds_output_pragma_export_func_name(ModuleName, Indent,
 		ml_pragma_export(C_name, _MLDS_Name, Signature, Context),
 		!IO) :-
-	Name = qual(ModuleName, export(C_name)),
+	Name = qual(ModuleName, module_qual, export(C_name)),
 	mlds_indent(Context, Indent, !IO),
 	% For functions exported using `pragma export',
 	% we use the default C calling convention.
@@ -878,8 +880,8 @@
 
 mlds_output_pragma_input_arg(ModuleName, Arg, !IO) :-
 	Arg = mlds__argument(Name, Type, _GC_TraceCode),
-	QualName = qual(ModuleName, Name),
-	BoxedQualName = qual(ModuleName, boxed_name(Name)),
+	QualName = qual(ModuleName, module_qual, Name),
+	BoxedQualName = qual(ModuleName, module_qual, boxed_name(Name)),
 	io__write_string("\tMR_MAYBE_BOX_FOREIGN_TYPE(", !IO),
 	mlds_output_pragma_export_type(Type, !IO),
 	io__write_string(", ", !IO),
@@ -893,8 +895,8 @@
 
 mlds_output_pragma_output_arg(ModuleName, Arg, !IO) :-
 	Arg = mlds__argument(Name, Type, _GC_TraceCode),
-	QualName = qual(ModuleName, Name),
-	BoxedQualName = qual(ModuleName, boxed_name(Name)),
+	QualName = qual(ModuleName, module_qual, Name),
+	BoxedQualName = qual(ModuleName, module_qual, boxed_name(Name)),
 	io__write_string("\tMR_MAYBE_UNBOX_FOREIGN_TYPE(", !IO),
 	mlds_output_pragma_export_type(pointed_to_type(Type), !IO),
 	io__write_string(", ", !IO),
@@ -911,7 +913,7 @@
 	io__write_string("\t", !IO),
 	mlds_output_data_decl_ho(mlds_output_type_prefix,
 		mlds_output_type_suffix,
-		qual(ModuleName, boxed_name(Name)), Type, !IO),
+		qual(ModuleName, module_qual, boxed_name(Name)), Type, !IO),
 	io__write_string(";\n", !IO).
 
 :- pred mlds_output_pragma_export_output_defns(mlds_module_name::in,
@@ -922,7 +924,8 @@
 	io__write_string("\t", !IO),
 	mlds_output_data_decl_ho(mlds_output_type_prefix,
 		mlds_output_type_suffix,
-		qual(ModuleName, boxed_name(Name)), pointed_to_type(Type),
+		qual(ModuleName, module_qual, boxed_name(Name)),
+		pointed_to_type(Type),
 		!IO),
 	io__write_string(";\n", !IO).
 
@@ -967,20 +970,21 @@
 		% This is a foreign_type input.  Pass in the already-boxed
 		% value.
 		BoxedName = boxed_name(Name),
-		mlds_output_fully_qualified_name(qual(ModuleName, BoxedName),
-			!IO)
+		mlds_output_fully_qualified_name(
+			qual(ModuleName, module_qual, BoxedName), !IO)
 	; Type = mlds__ptr_type(mlds__foreign_type(c(_))) ->
 		% This is a foreign_type output.  Pass in the address of the
 		% local variable which will hold the boxed value.
 		io__write_string("&", !IO),
 		BoxedName = boxed_name(Name),
-		mlds_output_fully_qualified_name(qual(ModuleName, BoxedName),
-			!IO)
+		mlds_output_fully_qualified_name(
+			qual(ModuleName, module_qual, BoxedName), !IO)
 	;
 		% Otherwise, no boxing or unboxing is needed.
 		% Just cast the argument to the right type.
 		mlds_output_cast(Type, !IO),
-		mlds_output_fully_qualified_name(qual(ModuleName, Name), !IO)
+		mlds_output_fully_qualified_name(
+			qual(ModuleName, module_qual, Name), !IO)
 	).
 
 	%
@@ -1091,7 +1095,8 @@
 		mlds_indent(Context, Indent, !IO),
 		mlds_output_decl_flags(Flags, forward_decl, Name, DefnBody,
 			!IO),
-		mlds_output_decl_body(Indent, qual(ModuleName, Name), Context,
+		mlds_output_decl_body(Indent,
+			qual(ModuleName, module_qual, Name), Context,
 			DefnBody, !IO)
 	).
 
@@ -1169,8 +1174,8 @@
 	),
 	mlds_indent(Context, Indent, !IO),
 	mlds_output_decl_flags(Flags, definition, Name, DefnBody, !IO),
-	mlds_output_defn_body(Indent, qual(ModuleName, Name), Context,
-		DefnBody, !IO).
+	mlds_output_defn_body(Indent, qual(ModuleName, module_qual, Name),
+		Context, DefnBody, !IO).
 
 :- pred mlds_output_decl_body(indent::in, mlds__qualified_entity_name::in,
 	mlds__context::in, mlds__entity_defn::in, io::di, io::uo) is det.
@@ -1265,10 +1270,11 @@
 	% of discriminated union types.)
 	% Here we compute the appropriate qualifier.
 	%
-	Name = qual(ModuleName, UnqualName),
+	Name = qual(ModuleName, QualKind, UnqualName),
 	( UnqualName = type(ClassName, ClassArity) ->
+		globals__io_get_globals(Globals, !IO),
 		ClassModuleName = mlds__append_class_qualifier(ModuleName,
-			ClassName, ClassArity)
+			QualKind, Globals, ClassName, ClassArity)
 	;
 		error("mlds_output_enum_constants")
 	),
@@ -1394,8 +1400,8 @@
 		DefnBody = data(Type, Initializer, _GC_TraceCode)
 	->
 		mlds_indent(Context, Indent, !IO),
-		mlds_output_fully_qualified_name(qual(EnumModuleName, Name),
-			!IO),
+		mlds_output_fully_qualified_name(
+			qual(EnumModuleName, type_qual, Name), !IO),
 		mlds_output_initializer(Type, Initializer, !IO)
 	;
 		error("mlds_output_enum_constant: constant is not data")
@@ -1579,7 +1585,7 @@
 	io__write_char(' ', !IO),
 	io__write_string(CallingConvention, !IO),
 	mlds_output_fully_qualified_name(QualifiedName, !IO),
-	QualifiedName = qual(ModuleName, _),
+	QualifiedName = qual(ModuleName, _, _),
 	mlds_output_params(OutputPrefix, OutputSuffix,
 		Indent, ModuleName, Context, Parameters, !IO),
 	( RetTypes = [RetType2] ->
@@ -1619,7 +1625,7 @@
 mlds_output_param(OutputPrefix, OutputSuffix, Indent, ModuleName, Context,
 		Arg, !IO) :-
 	Arg = mlds__argument(Name, Type, Maybe_GC_TraceCode),
-	QualName = qual(ModuleName, Name),
+	QualName = qual(ModuleName, module_qual, Name),
 	mlds_indent(Context, Indent, !IO),
 	mlds_output_data_decl_ho(OutputPrefix, OutputSuffix, QualName, Type,
 		!IO),
@@ -1674,7 +1680,7 @@
 	io::di, io::uo) is det.
 
 mlds_output_fully_qualified_name(QualifiedName, !IO) :-
-	QualifiedName = qual(_ModuleName, Name),
+	QualifiedName = qual(_ModuleName, _QualKind, Name),
 	(
 		(
 			%
@@ -1705,7 +1711,7 @@
 		%
 		% don't module-qualify main/2
 		%
-		QualifiedName = qual(_ModuleName, Name),
+		QualifiedName = qual(_ModuleName, _QualKind, Name),
 		Name = PredLabel - _ProcId,
 		PredLabel = pred(predicate, no, "main", 2, model_det, no)
 	->
@@ -1718,7 +1724,8 @@
 :- pred mlds_output_fully_qualified(mlds__fully_qualified_name(T)::in,
 	pred(T, io, io)::in(pred(in, di, uo) is det), io::di, io::uo) is det.
 
-mlds_output_fully_qualified(qual(ModuleName, Name), OutputFunc, !IO) :-
+mlds_output_fully_qualified(qual(ModuleName, _QualKind, Name), OutputFunc,
+		!IO) :-
 	SymName = mlds_module_name_to_sym_name(ModuleName),
 	MangledModuleName = sym_name_mangle(SymName),
 	io__write_string(MangledModuleName, !IO),
@@ -2255,7 +2262,7 @@
 	io__write_string("{\n", !IO),
 	( Defns \= [] ->
 		FuncInfo = func_info(FuncName, _),
-		FuncName = qual(ModuleName, _),
+		FuncName = qual(ModuleName, _, _),
 
 		% output forward declarations for any nested functions
 		% defined in this block, in case they are referenced before
@@ -2710,7 +2717,7 @@
 		io__write_string(""", ", !IO),
 		( MaybeCtorName = yes(CtorId) ->
 			io__write_char('"', !IO),
-			CtorId = qual(_ModuleName, CtorDefn),
+			CtorId = qual(_ModuleName, _QualKind, CtorDefn),
 			CtorDefn = ctor_id(CtorName, _CtorArity),
 			c_util__output_quoted_string(CtorName, !IO),
 			io__write_char('"', !IO)
@@ -2915,7 +2922,7 @@
 	io__write_string(", ", !IO),
 	( MaybeCtorName = yes(QualifiedCtorId) ->
 		io__write_char('"', !IO),
-		QualifiedCtorId = qual(_ModuleName, CtorDefn),
+		QualifiedCtorId = qual(_ModuleName, _QualKind, CtorDefn),
 		CtorDefn = ctor_id(CtorName, _CtorArity),
 		c_util__output_quoted_string(CtorName, !IO),
 		io__write_char('"', !IO)
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.97
diff -u -d -r1.97 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	14 Jun 2004 04:16:19 -0000	1.97
+++ compiler/mlds_to_gcc.m	2 Aug 2004 04:23:22 -0000
@@ -392,7 +392,7 @@
 	{ map__init(SymbolTable) },
 	{ map__init(LabelTable) },
 	{ DefnInfo = defn_info(GlobalInfo,
-		qual(MLDS_ModuleName, Name),
+		qual(MLDS_ModuleName, module_qual, Name),
 		SymbolTable, LabelTable) },
 	{ term__context_init(Context) },
 	{ FuncBody = mlds__statement(block([], []),
@@ -531,9 +531,10 @@
 	% 	MR_insert_entry_label(const char *name, MR_Code *addr,
 	% 		const MR_Stack_Layout_Entry *entry_layout);
 	io__write_string("\tMR_insert_entry_label("""),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName)),
+	{ QualifiedName = qual(ModuleName, module_qual, EntityName) },
+	mlds_output_fully_qualified_name(QualifiedName),
 	io__write_string("\t"", "),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName)),
+	mlds_output_fully_qualified_name(QualifiedName),
 	io__write_string(", NULL);\n"),
 	mlds_output_calls_to_init_entry(ModuleName, FuncDefns).
 
@@ -548,7 +549,8 @@
 		[TypeCtorInfoDefn | TypeCtorInfoDefns]) -->
 	{ TypeCtorInfoDefn = mlds__defn(EntityName, _, _, _) },
 	io__write_string("\tMR_register_type_ctor_info(&"),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName)),
+	mlds_output_fully_qualified_name(
+		qual(ModuleName, module_qual, EntityName)),
 	io__write_string(");\n"),
 	mlds_output_calls_to_register_tci(ModuleName, TypeCtorInfoDefns).
 ********************/
@@ -594,7 +596,7 @@
 
 mlds_output_pragma_export_func_name(ModuleName, Indent,
 		ml_pragma_export(C_name, _MLDS_Name, Signature, Context)) -->
-	{ Name = qual(ModuleName, export(C_name)) },
+	{ Name = qual(ModuleName, module_qual, export(C_name)) },
 	mlds_indent(Context, Indent),
 	% For functions exported using `pragma export',
 	% we use the default C calling convention.
@@ -698,7 +700,7 @@
 
 mlds_output_name_with_cast(ModuleName, Name - Type) -->
 	mlds_output_cast(Type),
-	mlds_output_fully_qualified_name(qual(ModuleName, Name)).
+	mlds_output_fully_qualified_name(qual(ModuleName, module_qual, Name)).
 
 ************************/
 
@@ -737,7 +739,7 @@
 	{ Defn = mlds__defn(Name, _, _, _) },
 	{ DefnInfo1 = DefnInfo0 ^ local_vars :=
 		map__det_insert(DefnInfo0 ^ local_vars,
-			qual(ModuleName, Name), GCC_Defn) },
+			qual(ModuleName, module_qual, Name), GCC_Defn) },
 	build_local_defns(Defns, ModuleName, DefnInfo1, DefnInfo).
 
 	% Handle MLDS definitions that are nested inside a type,
@@ -757,7 +759,7 @@
 	( { Name = data(var(FieldName)) } ->
 		{ GCC_FieldName = ml_var_name_to_string(FieldName) },
 		{ FieldTable1 = map__det_insert(FieldTable0,
-			qual(ModuleName, GCC_FieldName),
+			qual(ModuleName, type_qual, GCC_FieldName),
 			GCC_FieldDefn) }
 	;
 		{ unexpected(this_file, "non-var field") }
@@ -772,8 +774,8 @@
 
 gen_defn(ModuleName, Defn, GlobalInfo0, GlobalInfo) -->
 	{ Defn = mlds__defn(Name, Context, Flags, DefnBody) },
-	gen_defn_body(qual(ModuleName, Name), Context, Flags, DefnBody,
-		GlobalInfo0, GlobalInfo).
+	gen_defn_body(qual(ModuleName, module_qual, Name), Context, Flags,
+		DefnBody, GlobalInfo0, GlobalInfo).
 
 :- pred build_local_defn(mlds__defn, defn_info, mlds_module_name,
 		gcc__var_decl, io__state, io__state).
@@ -781,7 +783,8 @@
 
 build_local_defn(Defn, DefnInfo, ModuleName, GCC_Defn) -->
 	{ Defn = mlds__defn(Name, Context, Flags, DefnBody) },
-	build_local_defn_body(qual(ModuleName, Name), DefnInfo, Context, Flags,
+	build_local_defn_body(qual(ModuleName, module_qual, Name),
+		DefnInfo, Context, Flags,
 		DefnBody, GCC_Defn).
 
 :- pred build_field_defn(mlds__defn, mlds_module_name, global_info,
@@ -790,8 +793,8 @@
 
 build_field_defn(Defn, ModuleName, GlobalInfo, GCC_Defn) -->
 	{ Defn = mlds__defn(Name, Context, Flags, DefnBody) },
-	build_field_defn_body(qual(ModuleName, Name), Context, Flags, DefnBody,
-		GlobalInfo, GCC_Defn).
+	build_field_defn_body(qual(ModuleName, type_qual, Name),
+		Context, Flags, DefnBody, GlobalInfo, GCC_Defn).
 
 :- pred gen_defn_body(mlds__qualified_entity_name,
 		mlds__context, mlds__decl_flags, mlds__entity_defn,
@@ -1143,7 +1146,7 @@
 build_local_data_defn(Name, Flags, Type, Initializer, DefnInfo, GCC_Defn) -->
 	build_type(Type, initializer_array_size(Initializer),
 		DefnInfo ^ global_info, GCC_Type),
-	{ Name = qual(_ModuleName, UnqualName) },
+	{ Name = qual(_ModuleName, _QualKind, UnqualName) },
 	( { UnqualName = data(var(VarName0)) } ->
 		{ VarName = VarName0 }
 	;
@@ -1191,7 +1194,7 @@
 build_field_data_defn(Name, Type, Initializer, GlobalInfo, GCC_Defn) -->
 	build_type(Type, initializer_array_size(Initializer),
 		GlobalInfo, GCC_Type),
-	{ Name = qual(_ModuleName, UnqualName) },
+	{ Name = qual(_ModuleName, _QualKind, UnqualName) },
 	( { UnqualName = data(var(VarName)) } ->
 		{ GCC_VarName = ml_var_name_to_string(VarName) },
 		gcc__build_field_decl(GCC_VarName, GCC_Type, GCC_Defn)
@@ -1282,10 +1285,11 @@
 	% of discriminated union types.)
 	% Here we compute the appropriate qualifier.
 	%
-	{ Name = qual(ModuleName, UnqualName) },
+	{ Name = qual(ModuleName, QualKind, UnqualName) },
+	globals__io_get_globals(Globals),
 	{ UnqualName = type(ClassName, ClassArity) ->
 		ClassModuleName = mlds__append_class_qualifier(ModuleName,
-			ClassName, ClassArity)
+			QualKind, Globals, ClassName, ClassArity)
 	;
 		error("mlds_output_enum_constants")
 	},
@@ -1452,7 +1456,8 @@
 		{ DefnBody = data(Type, Initializer) }
 	->
 		mlds_indent(Context, Indent),
-		mlds_output_fully_qualified_name(qual(EnumModuleName, Name)),
+		mlds_output_fully_qualified_name(
+			qual(EnumModuleName, type_qual, Name)),
 		mlds_output_initializer(Type, Initializer)
 	;
 		{ error("mlds_output_enum_constant: constant is not data") }
@@ -1569,7 +1574,7 @@
 :- pred get_qualified_func_name(mlds__qualified_entity_name::in,
 		mlds_module_name::out, string::out, string::out) is det.
 get_qualified_func_name(Name, ModuleName, FuncName, AsmFuncName) :-
-	Name = qual(ModuleName, EntityName),
+	Name = qual(ModuleName, _QualKind, EntityName),
 	get_func_name(EntityName, FuncName, AsmFuncName0),
 	maybe_add_module_qualifier(Name, AsmFuncName0, AsmFuncName).
 
@@ -1693,7 +1698,7 @@
 		{ GCC_ArgVarName = ml_var_name_to_string(ArgVarName) },
 		gcc__build_param_decl(GCC_ArgVarName, GCC_Type, ParamDecl),
 		{ SymbolTable = map__det_insert(SymbolTable0,
-			qual(ModuleName, ArgName), ParamDecl) }
+			qual(ModuleName, module_qual, ArgName), ParamDecl) }
 	;
 		{ error("build_param_types_and_decls: invalid param name") }
 	),
@@ -1752,8 +1757,9 @@
 		% Check to see whether we already have a definition for
 		% this type.
 		%
-		{ Name = qual(ModuleName, TypeName) },
-		{ EntityName = qual(ModuleName, type(TypeName, Arity)) },
+		{ Name = qual(ModuleName, QualKind, TypeName) },
+		{ EntityName = qual(ModuleName, QualKind,
+			type(TypeName, Arity)) },
 		(
 			{ map__search(GlobalInfo ^ type_table, EntityName,
 				gcc_type_info(GCC_TypeDecl, _)) }
@@ -2512,14 +2518,14 @@
 :- func build_qualified_name(mlds__qualified_entity_name) = string.
 
 build_qualified_name(QualifiedName) = AsmName :-
-	QualifiedName = qual(_ModuleName, Name),
+	QualifiedName = qual(_ModuleName, _QualKind, Name),
 	AsmName0 = build_name(Name),
 	maybe_add_module_qualifier(QualifiedName, AsmName0, AsmName).
 
 :- pred maybe_add_module_qualifier(mlds__qualified_entity_name::in,
 		string::in, string::out) is det.
 maybe_add_module_qualifier(QualifiedName, AsmName0, AsmName) :-
-	QualifiedName = qual(ModuleName, Name),
+	QualifiedName = qual(ModuleName, _QualKind, Name),
 	(
 		(
 			%
@@ -2700,7 +2706,7 @@
 gen_stmt(DefnInfo0, block(Defns, Statements), _Context) -->
 	gcc__start_block,
 	{ FuncName = DefnInfo0 ^ func_name },
-	{ FuncName = qual(ModuleName, _) },
+	{ FuncName = qual(ModuleName, _, _) },
 	build_local_defns(Defns, ModuleName, DefnInfo0, DefnInfo),
 	gen_statements(DefnInfo, Statements),
 	gcc__end_block.
@@ -3264,7 +3270,8 @@
 	build_rval(PointerRval, DefnInfo, PointerExpr),
 	gcc__build_pointer_deref(PointerExpr, Expr).
 
-build_lval(var(qual(ModuleName, VarName), _VarType), DefnInfo, Expr) -->
+build_lval(var(qual(ModuleName, QualKind, VarName), _VarType), DefnInfo,
+		Expr) -->
 	%
 	% Look up the variable in the symbol table.
 	% We try the symbol table for local vars first,
@@ -3272,7 +3279,7 @@
 	% symbol table.  If it's not in either of those,
 	% we check if its an RTTI enumeration constant.
 	%
-	{ Name = qual(ModuleName, data(var(VarName))) },
+	{ Name = qual(ModuleName, QualKind, data(var(VarName))) },
 	(
 		{ map__search(DefnInfo ^ local_vars, Name, LocalVarDecl) }
 	->
@@ -3317,8 +3324,8 @@
 						Arity, _Kind))
 		)
 	->
-		ClassName = qual(ModuleName, UnqualClassName),
-		Name = qual(ModuleName, type(UnqualClassName, Arity))
+		ClassName = qual(ModuleName, QualKind, UnqualClassName),
+		Name = qual(ModuleName, QualKind, type(UnqualClassName, Arity))
 	;
 		unexpected(this_file, "non-class_type in get_type_name")
 	).
@@ -3646,8 +3653,8 @@
 	),
 	% convert the label into a entity_name,
 	% so we can use make_func_decl below
-	{ Label = qual(ModuleName, PredLabel - ProcId) },
-	{ Name = qual(ModuleName, function(PredLabel, ProcId,
+	{ Label = qual(ModuleName, QualKind, PredLabel - ProcId) },
+	{ Name = qual(ModuleName, QualKind, function(PredLabel, ProcId,
 		MaybeSeqNum, invalid_pred_id)) },
 	% build a function declaration for the function,
 	% and take its address.
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.141
diff -u -d -r1.141 mlds_to_il.m
--- compiler/mlds_to_il.m	14 Jun 2004 04:16:20 -0000	1.141
+++ compiler/mlds_to_il.m	26 Jul 2004 09:39:44 -0000
@@ -525,8 +525,8 @@
 rename_code_addr(internal(Label, Seq, Signature))
 	= internal(rename_proc_label(Label), Seq, Signature).
 
-rename_proc_label(qual(Module, Name))
-	= qual(append_wrapper_class(Module), Name).
+rename_proc_label(qual(Module, _QualKind, Name))
+	= qual(append_wrapper_class(Module), type_qual, Name).
 
 :- func rename_lval(mlds__lval) = mlds__lval.
 
@@ -565,8 +565,8 @@
 	% Again append a wrapper class qualifier to the var name.
 :- func rename_var(mlds__var, mlds__type) = mlds__var.
 
-rename_var(qual(ModuleName, Name), _Type)
-	= qual(append_wrapper_class(ModuleName), Name).
+rename_var(qual(ModuleName, _QualKind, Name), _Type)
+	= qual(append_wrapper_class(ModuleName), type_qual, Name).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -1297,7 +1297,7 @@
 
 mlds_export_to_mlds_defn(
 	ml_pragma_export(ExportName, EntityName, Params, Context), Defn) :-
-	EntityName = qual(ModuleName, UnqualName),
+	EntityName = qual(ModuleName, _QualKind, UnqualName),
 
 	Params = mlds__func_params(Inputs, RetTypes),
 	list__map_foldl(
@@ -1310,12 +1310,12 @@
 			RV = ml_gen_mlds_var_decl(
 				var(VN), RT, no_initializer, GC_TraceCode,
 				Context),
-			Lval = var(qual(ModuleName, VN), RT)
+			Lval = var(qual(ModuleName, module_qual, VN), RT)
 		), RetTypes, ReturnVars, 0, _),
 
 	EntNameToVarName = (func(EntName) = VarName :-
 		( EntName = data(var(VarName0)) ->
-			VarName = qual(ModuleName, VarName0)
+			VarName = qual(ModuleName, module_qual, VarName0)
 		;
 			error("exported method has argument without var name")
 		)
@@ -1335,7 +1335,7 @@
 		UnqualName = function(PredLabel, ProcId, _MaybeSeq, _PredId)
 	->
 		CodeRval = const(code_addr_const(proc(
-			qual(ModuleName, PredLabel - ProcId),
+			qual(ModuleName, module_qual, PredLabel - ProcId),
 			Signature)))
 	;
 		error("exported entity is not a function")
@@ -1386,8 +1386,8 @@
 		;
 			( { DataName = var(VarName) } ->
 				il_info_get_module_name(ModuleName),
-				{ Lval = var(qual(ModuleName, VarName),
-					MLDSType) },
+				{ Lval = var(qual(ModuleName, module_qual,
+					VarName), MLDSType) },
 				get_load_store_lval_instrs(Lval,
 					LoadMemRefInstrs, StoreLvalInstrs),
 				{ NameString = mangle_mlds_var_name(VarName) }
@@ -1983,7 +1983,7 @@
 			%
 		{ ClassName0 = mlds_type_to_ilds_class_name(DataRep, Type) },
 		( { MaybeCtorName = yes(QualifiedCtorName) } ->
-			{ QualifiedCtorName = qual(_,
+			{ QualifiedCtorName = qual(_, _,
 				ctor_id(CtorName, CtorArity)) },
 			{ CtorType = entity_name_to_ilds_id(
 				type(CtorName, CtorArity)) },
@@ -3131,8 +3131,8 @@
 :- func mlds_class_name_to_ilds_class_name(mlds__class, arity) =
 	ilds__class_name.
 
-mlds_class_name_to_ilds_class_name(
-		qual(MldsModuleName, MldsClassName0), Arity) = IldsClassName :-
+mlds_class_name_to_ilds_class_name(QualClassName, Arity) = IldsClassName :-
+	QualClassName = qual(MldsModuleName, _QualKind, MldsClassName0),
 	MldsClassName = string__format("%s_%d", [s(MldsClassName0), i(Arity)]),
 	IldsClassName = append_toplevel_class_name(
 		mlds_module_name_to_class_name(MldsModuleName), MldsClassName).
@@ -3279,7 +3279,7 @@
 :- func make_static_fieldref(il_data_rep, mlds__var, mlds__type)
 	 = fieldref.
 make_static_fieldref(DataRep, Var, VarType) = FieldRef :-
-	Var = qual(ModuleName, VarName),
+	Var = qual(ModuleName, _QualKind, VarName),
 	mangle_mlds_var(Var, MangledVarStr),
 	mangle_dataname_module(yes(var(VarName)), ModuleName, NewModuleName),
 	ClassName = mlds_module_name_to_class_name(NewModuleName),
@@ -3383,7 +3383,7 @@
 	error("unimplemented: mangling tabling_pointer").
 
 	% We turn procedures into methods of classes.
-mangle_mlds_proc_label(qual(ModuleName, PredLabel - ProcId), MaybeSeqNum,
+mangle_mlds_proc_label(qual(ModuleName, _, PredLabel - ProcId), MaybeSeqNum,
 		ClassName, PredStr) :-
 	ClassName = mlds_module_name_to_class_name(ModuleName),
 	predlabel_to_id(PredLabel, ProcId, MaybeSeqNum, PredStr).
@@ -3402,7 +3402,7 @@
 	% Any valid Mercury identifier will be fine here too.
 	% We quote all identifiers before we output them, so
 	% even funny characters should be fine.
-mangle_mlds_var(qual(_ModuleName, VarName), Str) :-
+mangle_mlds_var(qual(_ModuleName, _, VarName), Str) :-
 	Str = mangle_mlds_var_name(VarName).
 
 :- func mangle_mlds_var_name(mlds__var_name) = string.
@@ -3502,7 +3502,7 @@
 is_local_field(Var, VarType, Info, FieldRef) :-
 	mangle_mlds_var(Var, VarName),
 	set__member(VarName, Info ^ field_names),
-	Var = qual(ModuleName, _),
+	Var = qual(ModuleName, _, _),
 	ClassName = mlds_module_name_to_class_name(ModuleName),
 	FieldRef = make_fieldref(
 			mlds_type_to_ilds_type(Info ^ il_data_rep, VarType),
@@ -3649,7 +3649,7 @@
 		),
 		CastClassInstrs = empty
 	;
-		FieldNum = named_field(qual(ModuleName, FieldId), _CtorType),
+		FieldNum = named_field(qual(ModuleName, _, FieldId), _CtorType),
 		% The MLDS doesn't record which qualifiers are class qualifiers
 		% and which are namespace qualifiers... we first generate
 		% a name for the CtorClass as if it wasn't nested, and then
@@ -3728,7 +3728,7 @@
 		Entity = mlds__data(MLDSType0, _Initializer, _GC_TraceCode)
 	->
 		mangle_dataname(DataName, MangledDataName),
-		mangle_mlds_var(qual(ModuleName,
+		mangle_mlds_var(qual(ModuleName, module_qual,
 			var_name(MangledDataName, no)), Id),
 		MLDSType0 = MLDSType
 	;
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.60
diff -u -d -r1.60 mlds_to_java.m
--- compiler/mlds_to_java.m	14 Jun 2004 04:16:21 -0000	1.60
+++ compiler/mlds_to_java.m	2 Aug 2004 06:23:28 -0000
@@ -113,7 +113,7 @@
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_io.
 
-:- import_module bool, int, string, library, list, map, set.
+:- import_module bool, int, char, string, library, list, map, set.
 :- import_module assoc_list, term, std_util, require.
 
 %-----------------------------------------------------------------------------%
@@ -283,26 +283,36 @@
 	string__to_char_list(String0, String1),
 	string__from_rev_char_list(String1, String).
 
-:- pred mangle_mlds_sym_name_for_java(sym_name::in, string::in,
+:- pred mangle_mlds_sym_name_for_java(sym_name::in, qual_kind::in, string::in,
 	string::out) is det.
 
-mangle_mlds_sym_name_for_java(unqualified(Name), _Qualifier, JavaSafeName) :-
-	MangledName = name_mangle(Name),
+mangle_mlds_sym_name_for_java(unqualified(Name), QualKind, _QualifierOp,
+		JavaSafeName) :-
+	(
+		QualKind = module_qual,
+		FlippedName = Name
+	;
+		QualKind = type_qual,
+		FlippedName = flip_initial_case(Name)
+	),
+	MangledName = name_mangle(FlippedName),
 	JavaSafeName = valid_symbol_name(MangledName).
-mangle_mlds_sym_name_for_java(qualified(ModuleName, PlainName), Qualifier,
-		MangledName) :-
-	mangle_mlds_sym_name_for_java(ModuleName, Qualifier,
+mangle_mlds_sym_name_for_java(qualified(ModuleName0, PlainName), QualKind,
+		QualifierOp, JavaSafeName) :-
+	mangle_mlds_sym_name_for_java(ModuleName0, module_qual, QualifierOp,
 		MangledModuleName),
-	MangledPlainName = name_mangle(PlainName),
+	(
+		QualKind = module_qual,
+		FlippedPlainName = PlainName
+	;
+		QualKind = type_qual,
+		FlippedPlainName = flip_initial_case(PlainName)
+	),
+	MangledPlainName = name_mangle(FlippedPlainName),
 	JavaSafePlainName = valid_symbol_name(MangledPlainName),
-	java_qualify_mangled_name(MangledModuleName, JavaSafePlainName,
-		Qualifier, MangledName).
-
-:- pred java_qualify_mangled_name(string::in, string::in, string::in,
-	string::out) is det.
-
-java_qualify_mangled_name(Module0, Name0, Qualifier, Name) :-
-	string__append_list([Module0, Qualifier, Name0], Name).
+	string__append_list(
+		[MangledModuleName, QualifierOp, JavaSafePlainName],
+		JavaSafeName).
 
 %-----------------------------------------------------------------------------%
 %
@@ -722,7 +732,7 @@
 	Context = mlds__make_context(term__context_init),
 	InterfaceModuleName = mercury_module_name_to_mlds(
 			qualified(unqualified("mercury"), "runtime")),
-	Interface = qual(InterfaceModuleName, "MethodPtr"),
+	Interface = qual(InterfaceModuleName, module_qual, "MethodPtr"),
 	generate_addr_wrapper_class(Interface, Context, CodeAddr, ClassDefn),
 	!:Defns = [ ClassDefn | !.Defns ],
 	generate_code_addr_wrappers(Indent, CodeAddrs, !Defns).
@@ -739,7 +749,7 @@
 		CodeAddr = mlds__internal(ProcLabel, SeqNum, _FuncSig),
 		MaybeSeqNum = yes(SeqNum)
 	),
-	ProcLabel = mlds__qual(ModuleQualifier, PredLabel - ProcID),
+	ProcLabel = mlds__qual(ModuleQualifier, QualKind, PredLabel - ProcID),
 	PredName = make_pred_name_string(PredLabel, ProcID, MaybeSeqNum),
 	%
 	% Create class components.
@@ -757,8 +767,9 @@
 	% method (predicate) name.
 	%
 	ModuleQualifierSym = mlds_module_name_to_sym_name(ModuleQualifier),
-	mangle_mlds_sym_name_for_java(ModuleQualifierSym, "__", ModuleNameStr),
-	ClassEntityName = "AddrOf__" ++ ModuleNameStr ++
+	mangle_mlds_sym_name_for_java(ModuleQualifierSym, QualKind, "__",
+		ModuleNameStr),
+	ClassEntityName = "addrOf__" ++ ModuleNameStr ++
 		"__" ++ PredName,
 	MangledClassEntityName = name_mangle(ClassEntityName),
 	%
@@ -815,7 +826,7 @@
 	% original method.
 	%
 	ReturnVarName = var_name("return_value", no),
-	ReturnVar = mlds__qual(ModuleName, ReturnVarName),
+	ReturnVar = mlds__qual(ModuleName, module_qual, ReturnVarName),
 	%
 	% Create a declaration for this variable.
 	%
@@ -839,7 +850,7 @@
 	%
 	% Create the call to the original method:
 	%
-	CallArgLabel = mlds__qual(ModuleName, MethodArgVariable),
+	CallArgLabel = mlds__qual(ModuleName, module_qual, MethodArgVariable),
 	generate_call_method_args(OrigArgTypes, CallArgLabel, 0, [], CallArgs),
 	CallRval = mlds__const(mlds__code_addr_const(CodeAddr)),
         %
@@ -1099,13 +1110,13 @@
 		% must be given in `pragma java_code' in the same module.)
 		io__write_string("/* external:\n", !IO),
 		output_decl_flags(Flags, Name, !IO),
-		output_defn_body(Indent, qual(ModuleName, Name), CtorData,
-			Context, DefnBody, !IO),
+		output_defn_body(Indent, qual(ModuleName, module_qual, Name),
+			CtorData, Context, DefnBody, !IO),
 		io__write_string("*/\n", !IO)
 	;
 		output_decl_flags(Flags, Name, !IO),
-		output_defn_body(Indent, qual(ModuleName, Name), CtorData,
-			Context, DefnBody, !IO)
+		output_defn_body(Indent, qual(ModuleName, module_qual, Name),
+			CtorData, Context, DefnBody, !IO)
 	).
 
 :- pred output_defn_body(indent::in, mlds__qualified_entity_name::in,
@@ -1132,7 +1143,7 @@
 	mlds__context::in, mlds__class_defn::in, io::di, io::uo) is det.
 
 output_class(Indent, Name, _Context, ClassDefn, !IO) :-
-	Name = qual(ModuleName, UnqualName),
+	Name = qual(ModuleName, _QualKind, UnqualName),
 	( UnqualName = type(_, _) ->
 		true
 	;
@@ -1145,7 +1156,7 @@
 	;
 		io__write_string("class ", !IO)
 	),
-	output_class_name(UnqualName, !IO),
+	output_class_name_and_arity(UnqualName, !IO),
 	io__nl(!IO),
 	output_extends_list(Indent + 1, BaseClasses, !IO),
 	output_implements_list(Indent + 1, Implements, !IO),
@@ -1192,9 +1203,13 @@
 :- pred output_interface(mlds__interface_id::in, io::di, io::uo) is det.
 
 output_interface(Interface, !IO) :-
-	 ( Interface = class_type(qual(ModuleQualifier, Name), Arity, _) ->
+	(
+		Interface = class_type(qual(ModuleQualifier, QualKind, Name),
+	 		Arity, _)
+	->
 		SymName = mlds_module_name_to_sym_name(ModuleQualifier),
-		mangle_mlds_sym_name_for_java(SymName, ".", ModuleName),
+		mangle_mlds_sym_name_for_java(SymName, QualKind, ".",
+			ModuleName),
 		io__format("%s.%s", [s(ModuleName), s(Name)], !IO),
 		%
 		% Check if the interface is one of the ones in the runtime
@@ -1231,7 +1246,7 @@
 
 output_class_body(Indent, mlds__enum, Name, AllMembers, _, !IO) :-
 	list__filter(defn_is_const, AllMembers, EnumConsts),
-	Name = qual(ModuleName, UnqualName),
+	Name = qual(ModuleName, _QualKind, UnqualName),
 	output_enum_constants(Indent + 1, ModuleName, EnumConsts, !IO),
 	indent_line(Indent + 1, !IO),
 	io__write_string("public int value;\n\n", !IO),
@@ -1309,7 +1324,7 @@
 :- pred output_data_decl(mlds__qualified_entity_name::in, mlds__type::in,
 	io::di, io::uo) is det.
 
-output_data_decl(qual(_, Name), Type, !IO) :-
+output_data_decl(qual(_, _, Name), Type, !IO) :-
 	output_type(Type, !IO),
 	io__write_char(' ', !IO),
 	output_name(Name, !IO).
@@ -1529,7 +1544,7 @@
 		io__write_string("java.lang.Object []", !IO)
 	),
 	io__write_char(' ', !IO),
-	QualifiedName = qual(ModuleName, Name),
+	QualifiedName = qual(ModuleName, _QualKind, Name),
 	output_name(Name, !IO),
 	output_params(Indent, ModuleName, Context, Parameters, !IO).
 
@@ -1574,7 +1589,7 @@
 	% and is also necessary in the case of local variables
 	% and function parameters, which must not be qualified.
 	%
-	QualifiedName = qual(ModuleName, Name),
+	QualifiedName = qual(ModuleName, _QualKind, Name),
 	( ModuleName = CurrentModuleName ->
 		output_name(Name, !IO)
 	;
@@ -1598,14 +1613,12 @@
 	pred(T, io, io)::pred(in, di, uo) is det, string::in, io::di,
 	io::uo) is det.
 
-output_fully_qualified(qual(ModuleName, Name), OutputFunc, Qualifier, !IO) :-
+output_fully_qualified(qual(ModuleName, QualKind, Name), OutputFunc,
+		Qualifier, !IO) :-
 	SymName = mlds_module_name_to_sym_name(ModuleName),
-	mangle_mlds_sym_name_for_java(SymName, Qualifier,
+	mangle_mlds_sym_name_for_java(SymName, QualKind, Qualifier,
 		MangledModuleName),
-	% XXX Name mangling code should be put here when we start enforcing
-	%     Java's naming convention.
-	MangledModuleName = JavaMangledName,
-	io__write_string(JavaMangledName, !IO),
+	io__write_string(MangledModuleName, !IO),
 	io__write_string(Qualifier, !IO),
 	OutputFunc(Name, !IO).
 
@@ -1614,21 +1627,31 @@
 output_module_name(ModuleName, !IO) :-
 	io__write_string(sym_name_mangle(ModuleName), !IO).
 
-:- pred output_class_name(mlds__entity_name::in, io::di, io::uo) is det.
+:- pred output_class_name_and_arity(mlds__entity_name::in, io::di, io::uo)
+	is det.
 
-output_class_name(type(Name, Arity), !IO) :-
-	MangledName = name_mangle(Name),
-	io__format("%s_%d", [s(MangledName), i(Arity)], !IO).
+output_class_name_and_arity(type(Name, Arity)) -->
+	output_class_name(Name),
+	io__format("_%d", [i(Arity)]).
+output_class_name_and_arity(data(_)) -->
+	{ unexpected(this_file, "output_class_name_and_arity") }.
+output_class_name_and_arity(function(_, _, _, _)) -->
+	{ unexpected(this_file, "output_class_name_and_arity") }.
+output_class_name_and_arity(export(_)) -->
+	{ unexpected(this_file, "output_class_name_and_arity") }.
 
-output_class_name(data(_), !IO).
-output_class_name(function(_, _, _, _), !IO).
-output_class_name(export(_), !IO).
+:- pred output_class_name(mlds__class_name::in, io::di, io::uo) is det.
+
+output_class_name(Name, !IO) :-
+	MangledName = name_mangle(Name),
+	% By convention, class names should start with a capital letter.
+	UppercaseMangledName = flip_initial_case(MangledName),
+	io__write_string(UppercaseMangledName, !IO).
 
 :- pred output_name(mlds__entity_name::in, io::di, io::uo) is det.
 
 output_name(type(Name, Arity), !IO) :-
-	MangledName = name_mangle(Name),
-	io__format("%s_%d", [s(MangledName), i(Arity)], !IO).
+	output_class_name_and_arity(type(Name, Arity), !IO).
 output_name(data(DataName), !IO) :-
 	output_data_name(DataName, !IO).
 output_name(function(PredLabel, ProcId, MaybeSeqNum, _PredId), !IO) :-
@@ -1749,24 +1772,18 @@
 		ForeignType = c(_),
 		unexpected(this_file, "output_type: c foreign_type")
 	;
-		 ForeignType = il(_),
-		 unexpected(this_file, "output_type: il foreign_type")
-	).
-output_type(mlds__class_type(Name, Arity, ClassKind), !IO) :-
-	( ClassKind = mlds__enum ->
-		output_fully_qualified(Name, output_mangled_name, ".", !IO),
-		io__format("_%d", [i(Arity)], !IO)
-	;
-		output_fully_qualified(Name, output_mangled_name, ".", !IO),
-		io__format("_%d", [i(Arity)], !IO)
+		ForeignType = il(_),
+		unexpected(this_file, "output_type: il foreign_type")
 	).
+output_type(mlds__class_type(Name, Arity, _ClassKind), !IO) :-
+	% We used to treat enumerations specially here, outputting
+	% them as "int", but now we do the same for all classes.
+	output_fully_qualified(Name, output_class_name, ".", !IO),
+	io__format("_%d", [i(Arity)], !IO).
 output_type(mlds__ptr_type(Type), !IO) :-
-	( Type = mlds__class_type(Name, Arity, _Kind) ->
-		output_fully_qualified(Name, output_mangled_name, ".", !IO),
-		io__format("_%d", [i(Arity)], !IO)
-	;
-		output_type(Type, !IO)
-	).
+	% XXX should we report an error here, if the type pointed to
+	%     is not a class type?
+	output_type(Type, !IO).
 output_type(mlds__array_type(Type), !IO) :-
 	output_type(Type, !IO),
 	io__write_string("[]", !IO).
@@ -2007,7 +2024,7 @@
 
 :- func mod_name(mlds__fully_qualified_name(T)) = mlds_module_name.
 
-mod_name(qual(ModuleName, _)) = ModuleName.
+mod_name(qual(ModuleName, _, _)) = ModuleName.
 
 :- pred output_statements(indent::in, func_info::in,
 	list(mlds__statement)::in, exit_methods::out, io::di, io::uo) is det.
@@ -2674,10 +2691,9 @@
 	->
 		output_type(Type, !IO),
 		io__write_char('.', !IO),
-		QualifiedCtorId = qual(_ModuleName, CtorDefn),
+		QualifiedCtorId = qual(_ModuleName, _QualKind, CtorDefn),
 		CtorDefn = ctor_id(CtorName, CtorArity),
-		MangledCtorName = name_mangle(CtorName),
-		io__format("%s_%d", [s(MangledCtorName), i(CtorArity)], !IO)
+		output_class_name_and_arity(type(CtorName, CtorArity), !IO)
 	;
 		output_type(Type, !IO)
 	),
@@ -2823,7 +2839,7 @@
 output_lval(field(_, PtrRval, named_field(FieldName, CtorType), _, _),
 		ModuleName, !IO) :-
 	(
-		FieldName = qual(_, UnqualFieldName),
+		FieldName = qual(_, _, UnqualFieldName),
 	 	MangledFieldName = name_mangle(UnqualFieldName),
 	  	MangledFieldName = "data_tag"
 	->
@@ -2847,14 +2863,14 @@
 			% the actual variable
 		io__write_string(").", !IO)
 	),
-	FieldName = qual(_, UnqualFieldName),
+	FieldName = qual(_, _, UnqualFieldName),
 	output_valid_mangled_name(UnqualFieldName, !IO).    % the field name
 
 output_lval(mem_ref(Rval, _Type), ModuleName, !IO) :-
 	output_bracketed_rval(Rval, ModuleName, !IO).
 
-output_lval(var(qual(ModName, Name), _), CurrentModuleName, !IO) :-
-	output_maybe_qualified_name(qual(ModName, data(var(Name))),
+output_lval(var(qual(ModName, QualKind, Name), _), CurrentModuleName, !IO) :-
+	output_maybe_qualified_name(qual(ModName, QualKind, data(var(Name))),
 		CurrentModuleName, !IO).
 
 :- pred output_mangled_name(string::in, io::di, io::uo) is det.
@@ -3240,7 +3256,7 @@
 
 mlds_output_data_addr(data_addr(ModuleQualifier, DataName), !IO) :-
 	SymName = mlds_module_name_to_sym_name(ModuleQualifier),
-	mangle_mlds_sym_name_for_java(SymName, ".", ModuleName),
+	mangle_mlds_sym_name_for_java(SymName, module_qual, ".", ModuleName),
 	io__write_string(ModuleName, !IO),
 	io__write_string(".", !IO),
 	output_data_name(DataName, !IO).
Index: compiler/mlds_to_managed.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_managed.m,v
retrieving revision 1.13
diff -u -d -r1.13 mlds_to_managed.m
--- compiler/mlds_to_managed.m	14 Jun 2004 04:16:21 -0000	1.13
+++ compiler/mlds_to_managed.m	26 Jul 2004 09:05:00 -0000
@@ -655,7 +655,7 @@
 	write_rval(Lang, Rval),
 	io__write_string(")"),
 	write_field_selector(Lang),
-	{ FieldId = qual(_, FieldName) },
+	{ FieldId = qual(_, _, FieldName) },
 	io__write_string(FieldName).
 write_lval(Lang, field(_, Rval, offset(OffSet), _, _)) -->
 	io__write_string("("),
@@ -672,7 +672,7 @@
 	),
 	write_rval(Lang, Rval).
 write_lval(_Lang, var(Var, _VarType)) -->
-	{ Var = qual(_, VarName) },
+	{ Var = qual(_, _, VarName) },
 	write_mlds_var_name_for_parameter(VarName).
 
 :- pred write_field_selector(foreign_language::in(managed_lang),
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.54
diff -u -d -r1.54 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m	30 Jun 2004 02:48:12 -0000	1.54
+++ compiler/rtti_to_mlds.m	26 Jul 2004 08:49:55 -0000
@@ -1432,7 +1432,7 @@
         ml_gen_pred_label_from_rtti(ModuleInfo, RttiProcId, PredLabel,
 		PredModule),
 	ProcId = RttiProcId ^ proc_id,
-        QualifiedProcLabel = qual(PredModule, PredLabel - ProcId),
+        QualifiedProcLabel = qual(PredModule, module_qual, PredLabel - ProcId),
 	Params = ml_gen_proc_params_from_rtti(ModuleInfo, RttiProcId),
 	Signature = mlds__get_func_signature(Params),
 	ProcAddrRval = const(code_addr_const(proc(QualifiedProcLabel,
@@ -1506,7 +1506,8 @@
 	% Perhaps we should be using an enumeration type here,
 	% rather than `mlds__native_int_type'.
 	Type = mlds__native_int_type,
-	Rval = lval(var(qual(MLDS_Module, var_name(Name, no)), Type)).
+	Rval = lval(var(qual(MLDS_Module, module_qual, var_name(Name, no)),
+		Type)).
 
 %-----------------------------------------------------------------------------%
 %
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.104
diff -u -d -r1.104 builtin.m
--- library/builtin.m	19 Jul 2004 04:36:12 -0000	1.104
+++ library/builtin.m	2 Aug 2004 06:22:05 -0000
@@ -761,11 +761,11 @@
 }
 ").
 :- pragma foreign_code("Java", "
-	public static class void_0
+	public static class Void_0
 	{
 		// Make the constructor private to ensure that we can
 		// never create an instance of this class.
-		private void_0()
+		private Void_0()
 		{
 		}
 	}
@@ -779,17 +779,17 @@
 	// Definitions of builtin types
 	//
 
-	public static class tuple_0
+	public static class Tuple_0
 	{
 		// stub only
 	}
 
-	public static class func_0
+	public static class Func_0
 	{
 		// stub only
 	}
 
-	public static class c_pointer_0
+	public static class C_pointer_0
 	{
 		// stub only
 	}
@@ -806,7 +806,7 @@
 		throw new java.lang.Error (""unify/3 not implemented"");
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	compare_3_p_0 (mercury.runtime.TypeInfo_Struct ti,
 		       java.lang.Object x, java.lang.Object y)
 	{
@@ -814,28 +814,28 @@
 		throw new java.lang.Error (""compare/3 not implemented"");
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	compare_3_p_1 (mercury.runtime.TypeInfo_Struct ti,
 		       java.lang.Object x, java.lang.Object y)
 	{
 		return compare_3_p_0(ti, x, y);
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	compare_3_p_2 (mercury.runtime.TypeInfo_Struct ti,
 		       java.lang.Object x, java.lang.Object y)
 	{
 		return compare_3_p_0(ti, x, y);
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	compare_3_p_3 (mercury.runtime.TypeInfo_Struct ti,
 		       java.lang.Object x, java.lang.Object y)
 	{
 		return compare_3_p_0(ti, x, y);
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	compare_representation_3_p_0 (mercury.runtime.TypeInfo_Struct ti,
 		       java.lang.Object x, java.lang.Object y)
 	{
@@ -850,7 +850,7 @@
 
 	public static boolean
 	__Unify____tuple_0_0
-		(mercury.builtin.tuple_0 x, mercury.builtin.tuple_0 y)
+		(mercury.builtin.Tuple_0 x, mercury.builtin.Tuple_0 y)
 	{
 		// stub only
 		throw new java.lang.Error (""unify/2 for tuple types not implemented"");
@@ -858,7 +858,7 @@
 
 	public static boolean
 	__Unify____func_0_0
-		(mercury.builtin.func_0 x, mercury.builtin.func_0 y)
+		(mercury.builtin.Func_0 x, mercury.builtin.Func_0 y)
 	{
 		// stub only
 		throw new java.lang.Error (""unify/2 for tuple types not implemented"");
@@ -875,7 +875,7 @@
 
 	public static boolean
 	__Unify____void_0_0
-		(mercury.builtin.void_0 x, mercury.builtin.void_0 y)
+		(mercury.builtin.Void_0 x, mercury.builtin.Void_0 y)
 	{
 		// there should never be any values of type void/0
 		throw new java.lang.Error (""unify/2 called for void type"");
@@ -885,24 +885,24 @@
 	// Type-specific comparison routines for builtin types
 	//
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	__Compare____tuple_0_0
-		(mercury.builtin.tuple_0 x, mercury.builtin.tuple_0 y)
+		(mercury.builtin.Tuple_0 x, mercury.builtin.Tuple_0 y)
 	{
 		// stub only
 		throw new java.lang.Error
 			(""compare/3 for tuple types not implemented"");
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	__Compare____func_0_0
-		(mercury.builtin.func_0 x, mercury.builtin.func_0 y)
+		(mercury.builtin.Func_0 x, mercury.builtin.Func_0 y)
 	{
 		// comparing values of higher-order types is a run-time error
 		throw new java.lang.Error (""compare/3 called for func type"");
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	__Compare____c_pointer_0_0
 		(java.lang.Object x, java.lang.Object y)
 	{
@@ -911,9 +911,9 @@
 			(""compare/3 called for c_pointer type"");
 	}
 
-	public static comparison_result_0
+	public static Comparison_result_0
 	__Compare____void_0_0
-		(mercury.builtin.void_0 x, mercury.builtin.void_0 y)
+		(mercury.builtin.Void_0 x, mercury.builtin.Void_0 y)
 	{
 		// there should never be any values of type void/0
 		throw new java.lang.Error (""compare/3 called for void type"");
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.324
diff -u -d -r1.324 io.m
--- library/io.m	19 Jul 2004 04:36:12 -0000	1.324
+++ library/io.m	2 Aug 2004 07:26:07 -0000
@@ -1488,9 +1488,9 @@
 :- pragma foreign_code("Java",
 "
 	static java.lang.Object	ML_io_stream_db =
-		new mercury.tree234.tree234_2.empty_0();
+		new mercury.tree234.Tree234_2.Empty_0();
 	static java.lang.Object	ML_io_user_globals =
-		new mercury.tree234.tree234_2.empty_0();
+		new mercury.tree234.Tree234_2.Empty_0();
 ").
 
 :- type io__stream_putback ==	map(io__stream_id, list(char)).
@@ -2502,14 +2502,14 @@
 	// directories, and for everything else it just returns unknown.
 
 	if (file.isFile()) {
-		Result = new mercury.io.res_1.ok_1(new mercury.io.file_type_0(
-			mercury.io.file_type_0.regular_file));
+		Result = new mercury.io.Res_1.Ok_1(new mercury.io.File_type_0(
+			mercury.io.File_type_0.regular_file));
 	} else if (file.isDirectory()) {
-		Result = new mercury.io.res_1.ok_1(new mercury.io.file_type_0(
-			mercury.io.file_type_0.directory));
+		Result = new mercury.io.Res_1.Ok_1(new mercury.io.File_type_0(
+			mercury.io.File_type_0.directory));
 	} else {
-		Result = new mercury.io.res_1.ok_1(new mercury.io.file_type_0(
-			mercury.io.file_type_0.unknown));
+		Result = new mercury.io.Res_1.Ok_1(new mercury.io.File_type_0(
+			mercury.io.File_type_0.unknown));
 	}
 ").
 
@@ -2624,13 +2624,13 @@
 	java.lang.String permissions = null;
 
 	if (access_types_includes_read_1_p_0(
-		(mercury.list.list_1) AccessTypes))
+		(mercury.list.List_1) AccessTypes))
 	{
 		permissions = ""read"";
 	}
 
 	if (access_types_includes_write_1_p_0(
-		(mercury.list.list_1) AccessTypes))
+		(mercury.list.List_1) AccessTypes))
 	{
 		if (permissions == null) {
 			permissions = ""write"";
@@ -2640,7 +2640,7 @@
 	}
 
 	if (access_types_includes_execute_1_p_0(
-		(mercury.list.list_1) AccessTypes))
+		(mercury.list.List_1) AccessTypes))
 	{
 		if (permissions == null) {
 			permissions = ""execute"";
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.137
diff -u -d -r1.137 private_builtin.m
--- library/private_builtin.m	31 May 2004 04:13:01 -0000	1.137
+++ library/private_builtin.m	26 Jul 2004 01:27:51 -0000
@@ -1322,12 +1322,12 @@
 %-----------------------------------------------------------------------------%
 
 :- pragma foreign_code("Java", "
-    public static class ref_1
+    public static class Ref_1
     {
      	// XXX stub only
     }
 
-    public static class heap_pointer_0
+    public static class Heap_pointer_0
     {
      	// XXX stub only
     }
@@ -1400,8 +1400,8 @@
 
 	public static boolean
 	__Unify____ref_1_0(mercury.runtime.TypeInfo_Struct ti,
-		mercury.private_builtin.ref_1 x,
-		mercury.private_builtin.ref_1 y)
+		mercury.private_builtin.Ref_1 x,
+		mercury.private_builtin.Ref_1 y)
 	{
 		// stub only
 		throw new java.lang.Error
@@ -1409,8 +1409,8 @@
 	}
 
 	public static boolean
-	__Unify____heap_pointer_0_0 (mercury.private_builtin.heap_pointer_0 x,
-		mercury.private_builtin.heap_pointer_0 y)
+	__Unify____heap_pointer_0_0 (mercury.private_builtin.Heap_pointer_0 x,
+		mercury.private_builtin.Heap_pointer_0 y)
 	{
 		// stub only
 		throw new java.lang.Error(""unify/2 for type heap_pointer/0"");
@@ -1453,25 +1453,25 @@
 			(""unify/2 for type typeclass_info/1"");
 	}
 
-	public static mercury.builtin.comparison_result_0
+	public static mercury.builtin.Comparison_result_0
 	__Compare____ref_1_0(mercury.runtime.TypeInfo_Struct ti,
-		mercury.private_builtin.ref_1 x,
-		mercury.private_builtin.ref_1 y)
+		mercury.private_builtin.Ref_1 x,
+		mercury.private_builtin.Ref_1 y)
 	{
 		// stub only
 		throw new java.lang.Error
 		    (""called compare/3 for type private_builtin.ref"");
 	}
 
-	public static mercury.builtin.comparison_result_0
-	__Compare____heap_pointer_0_0 (mercury.private_builtin.heap_pointer_0 x,
-		mercury.private_builtin.heap_pointer_0 y)
+	public static mercury.builtin.Comparison_result_0
+	__Compare____heap_pointer_0_0 (mercury.private_builtin.Heap_pointer_0 x,
+		mercury.private_builtin.Heap_pointer_0 y)
 	{
 		// stub only
 		throw new java.lang.Error(""compare/2 for type heap_pointer/0"");
 	}
 
-	public static mercury.builtin.comparison_result_0
+	public static mercury.builtin.Comparison_result_0
 	__Compare____type_ctor_info_1_0(mercury.runtime.TypeInfo_Struct ti,
 		mercury.runtime.TypeCtorInfo_Struct x,
 		mercury.runtime.TypeCtorInfo_Struct y)
@@ -1481,7 +1481,7 @@
 			(""compare/2 for type type_ctor_info/1"");
 	}
 
-	public static mercury.builtin.comparison_result_0
+	public static mercury.builtin.Comparison_result_0
 	__Compare____type_info_1_0(mercury.runtime.TypeInfo_Struct ti,
 		mercury.runtime.TypeInfo_Struct x,
 		mercury.runtime.TypeInfo_Struct y)
@@ -1491,7 +1491,7 @@
 			(""compare/2 for type type_info/1"");
 	}
 
-	public static mercury.builtin.comparison_result_0
+	public static mercury.builtin.Comparison_result_0
 	__Compare____base_typeclass_info_1_0(mercury.runtime.TypeInfo_Struct ti,
 		java.lang.Object[] x, java.lang.Object[] y)
 	{
@@ -1499,7 +1499,7 @@
 		throw new java.lang.Error(""compare/2 for type typeclass_info/1"");
 	}
 
-	public static mercury.builtin.comparison_result_0
+	public static mercury.builtin.Comparison_result_0
 	__Compare____typeclass_info_1_0(mercury.runtime.TypeInfo_Struct ti,
 		java.lang.Object[] x, java.lang.Object[] y)
 	{
Index: library/rtti_implementation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.53
diff -u -d -r1.53 rtti_implementation.m
--- library/rtti_implementation.m	28 Jun 2004 04:49:58 -0000	1.53
+++ library/rtti_implementation.m	2 Aug 2004 06:41:23 -0000
@@ -1896,7 +1896,7 @@
 "
 	mercury.runtime.Sectag_Locn SL_struct = PTagEntry.sectag_locn;
 
-	SectagLocn = new mercury.rtti_implementation.sectag_locn_0(
+	SectagLocn = new mercury.rtti_implementation.Sectag_locn_0(
 			SL_struct.value);
 ").
 
@@ -2154,7 +2154,7 @@
 	type_ctor_rep(TypeCtorInfo::in) = (TypeCtorRep::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	TypeCtorRep = new type_ctor_rep_0(
+	TypeCtorRep = new Type_ctor_rep_0(
 			((mercury.runtime.TypeCtorInfo_Struct) TypeCtorInfo).
 			type_ctor_rep.value);
 ").
Index: library/type_desc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/type_desc.m,v
retrieving revision 1.26
diff -u -d -r1.26 type_desc.m
--- library/type_desc.m	15 Mar 2004 23:49:36 -0000	1.26
+++ library/type_desc.m	2 Aug 2004 07:25:24 -0000
@@ -253,7 +253,7 @@
 	type_of(_Value::unused) = (TypeInfo::out),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
-	TypeInfo = new mercury.type_desc.type_desc_0(
+	TypeInfo = new mercury.type_desc.Type_desc_0(
 			(mercury.runtime.TypeInfo_Struct) TypeInfo_for_T);
 ").
 
@@ -276,7 +276,7 @@
 	has_type(_Arg::unused, TypeInfo::in),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
-	TypeInfo_for_T = ((mercury.type_desc.type_desc_0) TypeInfo).struct;
+	TypeInfo_for_T = ((mercury.type_desc.Type_desc_0) TypeInfo).struct;
 ").
 
 
@@ -411,20 +411,20 @@
 "
 	java.lang.Object [] result =
 			mercury.rtti_implementation.type_ctor_and_args_3_p_0(
-			((mercury.type_desc.type_desc_0) TypeDesc).struct);
+			((mercury.type_desc.Type_desc_0) TypeDesc).struct);
 
-	TypeCtorDesc = new type_ctor_desc_0((TypeCtorInfo_Struct) result[0]);
+	TypeCtorDesc = new Type_ctor_desc_0((TypeCtorInfo_Struct) result[0]);
 	ArgTypes = result[1];
 
 	// Convert list from TypeInfo_Struct to type_desc_0
-	mercury.list.list_1 type_list = (mercury.list.list_1) ArgTypes;
+	mercury.list.List_1 type_list = (mercury.list.List_1) ArgTypes;
 	while (type_list.data_tag == 1) {
-		((mercury.list.list_1.f_cons_2) type_list).F1 =
-			new mercury.type_desc.type_desc_0(
+		((mercury.list.List_1.F_cons_2) type_list).F1 =
+			new mercury.type_desc.Type_desc_0(
 			(TypeInfo_Struct)
-			((mercury.list.list_1.f_cons_2) type_list).F1);
-		type_list = (mercury.list.list_1)
-			((mercury.list.list_1.f_cons_2) type_list).F2;
+			((mercury.list.List_1.F_cons_2) type_list).F1);
+		type_list = (mercury.list.List_1)
+			((mercury.list.List_1.F_cons_2) type_list).F2;
 	}
 ").
 
@@ -546,7 +546,7 @@
 "
 	Object[] result = mercury.rtti_implementation.
 		type_ctor_name_and_arity_4_p_0(
-		((type_ctor_desc_0) TypeCtorDesc).struct);
+		((Type_ctor_desc_0) TypeCtorDesc).struct);
 
 	TypeCtorModuleName = (java.lang.String) result[0];
 	TypeCtorName = (java.lang.String) result[1];
@@ -580,17 +580,17 @@
 %-----------------------------------------------------------------------------%
 
 :- pragma foreign_code("Java", "
-	public static class type_desc_0 {
+	public static class Type_desc_0 {
 		public mercury.runtime.TypeInfo_Struct struct;
 
-		public type_desc_0(mercury.runtime.TypeInfo_Struct init) {
+		public Type_desc_0(mercury.runtime.TypeInfo_Struct init) {
 			struct = init;
 		}
 	}
-	public static class type_ctor_desc_0 {
+	public static class Type_ctor_desc_0 {
 		public mercury.runtime.TypeCtorInfo_Struct struct;
 
-		public type_ctor_desc_0(
+		public Type_ctor_desc_0(
 				mercury.runtime.TypeCtorInfo_Struct init)
 		{
 			struct = init;
@@ -598,33 +598,33 @@
 	}
 
 	public static boolean
-	__Unify____type_desc_0_0(mercury.type_desc.type_desc_0 x,
-		mercury.type_desc.type_desc_0 y)
+	__Unify____type_desc_0_0(mercury.type_desc.Type_desc_0 x,
+		mercury.type_desc.Type_desc_0 y)
 	{
 		return x.struct.unify(y.struct);
 	}
 
 	public static boolean
-	__Unify____type_ctor_desc_0_0(mercury.type_desc.type_ctor_desc_0 x,
-		mercury.type_desc.type_ctor_desc_0 y)
+	__Unify____type_ctor_desc_0_0(mercury.type_desc.Type_ctor_desc_0 x,
+		mercury.type_desc.Type_ctor_desc_0 y)
 	{
 		// stub only
 		throw new java.lang.Error
 			(""unify/2 for type_ctor_desc type not implemented"");
 	}
 
-	public static mercury.builtin.comparison_result_0
-	__Compare____type_desc_0_0(mercury.type_desc.type_desc_0 x,
-		mercury.type_desc.type_desc_0 y)
+	public static mercury.builtin.Comparison_result_0
+	__Compare____type_desc_0_0(mercury.type_desc.Type_desc_0 x,
+		mercury.type_desc.Type_desc_0 y)
 	{
 		// stub only
 		throw new java.lang.Error
 			(""compare/3 for type_desc type implemented"");
 	}
 
-	public static mercury.builtin.comparison_result_0
-	__Compare____type_ctor_desc_0_0(mercury.type_desc.type_ctor_desc_0 x,
-		mercury.type_desc.type_ctor_desc_0 y)
+	public static mercury.builtin.Comparison_result_0
+	__Compare____type_ctor_desc_0_0(mercury.type_desc.Type_ctor_desc_0 x,
+		mercury.type_desc.Type_ctor_desc_0 y)
 	{
 		// stub only
 		throw new java.lang.Error

-- 
Fergus Henderson                    |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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