[m-rev.] for review: add source package to mlds names

Peter Ross peter.ross at miscrit.be
Thu Jun 7 19:23:47 AEST 2001


Hi,

For Tyson to review.

This change bootchecks in hlc.gc grade, and I have used it to build
various .NET executables from the samples directory.

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


Estimated hours taken: 16
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
add to the name type the name of the source package which this name is
defined in.  This change will be needed for implementing foreign_class
in the .NET backend.

compiler/mlds.m:
    Add the new field to the mlds__fully_qualified_name type.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Propogate the changes around.

Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.22
diff -u -r1.22 ml_call_gen.m
--- compiler/ml_call_gen.m	2001/05/27 09:59:47	1.22
+++ compiler/ml_call_gen.m	2001/06/07 09:17:55
@@ -556,7 +556,8 @@
 		PredLabel, PredModule) },
 	{ Params = ml_gen_proc_params(ModuleInfo, PredId, ProcId) },
 	{ Signature = mlds__get_func_signature(Params) },
-	{ QualifiedProcLabel = qual(PredModule, PredLabel - ProcId) },
+	{ QualifiedProcLabel = qual(PredModule,
+			PredModule, PredLabel - ProcId) },
 	{ CodeAddrRval = const(code_addr_const(proc(QualifiedProcLabel,
 		Signature))) }.
 
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.87
diff -u -r1.87 ml_code_gen.m
--- compiler/ml_code_gen.m	2001/05/26 17:27:41	1.87
+++ compiler/ml_code_gen.m	2001/06/07 09:17:56
@@ -852,7 +852,8 @@
 		MLDS_Name, MLDS_ModuleName),
 	MLDS_FuncParams = ml_gen_proc_params(ModuleInfo, PredId, ProcId),
 	MLDS_Context = mlds__make_context(ProgContext),
-	ML_Defn = ml_pragma_export(C_Name, qual(MLDS_ModuleName, MLDS_Name),
+	ML_Defn = ml_pragma_export(C_Name,
+			qual(MLDS_ModuleName, MLDS_ModuleName, MLDS_Name),
 			MLDS_FuncParams, MLDS_Context).
 
 
@@ -2494,7 +2495,7 @@
 	{ ml_gen_proc_label(ModuleInfo, PredId, ProcId, MLDS_Name,
 			MLDS_Module) },
 	{ HashDefine = [raw_target_code("#define MR_PROC_LABEL "),
-			name(qual(MLDS_Module, MLDS_Name)),
+			name(qual(MLDS_Module, MLDS_Module, MLDS_Name)),
 			raw_target_code("\n")] }.
 
 
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.36
diff -u -r1.36 ml_code_util.m
--- compiler/ml_code_util.m	2001/05/12 05:30:21	1.36
+++ compiler/ml_code_util.m	2001/06/07 09:17:57
@@ -1199,7 +1199,7 @@
 		),
 		Signature = mlds__func_signature(ArgTypes, [])
 	},
-	{ ProcLabel = qual(PredModule, PredLabel - ProcId) },
+	{ ProcLabel = qual(PredModule, PredModule, PredLabel - ProcId) },
 	{ FuncLabelRval = const(code_addr_const(internal(ProcLabel,
 		FuncLabel, Signature))) }.
 
@@ -1342,8 +1342,8 @@
 		{ mercury_private_builtin_module(PrivateBuiltin) },
 		{ MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin) },
 		ml_gen_type(Type, MLDS_Type),
-		{ Lval = var(qual(MLDS_Module, var_name("dummy_var", no)),
-			MLDS_Type) }
+		{ Lval = var(qual(MLDS_Module, MLDS_Module,
+			var_name("dummy_var", no)), MLDS_Type) }
 	;
 		=(MLDSGenInfo),
 		{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
@@ -1409,7 +1409,8 @@
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_module_name(MLDSGenInfo, ModuleName) },
 	{ MLDS_Module = mercury_module_name_to_mlds(ModuleName) },
-	{ QualifiedVarLval = var(qual(MLDS_Module, VarName), VarType) }.
+	{ QualifiedVarLval = var(
+		qual(MLDS_Module, MLDS_Module, VarName), VarType) }.
 
 	% Generate a declaration for an MLDS variable, given its HLDS type.
 	%
@@ -1731,7 +1732,7 @@
 	{ InnerFuncParams0 = func_params(InnerArgs0, Rets) },
 	{ InnerArgRvals = list__map(
 		(func(Data - Type) 
-		= lval(var(qual(MLDS_Module, VarName), Type)) :-
+		= lval(var(qual(MLDS_Module, MLDS_Module, VarName), Type)) :-
 			( Data = data(var(VarName0)) ->
 				VarName = VarName0		
 			;
@@ -1741,7 +1742,8 @@
 			InnerArgs0) },
 	{ InnerFuncArgType = mlds__cont_type(ArgTypes0) },
 	{ PassedContVarName = mlds__var_name("passed_cont", no) },
-	{ InnerFuncRval = lval(var(qual(MLDS_Module, PassedContVarName),
+	{ InnerFuncRval = lval(var(
+		qual(MLDS_Module, MLDS_Module, PassedContVarName),
 		InnerFuncArgType)) },
 	{ InnerFuncParams = func_params(
 		[data(var(PassedContVarName)) - InnerFuncArgType | InnerArgs0],
@@ -1763,7 +1765,8 @@
 			yes(SeqNum), _), _, _, function(_, _, yes(_)))
 	->
 		% We call the proxy function.
-		QualProcLabel = qual(MLDS_Module, PredLabel - ProcId),
+		QualProcLabel = qual(MLDS_Module, MLDS_Module,
+			PredLabel - ProcId),
 		ProxyFuncRval = const(code_addr_const(
 			internal(QualProcLabel, SeqNum, ProxySignature))),
 
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.25
diff -u -r1.25 ml_elim_nested.m
--- compiler/ml_elim_nested.m	2001/05/10 15:07:56	1.25
+++ compiler/ml_elim_nested.m	2001/06/07 09:17:57
@@ -324,13 +324,14 @@
 		% struct:
 		%	env_ptr->foo = foo;
 		%
-		QualVarName = qual(ModuleName, VarName),
+		QualVarName = qual(ModuleName, ModuleName, VarName),
 		EnvModuleName = ml_env_module_name(ClassType),
 		FieldNameString = ml_var_name_to_string(VarName),
-		FieldName = named_field(qual(EnvModuleName, FieldNameString),
+		FieldName = named_field(
+			qual(EnvModuleName, EnvModuleName, FieldNameString),
 			EnvPtrTypeName),
 		Tag = yes(0),
-		EnvPtr = lval(var(qual(ModuleName,
+		EnvPtr = lval(var(qual(ModuleName, ModuleName,
 				mlds__var_name("env_ptr", no)),
 			EnvPtrTypeName)),
 		EnvArgLval = field(Tag, EnvPtr, FieldName, FieldType, 
@@ -373,7 +374,7 @@
 	%	};
 	%
 	EnvTypeKind = mlds__struct,
-	EnvTypeName = class_type(qual(ModuleName, EnvClassName), 0,
+	EnvTypeName = class_type(qual(ModuleName, ModuleName, EnvClassName), 0,
 		EnvTypeKind),
 	EnvTypeEntityName = type(EnvClassName, 0),
 	EnvTypeFlags = env_type_decl_flags,
@@ -398,7 +399,7 @@
 	% declare the `env_ptr' var, and
 	% initialize the `env_ptr' with the address of `env'
 	%
-	EnvVar = qual(ModuleName, mlds__var_name("env", no)),
+	EnvVar = qual(ModuleName, ModuleName, mlds__var_name("env", no)),
 	globals__get_target(Globals, Target),
 		% IL uses classes instead of structs, so the code
 		% generated needs to be a little different.
@@ -466,10 +467,10 @@
 	Defn0 = mlds__defn(Name, Context, Flags, DefnBody0),
 	(
 		DefnBody0 = mlds__function(PredProcId, Params, yes(FuncBody0)),
-		statement_contains_var(FuncBody0, qual(ModuleName,
+		statement_contains_var(FuncBody0, qual(ModuleName, ModuleName,
 			mlds__var_name("env_ptr", no)))
 	->
-		EnvPtrVal = lval(var(qual(ModuleName,
+		EnvPtrVal = lval(var(qual(ModuleName, ModuleName,
 				mlds__var_name("env_ptr_arg", no)),
 				mlds__generic_env_ptr_type)),
 		ml_init_env(TypeName, EnvPtrVal, Context, ModuleName, Globals,
@@ -524,7 +525,7 @@
 	%
 	%
-	EnvPtrVar = qual(ModuleName, mlds__var_name("env_ptr", no)),
+	EnvPtrVar = qual(ModuleName, ModuleName, mlds__var_name("env_ptr", no)),
 	AssignEnvPtr = assign(var(EnvPtrVar, EnvPtrVarType),
 		unop(cast(EnvPtrVarType), EnvPtrVal)),
 	InitEnvPtr = mlds__statement(atomic(AssignEnvPtr), Context).
@@ -874,7 +875,7 @@
 
 ml_should_add_local_data(ModuleName, VarName,
 		FollowingDefns, FollowingStatements) :-
-	QualVarName = qual(ModuleName, VarName),
+	QualVarName = qual(ModuleName, ModuleName, VarName),
 	(
 		list__member(FollowingDefn, FollowingDefns)
 	;
@@ -960,7 +961,8 @@
 fixup_target_code_component(target_code_output(Lval0),
 		target_code_output(Lval)) -->
 	fixup_lval(Lval0, Lval).
-fixup_target_code_component(name(Name), name(Name)) --> [].
+fixup_target_code_component(name(Name `with_type` mlds__qualified_entity_name),
+		name(Name)) --> [].
 
 :- pred fixup_trail_op(trail_op, trail_op, elim_info, elim_info).
 :- mode fixup_trail_op(in, out, in, out) is det.
@@ -1039,7 +1041,7 @@
 :- mode fixup_var(in, in, out, in, out) is det.
 
 fixup_var(ThisVar, ThisVarType, Lval, ElimInfo, ElimInfo) :-
-	ThisVar = qual(ThisVarModuleName, ThisVarName),
+	ThisVar = qual(_ThisVarPackageName, ThisVarModuleName, ThisVarName),
 	ModuleName = elim_info_get_module_name(ElimInfo),
 	Locals = elim_info_get_local_data(ElimInfo),
 	ClassType = elim_info_get_env_type_name(ElimInfo),
@@ -1059,12 +1061,13 @@
 			),
 		solutions(IsLocalVar, [FieldType])
 	->
-		EnvPtr = lval(var(qual(ModuleName,
+		EnvPtr = lval(var(qual(ModuleName, ModuleName,
 			mlds__var_name("env_ptr", no)),
 			EnvPtrVarType)),
 		EnvModuleName = ml_env_module_name(ClassType),
 		ThisVarFieldName = ml_var_name_to_string(ThisVarName),
-		FieldName = named_field(qual(EnvModuleName, ThisVarFieldName),
+		FieldName = named_field(
+			qual(EnvModuleName, EnvModuleName, ThisVarFieldName),
 			EnvPtrVarType),
 		Tag = yes(0),
 		Lval = field(Tag, EnvPtr, FieldName, FieldType, ClassType)
@@ -1147,7 +1150,11 @@
 
 :- func ml_env_module_name(mlds__type) = mlds_module_name.
 ml_env_module_name(ClassType) = EnvModuleName :-
-	( ClassType = class_type(qual(ClassModule, ClassName), Arity, _Kind) ->
+	( 
+		ClassType = class_type(
+				qual(_ClassPackage, ClassModule, ClassName),
+				Arity, _Kind)
+	->
 		EnvModuleName = mlds__append_class_qualifier(ClassModule,
 			ClassName, Arity)
 	;
@@ -1465,8 +1472,8 @@
 target_code_component_contains_var(target_code_output(Lval), Name) :-
 	lval_contains_var(Lval, Name).
 target_code_component_contains_var(name(EntityName), VarName) :-
-	EntityName = qual(ModuleName, data(var(UnqualVarName))),
-	VarName = qual(ModuleName, UnqualVarName).
+	EntityName = qual(PackageName, ModuleName, data(var(UnqualVarName))),
+	VarName = qual(PackageName, ModuleName, UnqualVarName).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.8
diff -u -r1.8 ml_optimize.m
--- compiler/ml_optimize.m	2001/05/02 11:36:37	1.8
+++ compiler/ml_optimize.m	2001/06/07 09:17:58
@@ -192,7 +192,8 @@
 	(
 		Stmt0 = call(_Signature, _FuncRval, _MaybeObject, CallArgs,
 			_Results, _IsTailCall),
-		can_optimize_tailcall(qual(OptInfo ^ module_name, 
+		ModuleName = OptInfo ^ module_name,
+		can_optimize_tailcall(qual(ModuleName, ModuleName,
 			OptInfo ^ entity_name), Stmt0)
 	->
 		CommentStatement = statement(
@@ -238,7 +239,8 @@
 		%
 		Name = data(var(VarName))
 	->
-		QualVarName = qual(OptInfo ^ module_name, VarName),
+		QualVarName = qual(OptInfo ^ module_name,
+				OptInfo ^ module_name, VarName),
 		(
 			% 
 			% don't bother assigning a variable to itself
@@ -268,7 +270,7 @@
 			TempName = mlds__var_name(VarNameStr ++ "__tmp_copy",
 				MaybeNum),
 			QualTempName = qual(OptInfo ^ module_name, 
-				TempName),
+				OptInfo ^ module_name, TempName),
 			Initializer = init_obj(Arg),
 			TempDefn = ml_gen_mlds_var_decl(var(TempName),
 				Type, Initializer, OptInfo ^ context),
@@ -307,8 +309,9 @@
 	(
 		stmt_contains_statement(Stmt0, Call),
 		Call = mlds__statement(CallStmt, _),
+		ModuleName = OptInfo ^ module_name,
 		can_optimize_tailcall(
-			qual(OptInfo ^ module_name, OptInfo ^ entity_name), 
+			qual(ModuleName, ModuleName, OptInfo ^ entity_name), 
 			CallStmt)
 	->
 		Comment = atomic(comment("tailcall optimized into a loop")),
@@ -423,8 +426,9 @@
 		Statements0 = [AssignStatement | Statements1],
 		AssignStatement = statement(atomic(assign(LHS, RHS)), _),
 		LHS = var(ThisVar, _ThisType),
-		ThisVar = qual(Qualifier, VarName),
+		ThisVar = qual(PackageName, Qualifier, VarName),
 		Qualifier = OptInfo ^ module_name,
+		PackageName = OptInfo ^ module_name,
 		list__takewhile(isnt(var_defn(VarName)), Defns0, 
 			_PrecedingDefns, [_VarDefn | FollowingDefns]),
 
@@ -439,7 +443,8 @@
 			list__member(OtherDefn, FollowingDefns),
 			OtherDefn = mlds__defn(data(var(OtherVarName)),
 				_, _, data(_Type, OtherInitializer)),
-			( rval_contains_var(RHS, qual(Qualifier, OtherVarName))
+			( rval_contains_var(RHS,
+				qual(PackageName, Qualifier, OtherVarName))
 			; initializer_contains_var(OtherInitializer, ThisVar)
 			)
 		)
Index: compiler/ml_tailcall.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.6
diff -u -r1.6 ml_tailcall.m
--- compiler/ml_tailcall.m	2001/02/20 07:52:18	1.6
+++ compiler/ml_tailcall.m	2001/06/07 09:17:58
@@ -454,7 +454,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, ModuleName, VarName), Locals)
 		;
 			true
 		)
@@ -479,7 +480,7 @@
 var_is_local(Var, Locals) :-
 		% XXX we ignore the ModuleName --
 		% that is safe, but overly conservative
-	Var = qual(_ModuleName, VarName),
+	Var = qual(_PackageName, _ModuleName, VarName),
 	some [Local] (
 		locals_member(Local, Locals),
 		Local = data(var(VarName))
@@ -503,7 +504,7 @@
 	),
 		% XXX we ignore the ModuleName --
 		% that is safe, but might be overly conservative
-	QualifiedProcLabel = qual(_ModuleName, ProcLabel),
+	QualifiedProcLabel = qual(_PackageName, _ModuleName, ProcLabel),
 	ProcLabel = PredLabel - ProcId,
 	some [Local] (
 		locals_member(Local, Locals),
Index: compiler/ml_type_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.7
diff -u -r1.7 ml_type_gen.m
--- compiler/ml_type_gen.m	2001/05/02 17:34:39	1.7
+++ compiler/ml_type_gen.m	2001/06/07 09:17:58
@@ -137,7 +137,7 @@
 	MLDS_Context = mlds__make_context(Context),
 
 	% generate the class name
-	ml_gen_type_name(TypeId, qual(_, MLDS_ClassName), MLDS_ClassArity),
+	ml_gen_type_name(TypeId, qual(_, _, MLDS_ClassName), MLDS_ClassArity),
 
 	% generate the class members
 	ValueMember = ml_gen_enum_value_member(Context),
@@ -270,7 +270,8 @@
 	ml_gen_type_name(TypeId, QualBaseClassName, BaseClassArity),
 	BaseClassId = mlds__class_type(QualBaseClassName, BaseClassArity,
 		mlds__class),
-	QualBaseClassName = qual(BaseClassModuleName, BaseClassName),
+	QualBaseClassName = qual(_BaseClassPackageName,
+			BaseClassModuleName, BaseClassName),
 	BaseClassQualifier = mlds__append_class_qualifier(
 		BaseClassModuleName, BaseClassName, BaseClassArity),
 
@@ -411,7 +412,8 @@
 	% Note: the secondary tag class is nested inside the
 	% base class for this type.
 	UnqualClassName = "tag_type",
-	ClassName = qual(BaseClassQualifier, UnqualClassName),
+	ClassName = qual(BaseClassQualifier,
+			BaseClassQualifier, UnqualClassName),
 	ClassArity = 0,
 	SecondaryTagClassId = mlds__class_type(ClassName, ClassArity,
 		mlds__class),
@@ -564,7 +566,8 @@
 % Miscellaneous helper routines.
 %
 
-ml_gen_type_name(Name - Arity, qual(MLDS_Module, TypeName), Arity) :-
+ml_gen_type_name(Name - Arity,
+		qual(MLDS_Module, MLDS_Module, TypeName), Arity) :-
 	(
 		Name = qualified(ModuleName, TypeName)
 	;
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.34
diff -u -r1.34 ml_unify_gen.m
--- compiler/ml_unify_gen.m	2001/05/31 05:59:47	1.34
+++ compiler/ml_unify_gen.m	2001/06/07 09:17:58
@@ -446,6 +446,7 @@
 	{ MLDS_PrivateBuiltinModule = mercury_module_name_to_mlds(
 		PrivateBuiltinModule) },
 	{ ClosureLayoutType = mlds__class_type(qual(MLDS_PrivateBuiltinModule,
+			MLDS_PrivateBuiltinModule,
 			"closure_layout"), 0, mlds__class) },
 	{ ClosureLayoutRval = const(null(ClosureLayoutType)) },
 
@@ -475,7 +476,8 @@
 	%
 	{ Tag = 0 },
 	{ CtorDefn = ctor_id("<closure>", 0) },
-	{ QualifiedCtorId = qual(MLDS_PrivateBuiltinModule, CtorDefn) },
+	{ QualifiedCtorId = qual(MLDS_PrivateBuiltinModule,
+			MLDS_PrivateBuiltinModule, CtorDefn) },
 
 	%
 	% put all the extra arguments of the closure together
@@ -1245,7 +1247,7 @@
 		{ ConsId = ctor_id(ConsName, 0) },
 		{ ModuleName = mercury_module_name_to_mlds(unqualified("")) }
 	),
-	{ QualifiedConsId = qual(ModuleName, ConsId) }.
+	{ QualifiedConsId = qual(ModuleName, ModuleName, ConsId) }.
 
 :- pred ml_gen_cons_args(list(mlds__lval), list(prog_type),
 		list(uni_mode), module_info, list(mlds__rval)).
@@ -1819,15 +1821,16 @@
 		type_to_type_id(Type, TypeId, _)
 	->
 		ml_gen_type_name(TypeId,
-			qual(MLDS_Module, TypeName), TypeArity),
+			qual(_Package, MLDS_Module, TypeName), TypeArity),
 		ClassQualifier = mlds__append_class_qualifier(
 			MLDS_Module, TypeName, TypeArity),
-		QualClassName = qual(ClassQualifier, ClassName),
+		QualClassName = qual(ClassQualifier, ClassQualifier, ClassName),
 		ClassPtrType = mlds__ptr_type(mlds__class_type(
 			QualClassName, ClassArity, mlds__class)),
 		FieldQualifier = mlds__append_class_qualifier(
 			ClassQualifier, ClassName, ClassArity),
-		QualifiedFieldName = qual(FieldQualifier, FieldName),
+		QualifiedFieldName = qual(FieldQualifier,
+				FieldQualifier, FieldName),
 		FieldId = named_field(QualifiedFieldName, ClassPtrType)
 	;
 		error("ml_gen_field_id: invalid type")
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.9
diff -u -r1.9 ml_util.m
--- compiler/ml_util.m	2001/05/10 15:07:57	1.9
+++ compiler/ml_util.m	2001/06/07 09:17:59
@@ -165,9 +165,9 @@
 		CodeAddr = internal(QualifiedProcLabel, SeqNum, _Sig),
 		MaybeSeqNum = yes(SeqNum)
 	),
-	QualifiedProcLabel = qual(ModuleName, PredLabel - ProcId),
+	QualifiedProcLabel = qual(PackageName, ModuleName, PredLabel - ProcId),
 	% check that the module name matches
-	Name = qual(ModuleName, FuncName),
+	Name = qual(PackageName, ModuleName, FuncName),
 	% check that the PredLabel, ProcId, and MaybeSeqNum match
 	FuncName = function(PredLabel, ProcId, MaybeSeqNum, _),
 
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.53
diff -u -r1.53 mlds.m
--- compiler/mlds.m	2001/05/10 15:07:57	1.53
+++ compiler/mlds.m	2001/06/07 09:17:59
@@ -360,7 +360,18 @@
 % 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).
+	---> 	qual(
+				% Package which contains this name.
+				% ie mscorlib
+			package		:: mlds__package_name,
+
+				% Qualifers for this name.
+				% ie 'System'
+			qualifiers	:: mlds_module_name,
+
+				% The name ie 'Object'
+			name		:: T
+		).
 :- type mlds__qualified_entity_name
 	==	mlds__fully_qualified_name(mlds__entity_name).
 
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.86
diff -u -r1.86 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/05/10 15:07:57	1.86
+++ compiler/mlds_to_c.m	2001/06/07 09:18:00
@@ -458,7 +458,8 @@
 mlds_output_calls_to_init_entry(ModuleName, [FuncDefn | FuncDefns]) --> 
 	{ FuncDefn = mlds__defn(EntityName, _, _, _) },
 	io__write_string("\tMR_init_entry("),
-	mlds_output_fully_qualified_name(qual(ModuleName, EntityName)),
+	mlds_output_fully_qualified_name(
+			qual(ModuleName, ModuleName, EntityName)),
 	io__write_string(");\n"),
 	mlds_output_calls_to_init_entry(ModuleName, FuncDefns).
 
@@ -473,7 +474,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, ModuleName, EntityName)),
 	io__write_string(");\n"),
 	mlds_output_calls_to_register_tci(ModuleName, TypeCtorInfoDefns).
 
@@ -570,7 +572,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, ModuleName, export(C_name)) },
 	mlds_indent(Context, Indent),
 	% For functions exported using `pragma export',
 	% we use the default C calling convention.
@@ -676,7 +678,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, ModuleName, Name)).
 
 	%
 	% Generates the signature for det functions in the forward mode.
@@ -789,8 +791,8 @@
 		%
 		mlds_indent(Context, Indent),
 		mlds_output_decl_flags(Flags, forward_decl, Name, DefnBody),
-		mlds_output_decl_body(Indent, qual(ModuleName, Name), Context,
-			DefnBody)
+		mlds_output_decl_body(Indent,
+			qual(ModuleName, ModuleName, Name), Context, DefnBody)
 	).
 
 :- pred mlds_output_type_forward_decls(indent, list(mlds__type),
@@ -869,8 +871,8 @@
 	),
 	mlds_indent(Context, Indent),
 	mlds_output_decl_flags(Flags, definition, Name, DefnBody),
-	mlds_output_defn_body(Indent, qual(ModuleName, Name), Context,
-			DefnBody).
+	mlds_output_defn_body(Indent, qual(ModuleName, ModuleName, Name),
+			Context, DefnBody).
 
 :- pred mlds_output_decl_body(indent, mlds__qualified_entity_name,
 		mlds__context, mlds__entity_defn, io__state, io__state).
@@ -943,7 +945,7 @@
 	% of discriminated union types.)
 	% Here we compute the appropriate qualifier.
 	%
-	{ Name = qual(ModuleName, UnqualName) },
+	{ Name = qual(_PackageName, ModuleName, UnqualName) },
 	{ UnqualName = type(ClassName, ClassArity) ->
 		ClassModuleName = mlds__append_class_qualifier(ModuleName,
 			ClassName, ClassArity)
@@ -1059,7 +1061,8 @@
 		{ DefnBody = data(Type, Initializer) }
 	->
 		mlds_indent(Context, Indent),
-		mlds_output_fully_qualified_name(qual(EnumModuleName, Name)),
+		mlds_output_fully_qualified_name(
+				qual(EnumModuleName, EnumModuleName, Name)),
 		mlds_output_initializer(Type, Initializer)
 	;
 		{ error("mlds_output_enum_constant: constant is not data") }
@@ -1234,7 +1237,7 @@
 	io__write_char(' '),
 	io__write_string(CallingConvention),
 	mlds_output_fully_qualified_name(QualifiedName),
-	{ QualifiedName = qual(ModuleName, _) },
+	{ QualifiedName = qual(_, ModuleName, _) },
 	mlds_output_params(OutputPrefix, OutputSuffix,
 			Indent, ModuleName, Context, Parameters),
 	( { RetTypes = [RetType2] } ->
@@ -1273,7 +1276,7 @@
 		ModuleName, Context, Name - Type) -->
 	mlds_indent(Context, Indent),
 	mlds_output_data_decl_ho(OutputPrefix, OutputSuffix,
-			qual(ModuleName, Name), Type).
+			qual(ModuleName, ModuleName, Name), Type).
 
 :- pred mlds_output_func_type_prefix(func_params, io__state, io__state).
 :- mode mlds_output_func_type_prefix(in, di, uo) is det.
@@ -1329,7 +1332,7 @@
 :- mode mlds_output_fully_qualified_name(in, di, uo) is det.
 
 mlds_output_fully_qualified_name(QualifiedName) -->
-	{ QualifiedName = qual(_ModuleName, Name) },
+	{ QualifiedName = qual(_Package, _ModuleName, Name) },
 	(
 		(
 			%
@@ -1368,7 +1371,7 @@
 		%
 		% don't module-qualify main/2
 		%
-		{ QualifiedName = qual(_ModuleName, Name) },
+		{ QualifiedName = qual(_Package, _ModuleName, Name) },
 		{ Name = PredLabel - _ProcId },
 		{ PredLabel = pred(predicate, no, "main", 2, model_det, no) }
 	->
@@ -1383,7 +1386,7 @@
 :- mode mlds_output_fully_qualified(in, pred(in, di, uo) is det,
 		di, uo) is det.
 
-mlds_output_fully_qualified(qual(ModuleName, Name), OutputFunc) -->
+mlds_output_fully_qualified(qual(_Package, ModuleName, Name), OutputFunc) -->
 	{ SymName = mlds_module_name_to_sym_name(ModuleName) },
 	{ llds_out__sym_name_mangle(SymName, MangledModuleName) },
 	io__write_string(MangledModuleName),
@@ -1866,7 +1869,7 @@
 	io__write_string("{\n"),
 	( { Defns \= [] } ->
 		{ FuncInfo = func_info(FuncName, _) },
-		{ FuncName = qual(ModuleName, _) },
+		{ FuncName = qual(_, ModuleName, _) },
 		mlds_output_defns(Indent + 1, ModuleName, Defns),
 		io__write_string("\n")
 	;
@@ -2272,7 +2275,7 @@
 		io__write_string(""", "),
 		( { MaybeCtorName = yes(CtorId) } ->
 			io__write_char('"'),
-			{ CtorId = qual(_ModuleName, CtorDefn) },
+			{ CtorId = qual(_Package, _ModuleName, CtorDefn) },
 			{ CtorDefn = ctor_id(CtorName, _CtorArity) },
 			c_util__output_quoted_string(CtorName),
 			io__write_char('"')
@@ -2426,7 +2429,7 @@
 	io__write_string(", "),
 	( { MaybeCtorName = yes(QualifiedCtorId) } ->
 		io__write_char('"'),
-		{ QualifiedCtorId = qual(_ModuleName, CtorDefn) },
+		{ QualifiedCtorId = qual(_Package, _ModuleName, CtorDefn) },
 		{ CtorDefn = ctor_id(CtorName, _CtorArity) },
 		c_util__output_quoted_string(CtorName),
 		io__write_char('"')
Index: compiler/mlds_to_csharp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_csharp.m,v
retrieving revision 1.4
diff -u -r1.4 mlds_to_csharp.m
--- compiler/mlds_to_csharp.m	2001/05/24 07:03:52	1.4
+++ compiler/mlds_to_csharp.m	2001/06/07 09:18:00
@@ -91,6 +91,7 @@
 
 	{ MLDS = mlds(ModuleName, ForeignCode, _Imports, Defns) },
 	{ ClassName = mlds_module_name_to_class_name(
+		mercury_module_name_to_mlds(ModuleName),
 		mercury_module_name_to_mlds(ModuleName), yes) },
 
 	io__nl,
@@ -277,7 +278,7 @@
 write_csharp_code_component(raw_target_code(Code)) -->
 	io__write_string(Code).
 		% XXX we don't handle name yet.
-write_csharp_code_component(name(_)) --> [].
+write_csharp_code_component(name(_ `with_type` qualified_entity_name)) --> [].
 write_csharp_code_component(target_code_input(Rval)) -->
 	write_csharp_rval(Rval).
 write_csharp_code_component(target_code_output(Lval)) -->
@@ -375,7 +376,7 @@
 	write_csharp_rval(Rval),
 	io__write_string(")"),
 	io__write_string("."),
-	{ FieldId = qual(_, FieldName) },
+	{ FieldId = qual(_, _, FieldName) },
 	io__write_string(FieldName).
 
 write_csharp_lval(field(_, Rval, offset(OffSet), _, _)) -->
@@ -390,7 +391,7 @@
 	io__write_string("*"),
 	write_csharp_rval(Rval).
 write_csharp_lval(var(Var, _VarType)) -->
-	{ Var = qual(_, VarName) },
+	{ Var = qual(_, _, VarName) },
 	write_mlds_var_name_for_parameter(VarName).
 
 :- pred write_csharp_defn_decl(mlds__defn, io__state, io__state).
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.29
diff -u -r1.29 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/05/29 13:06:29	1.29
+++ compiler/mlds_to_il.m	2001/06/07 09:18:01
@@ -123,8 +123,8 @@
 
 	% Turn an MLDS module name into a class_name name, adding a
 	% "mercury_code" suffix if the bool is "yes".
-:- func mlds_module_name_to_class_name(mlds_module_name, bool) =
-	ilds__class_name.
+:- func mlds_module_name_to_class_name(mlds__package_name,
+		mlds_module_name, bool) = ilds__class_name.
 
 
 	% Return the class_name for the generic class.
@@ -214,7 +214,7 @@
 		Info3),
 	list__condense(OtherDeclsList, OtherDecls),
 
-	ClassName = mlds_module_name_to_class_name(ModuleName, yes),
+	ClassName = mlds_module_name_to_class_name(ModuleName, ModuleName, yes),
 
 		% Make this module an assembly unless it is in the standard
 		% library.  Standard library modules all go in the one
@@ -383,7 +383,8 @@
 generate_method_defn(DataDefn) --> 
 	{ DataDefn = defn(data(DataName), Context, _DeclsFlags, Entity) },
 	il_info_get_module_name(ModuleName),
-	{ ClassName = mlds_module_name_to_class_name(ModuleName, yes) },
+	{ ClassName = mlds_module_name_to_class_name(
+			ModuleName, ModuleName, yes) },
 
 		% Generate a term (we use it to emit the complete
 		% method definition as a comment, which is nice
@@ -495,7 +496,8 @@
 :- mode generate_other_decls(in, out, in, out) is det.
 generate_other_decls(MLDSDefn, Decls) -->
 	ModuleName =^ module_name,
-	{ ClassName = mlds_module_name_to_class_name(ModuleName, yes) },
+	{ ClassName = mlds_module_name_to_class_name(ModuleName,
+			ModuleName, yes) },
 	{ MLDSDefn = mlds__defn(EntityName, _Context, _DeclFlags, Entity) }, 
 	{ term__type_to_term(MLDSDefn, MLDSDefnTerm) },
 	( { EntityName = type(TypeName0, Arity) },
@@ -553,7 +555,8 @@
 		;
 			( { DataName = var(VarName) } ->
 				il_info_get_module_name(ModuleName),
-				{ Lval = var(qual(ModuleName, VarName), 
+				{ Lval = var(
+					qual(ModuleName, ModuleName, VarName), 
 					MLDSType) },
 				get_load_store_lval_instrs(Lval,
 					LoadMemRefInstrs, StoreLvalInstrs),
@@ -982,7 +985,7 @@
 		{ mangle_foreign_code_module(ModuleName, Lang,
 			OutlineLangModuleName) },
 		{ ClassName = mlds_module_name_to_class_name(
-			OutlineLangModuleName, yes) },
+			OutlineLangModuleName, OutlineLangModuleName, yes) },
 		signature(_, RetType, Params) =^ signature, 
 
 		( { ReturnLvals = [] } ->
@@ -1030,7 +1033,7 @@
 		^ method_foreign_lang := yes(managed_cplusplus),
 		{ mangle_dataname_module(no, ModuleName, NewModuleName) },
 		{ ClassName = mlds_module_name_to_class_name(NewModuleName,
-				no) },
+				NewModuleName, yes) },
 		signature(_, RetType, Params) =^ signature, 
 			% If there is a return value, put it in succeeded.
 			% XXX this is incorrect for functions, which might
@@ -1767,7 +1770,7 @@
 	test_rtti_initialization_field(DoneFieldRef, TestInstrs),
 	set_rtti_initialization_field(DoneFieldRef, SetInstrs),
 	{ CCtorCalls = list__map((func(X) = call_class_constructor(
-		mlds_module_name_to_class_name(X, yes))), Imports) },
+		mlds_module_name_to_class_name(X, X, yes))), Imports) },
 	{ AllInstrs = list__condense([TestInstrs, AllocInstrs, SetInstrs,
 		CCtorCalls, InitInstrs, [ret]]) },
 	{ MethodDecls = [instrs(AllInstrs)] }.
@@ -1967,11 +1970,12 @@
 :- 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(qual(MldsPackageName,
+		MldsModuleName, MldsClassName0), Arity) = IldsClassName :-
 	MldsClassName = string__format("%s_%d", [s(MldsClassName0), i(Arity)]),
 	IldsClassName = append_class_name(
-		mlds_module_name_to_class_name(MldsModuleName, yes),
+		mlds_module_name_to_class_name(MldsPackageName,
+				MldsModuleName, yes),
 		[MldsClassName]).
 
 mlds_type_to_ilds_class_name(DataRep, MldsType) = 
@@ -2114,10 +2118,11 @@
 :- func make_fieldref_for_handdefined_var(il_data_rep, mlds__var, mlds__type)
 	 = fieldref.
 make_fieldref_for_handdefined_var(DataRep, Var, VarType) = FieldRef :-
-	Var = qual(ModuleName, _),
+	Var = qual(Package, ModuleName, _),
 	mangle_mlds_var(Var, MangledVarStr),
+		% XXX Do we need to mangle the package name?
 	mangle_dataname_module(no, ModuleName, NewModuleName),
-	ClassName = mlds_module_name_to_class_name(NewModuleName, yes),
+	ClassName = mlds_module_name_to_class_name(Package, NewModuleName, yes),
 	FieldRef = make_fieldref(
 		mlds_type_to_ilds_type(DataRep, VarType), ClassName,
 		MangledVarStr).
@@ -2217,9 +2222,9 @@
 	error("unimplemented: mangling tabling_pointer").
 
 	% We turn procedures into methods of classes.
-mangle_mlds_proc_label(qual(ModuleName, PredLabel - ProcId), MaybeSeqNum,
-		ClassName, PredStr) :-
-	ClassName = mlds_module_name_to_class_name(ModuleName, yes),
+mangle_mlds_proc_label(qual(Package, ModuleName, PredLabel - ProcId),
+		MaybeSeqNum, ClassName, PredStr) :-
+	ClassName = mlds_module_name_to_class_name(Package, ModuleName, yes),
 	predlabel_to_id(PredLabel, ProcId, MaybeSeqNum, PredStr).
 
 :- pred mangle_entity_name(mlds__entity_name, string).
@@ -2236,7 +2241,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(_Package, _ModuleName, VarName), Str) :-
 	Str = mangle_mlds_var_name(VarName).
 
 :- func mangle_mlds_var_name(mlds__var_name) = string.
@@ -2266,7 +2271,7 @@
 mlds_to_il__sym_name_to_string_2(unqualified(Name), _) -->
         [Name].
 
-mlds_module_name_to_class_name(MldsModuleName, AddMercuryCode) = 
+mlds_module_name_to_class_name(Package, MldsModuleName, AddMercuryCode) = 
 		structured_name(AssemblyName, ClassName) :-
 	SymName = mlds_module_name_to_sym_name(MldsModuleName),
 	sym_name_to_class_name(SymName, AddMercuryCode, ClassName),
@@ -2275,7 +2280,9 @@
 	->
 		AssemblyName = "mercury"
 	;
-		mlds_to_il__sym_name_to_string(SymName, AssemblyName)
+		mlds_to_il__sym_name_to_string(
+				mlds_module_name_to_sym_name(Package),
+				AssemblyName)
 	).
 
 :- pred sym_name_to_class_name(sym_name, bool, list(ilds__id)).
@@ -2347,19 +2354,19 @@
 	% XXX can we just call error?
 rval_to_type(mkword(_Tag, _Rval), Type, I, I) :- 
 	ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
-	Type = mlds__class_type(qual(ModuleName, "invalid"),
+	Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
 		0, mlds__class).
 rval_to_type(unop(_, _), Type, I, I) :- 
 	ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
-	Type = mlds__class_type(qual(ModuleName, "invalid"),
+	Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
 		0, mlds__class).
 rval_to_type(binop(_, _, _), Type, I, I) :- 
 	ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
-	Type = mlds__class_type(qual(ModuleName, "invalid"),
+	Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
 		0, mlds__class).
 rval_to_type(mem_addr(_), Type, I, I) :-
 	ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
-	Type = mlds__class_type(qual(ModuleName, "invalid"),
+	Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
 		0, mlds__class).
 rval_to_type(const(Const), Type, I, I) :- 
 	Type = rval_const_to_type(Const).
@@ -2412,7 +2419,8 @@
 data_addr_constant_to_fieldref(data_addr(ModuleName, DataName), FieldRef) :-
 	mangle_dataname(DataName, FieldName),
 	mangle_dataname_module(yes(DataName), ModuleName, NewModuleName),
-	ClassName = mlds_module_name_to_class_name(NewModuleName, yes),
+	ClassName = mlds_module_name_to_class_name(
+			NewModuleName, NewModuleName, yes),
 	FieldRef = make_fieldref(il_array_type, ClassName, FieldName).
 
 
@@ -2447,10 +2455,12 @@
 					"offsets for non-int_const rvals")
 			)
 		; 
-			FieldNum = named_field(qual(ModuleName, FieldId),
+			FieldNum = named_field(
+				qual(PackageName, ModuleName, FieldId),
 				_Type),
-			ClassName = mlds_module_name_to_class_name(ModuleName,
-				no)
+			ClassName =
+			mlds_module_name_to_class_name(PackageName,
+				ModuleName, no)
 		),
 		FieldRef = make_fieldref(FieldILType, ClassName, FieldId).
 
@@ -2466,7 +2476,7 @@
 	( Name = data(DataName),
 	  Entity = mlds__data(MLDSType0, _Initializer) ->
 		mangle_dataname(DataName, MangledDataName),
-		mangle_mlds_var(qual(ModuleName,
+		mangle_mlds_var(qual(ModuleName, ModuleName,
 			var_name(MangledDataName, no)), Id),
 		MLDSType0 = MLDSType
 	;
@@ -2663,7 +2673,7 @@
 
 mlds_to_il__generate_extern_assembly(Imports, AllDecls) :-
 	Gen = (pred(Import::in, Decl::out) is semidet :-
-		ClassName = mlds_module_name_to_class_name(Import, yes),
+		ClassName = mlds_module_name_to_class_name(Import, Import, yes),
 		ClassName = structured_name(Assembly, _),
 		not (Assembly = "mercury"),
 		Decl = extern_assembly(Assembly, [])
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.4
diff -u -r1.4 mlds_to_java.m
--- compiler/mlds_to_java.m	2001/05/10 15:07:59	1.4
+++ compiler/mlds_to_java.m	2001/06/07 09:18:02
@@ -362,7 +362,8 @@
 		),
 		InterfaceModuleName = mercury_module_name_to_mlds(
 			qualified(unqualified("mercury"), "runtime")), 
-		Interface = qual(InterfaceModuleName, InterfaceName),
+		Interface = qual(InterfaceModuleName,
+				InterfaceModuleName, InterfaceName),
 		%
 		% Create the new class
 		%
@@ -481,6 +482,7 @@
 	Flags = ml_gen_local_var_decl_flags,
 	ArrayIndex = const(int_const(Count)),		
 	NewVarName = qual(mercury_module_name_to_mlds(ModuleName), 
+		mercury_module_name_to_mlds(ModuleName), 
 		var_name("args", no)),
 	NewArgLval = var(NewVarName, mlds__generic_type),
 	%	
@@ -614,7 +616,8 @@
 	{ Defn = mlds__defn(Name, Context, Flags, DefnBody) },
 	indent_line(Context, Indent),
 	output_decl_flags(Flags, Name),
-	output_defn_body(Indent, qual(ModuleName, Name), Context, DefnBody).
+	output_defn_body(Indent,
+		qual(ModuleName, ModuleName, Name), Context, DefnBody).
 
 :- pred output_defn_body(indent, mlds__qualified_entity_name,
 		mlds__context, mlds__entity_defn, io__state, io__state).
@@ -639,7 +642,7 @@
 :- mode output_class(in, in, in, in, di, uo) is det.
 
 output_class(Indent, Name, _Context, ClassDefn) -->
-	{ Name = qual(ModuleName, UnqualName) },
+	{ Name = qual(_Package, ModuleName, UnqualName) },
 	( { UnqualName = type(_, _) } ->
 		[]	
 	;
@@ -693,7 +696,10 @@
 :- mode output_interface(in, di, uo) is det.
 
 output_interface(Interface) -->
-	 ( { Interface = class_type(qual(ModuleQualifier, Name), Arity, _) } ->
+	 ( 
+	 	{ Interface = class_type(qual(_Package, ModuleQualifier, Name),
+			Arity, _) }
+	->
 		{ SymName = mlds_module_name_to_sym_name(ModuleQualifier) },	
 		{ mangle_mlds_sym_name_for_java(SymName, ModuleName) },
 		io__format("%s.%s", [s(ModuleName), s(Name)]),
@@ -732,7 +738,7 @@
 
 output_class_body(Indent, mlds__enum, Name, AllMembers, _) -->
 	{ list__filter(defn_is_const, AllMembers, EnumConsts) },
-	{ Name = qual(ModuleName, UnqualName) },
+	{ Name = qual(_Package, ModuleName, UnqualName) },
 	output_enum_constants(Indent + 1, ModuleName, EnumConsts),
 	indent_line(Indent + 1),
 	io__write_string("public int value;\n\n"),  
@@ -797,7 +803,8 @@
 	->
 		indent_line(Indent),
 		io__write_string("public static final int "),
-		output_fully_qualified_name(qual(EnumModuleName, Name)),
+		output_fully_qualified_name(
+			qual(EnumModuleName, EnumModuleName, Name)),
 		output_initializer(Type, Initializer),
 		io__write_char(';')
 	;
@@ -1001,7 +1008,7 @@
 		io__write_string("java.lang.Object []")
 	),
 	io__write_char(' '),
-	{ QualifiedName = qual(ModuleName, Name) },
+	{ QualifiedName = qual(_Package, ModuleName, Name) },
 	output_name(Name),	
 	output_params(Indent, ModuleName, Context, Parameters).
 
@@ -1028,7 +1035,7 @@
 	indent_line(Context, Indent),
 	output_type(Type),
 	io__write_char(' '),
-	output_fully_qualified_name(qual(ModuleName, Name)).
+	output_fully_qualified_name(qual(ModuleName, ModuleName, Name)).
 
 %-----------------------------------------------------------------------------%
 %
@@ -1041,7 +1048,7 @@
 :- mode output_fully_qualified_name(in, di, uo) is det.
 
 output_fully_qualified_name(QualifiedName) -->
-	{ QualifiedName = qual(_ModuleName, Name) },
+	{ QualifiedName = qual(_Package, _ModuleName, Name) },
 	%
 	% Don't module qualify data names, otherwise all 
 	% variable declarations will be qualified with the
@@ -1066,7 +1073,7 @@
 		pred(T, io__state, io__state), io__state, io__state).
 :- mode output_fully_qualified(in, pred(in, di, uo) is det, di, uo) is det.
 
-output_fully_qualified(qual(ModuleName, Name), OutputFunc) -->
+output_fully_qualified(qual(_Package, ModuleName, Name), OutputFunc) -->
 	{ SymName = mlds_module_name_to_sym_name(ModuleName) },
 	{ mangle_mlds_sym_name_for_java(SymName, MangledModuleName) },
 	( { qualified_name_is_stdlib(SymName) } ->
@@ -1401,7 +1408,7 @@
 	io__write_string("{\n"),
 	( { Defns \= [] } ->
 		{ FuncInfo = func_info(FuncName, _) },
-		{ FuncName = qual(ModuleName, _) },
+		{ FuncName = qual(_Package, ModuleName, _) },
 		output_defns(Indent + 1, ModuleName, Defns),
 		io__write_string("\n")
 	;
@@ -1568,7 +1575,7 @@
 		( 
 	   		{ Rval = mlds__lval(Lval) },
 	   		{ Lval = var(VarName, _) },
-	   		{ VarName = qual(_, UnqualName) },
+	   		{ VarName = qual(_, _, UnqualName) },
 	   		{ UnqualName = var_name("dummy_var", no) } 
 		->
 			[]
@@ -1772,7 +1779,7 @@
 	( { MaybeCtorName = yes(QualifiedCtorId) } ->
 		output_type(Type),
 		io__write_char('.'),
-		{ QualifiedCtorId = qual(_ModuleName, CtorDefn) },
+		{ QualifiedCtorId = qual(_Package, _ModuleName, CtorDefn) },
 		{ CtorDefn = ctor_id(CtorName, CtorArity) },
 		{ llds_out__name_mangle(CtorName, MangledCtorName) },
 		io__format("%s_%d", [s(MangledCtorName), i(CtorArity)])
@@ -1913,7 +1920,7 @@
 output_lval(field(_MaybeTag, PtrRval, named_field(FieldName, CtorType),
 		_FieldType, _PtrType)) -->
 	( 
-		{ FieldName = qual(_, UnqualFieldName) }, 
+		{ FieldName = qual(_, _, UnqualFieldName) }, 
 	 	{ llds_out__name_mangle(UnqualFieldName, MangledFieldName) },
 	  	{ MangledFieldName = "data_tag" } 
 	->
@@ -1936,13 +1943,13 @@
 		output_bracketed_rval(PtrRval),  % the actual variable
 		io__write_string(").")
 	),
-	{ FieldName = qual(_, UnqualFieldName) },
+	{ FieldName = qual(_, _, UnqualFieldName) },
 	output_mangled_name(UnqualFieldName).    % the field name
 
 output_lval(mem_ref(Rval, _Type)) -->
 	output_bracketed_rval(Rval).
 
-output_lval(var(qual(_ModuleName, Name), _VarType)) -->
+output_lval(var(qual(_Package, _ModuleName, Name), _VarType)) -->
 	output_mlds_var_name(Name).
 		
 :- pred output_mangled_name(string, io__state, io__state).
Index: compiler/mlds_to_mcpp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_mcpp.m,v
retrieving revision 1.5
diff -u -r1.5 mlds_to_mcpp.m
--- compiler/mlds_to_mcpp.m	2001/05/24 07:03:52	1.5
+++ compiler/mlds_to_mcpp.m	2001/06/07 09:18:02
@@ -94,6 +94,7 @@
 	{ MLDS = mlds(ModuleName, ForeignCode, _Imports, Defns) },
 	{ prog_out__sym_name_to_string(ModuleName, ModuleNameStr) },
 	{ ClassName = mlds_module_name_to_class_name(
+		mercury_module_name_to_mlds(ModuleName),
 		mercury_module_name_to_mlds(ModuleName), yes) },
 
 	io__nl,
@@ -374,7 +375,8 @@
 write_managed_cpp_code_component(raw_target_code(Code)) -->
 	io__write_string(Code).
 		% XXX we don't handle name yet.
-write_managed_cpp_code_component(name(_)) --> [].
+write_managed_cpp_code_component(
+	name(_ `with_type` qualified_entity_name)) --> [].
 write_managed_cpp_code_component(target_code_input(Rval)) -->
 	write_managed_cpp_rval(Rval).
 write_managed_cpp_code_component(target_code_output(Lval)) -->
@@ -471,7 +473,7 @@
 	write_managed_cpp_rval(Rval),
 	io__write_string(")"),
 	io__write_string("->"),
-	{ FieldId = qual(_, FieldName) },
+	{ FieldId = qual(_, _, FieldName) },
 	io__write_string(FieldName).
 
 write_managed_cpp_lval(field(_, Rval, offset(OffSet), _, _)) -->
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.14
diff -u -r1.14 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m	2001/05/10 15:07:59	1.14
+++ compiler/rtti_to_mlds.m	2001/06/07 09:18:07
@@ -530,7 +530,7 @@
         ml_gen_pred_label_from_rtti(ModuleInfo, RttiProcId, PredLabel,
 		PredModule),
 	ProcId = RttiProcId^proc_id,
-        QualifiedProcLabel = qual(PredModule, PredLabel - ProcId),
+        QualifiedProcLabel = qual(PredModule, PredModule, PredLabel - ProcId),
 	Params = ml_gen_proc_params_from_rtti(ModuleInfo, RttiProcId),
 	Signature = mlds__get_func_signature(Params),
 	ProcAddrRval = const(code_addr_const(proc(QualifiedProcLabel, 
@@ -569,7 +569,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, MLDS_Module, var_name(Name, no)), Type)).
 
 %-----------------------------------------------------------------------------%
 %

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