[m-rev.] diff: factor out tests for base_typeclass_infos

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Feb 20 13:34:51 AEDT 2004


Factor out some common code.

compiler/rtti.m:
	Add a new predicate to test whether the name of an RTTI data structure
	we generate should be module qualified.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
	Replace repeated instances of the same code with a call to the new
	predicate.
Zoltan.

cvs diff: Diffing .
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.159
diff -u -b -r1.159 mlds_to_c.m
--- mlds_to_c.m	9 Feb 2004 17:22:54 -0000	1.159
+++ mlds_to_c.m	18 Feb 2004 01:29:24 -0000
@@ -1664,17 +1664,8 @@
 			PredLabel = pred(predicate, no, "main", 2,
 				model_det, no)
 		;
-			%
-			% don't module-qualify base_typeclass_infos
-			%
-			% We don't want to include the module name as part
-			% of the name if it is a base_typeclass_info, since
-			% we _want_ to cause a link error for overlapping
-			% instance decls, even if they are in a different
-			% module
-			%
-			Name = data(rtti(tc_rtti_id(
-				base_typeclass_info(_, _, _))))
+			Name = data(rtti(RttiId)),
+			module_qualify_name_of_rtti_id(RttiId) = no
 		;
 			% We don't module qualify pragma export names.
 			Name = export(_)
@@ -3581,16 +3572,8 @@
 
 mlds_output_data_var_name(ModuleName, DataName, !IO) :-
 	(
-		%
-		% don't module-qualify base_typeclass_infos
-		%
-		% We don't want to include the module name as part
-		% of the name if it is a base_typeclass_info, since
-		% we _want_ to cause a link error for overlapping
-		% instance decls, even if they are in a different
-		% module
-		%
-		DataName = rtti(tc_rtti_id(base_typeclass_info(_, _, _)))
+		DataName = rtti(RttiId),
+		module_qualify_name_of_rtti_id(RttiId) = no
 	->
 		true
 	;
Index: mlds_to_gcc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.92
diff -u -b -r1.92 mlds_to_gcc.m
--- mlds_to_gcc.m	9 Feb 2004 17:22:56 -0000	1.92
+++ mlds_to_gcc.m	18 Feb 2004 01:22:26 -0000
@@ -2531,17 +2531,8 @@
 			PredLabel = pred(predicate, no, "main", 2,
 				model_det, no)
 		;
-			%
-			% don't module-qualify base_typeclass_infos
-			%
-			% We don't want to include the module name as part
-			% of the name if it is a base_typeclass_info, since
-			% we _want_ to cause a link error for overlapping
-			% instance decls, even if they are in a different
-			% module
-			%
-			Name = data(rtti(tc_rtti_id(
-				base_typeclass_info(_, _, _))))
+			Name = data(rtti(RttiId)),
+			module_qualify_name_of_rtti_id(RttiId) = no
 		;
 			% We don't module qualify pragma export names.
 			Name = export(_)
@@ -3685,16 +3676,8 @@
 build_data_var_name(ModuleName, DataName) =
 		ModuleQualifier ++ build_data_name(DataName) :-
 	(
-		%
-		% don't module-qualify base_typeclass_infos
-		%
-		% We don't want to include the module name as part
-		% of the name if it is a base_typeclass_info, since
-		% we _want_ to cause a link error for overlapping
-		% instance decls, even if they are in a different
-		% module
-		%
-		DataName = rtti(tc_rtti_id(base_typeclass_info(_, _, _)))
+		DataName = rtti(RttiId),
+		module_qualify_name_of_rtti_id(RttiId) = no
 	->
 		ModuleQualifier = ""
 	;
Index: rtti.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.41
diff -u -b -r1.41 rtti.m
--- rtti.m	19 Feb 2004 09:37:14 -0000	1.41
+++ rtti.m	20 Feb 2004 01:56:07 -0000
@@ -797,6 +797,12 @@
 	% part of C identifiers.
 :- func rtti__encode_tc_instance_type(tc_type) = string.
 
+	% Return yes iff the name of the given data structure should be module
+	% qualified.
+:- func module_qualify_name_of_rtti_id(rtti_id) = bool.
+:- func module_qualify_name_of_ctor_rtti_name(ctor_rtti_name) = bool.
+:- func module_qualify_name_of_tc_rtti_name(tc_rtti_name) = bool.
+
 :- implementation.
 
 :- import_module backend_libs__name_mangle.
@@ -1835,5 +1841,34 @@
 	% we use small integers to represent type_vars,
 	% rather than pointers, so there is no pointed-to type
 	error("pseudo_type_info_name_type: type_var").
+
+module_qualify_name_of_rtti_id(RttiId) = ShouldModuleQualify :-
+	(
+		RttiId = ctor_rtti_id(_, CtorRttiName),
+		ShouldModuleQualify =
+			module_qualify_name_of_ctor_rtti_name(CtorRttiName)
+	;
+		RttiId = tc_rtti_id(TCRttiName),
+		ShouldModuleQualify =
+			module_qualify_name_of_tc_rtti_name(TCRttiName)
+	).
+
+module_qualify_name_of_ctor_rtti_name(_) = yes.
+
+% We don't want to include the module name as part of the name for
+% base_typeclass_infos, since we _want_ to cause a link error for
+% overlapping instance decls, even if they are in a different modules.
+%
+% When we start generating data structures replacing base_typeclass_infos,
+% we should include their names here.
+%
+% This decision is implemented separately in rtti__tc_name_to_string.
+
+module_qualify_name_of_tc_rtti_name(TCRttiName) =
+	( TCRttiName = base_typeclass_info(_, _, _) ->
+		no
+	;
+		yes
+	).
 
 %-----------------------------------------------------------------------------%
cvs diff: Diffing notes
--------------------------------------------------------------------------
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