[m-dev.] for review: use NULL for empty field types RTTI

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Nov 14 22:13:58 AEDT 2000


Peter Ross, could you please review this one?

Estimated hours taken: 1

compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/type_ctor_info.m:
	When generating RTTI for constructors with no arguments, don't
	generate empty `field_types' arrays; not all C compilers
	support empty array initializers.  Instead, if there are no
	arguments, just use a null pointer.

	This is slightly more efficient than the previous approach to
	this problem which was to generate an array containing a
	single dummy element.  With this approach, we generate a null
	pointer rather than a pointer to an array containing a null pointer.
	
	The other advantage of this change is that it makes the
	treatment of the `field_types' array consistent with how we
	treat the `field_names' array.

Workspace: /home/mercury0/fjh/mercury
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.9
diff -u -d -r1.9 rtti.m
--- compiler/rtti.m	2000/11/01 05:12:13	1.9
+++ compiler/rtti.m	2000/11/14 06:39:13
@@ -220,9 +220,10 @@
 						% contains variables (assuming
 						% that arguments are numbered
 						% from zero)
-			rtti_name,		% a vector of length arity
+			maybe(rtti_name),	% a vector of length arity
 						% containing the pseudo
-						% typeinfos of the arguments
+						% typeinfos of the arguments,
+						% if any
 						% (a field_types rtti_name)
 			maybe(rtti_name),	% possibly a vector of length
 						% arity containing the names
Index: compiler/rtti_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_out.m,v
retrieving revision 1.17
diff -u -d -r1.17 rtti_out.m
--- compiler/rtti_out.m	2000/11/01 05:12:14	1.17
+++ compiler/rtti_out.m	2000/11/14 06:39:13
@@ -174,11 +174,17 @@
 	output_addr_of_rtti_data(ArgType),
 	io__write_string("\n};\n").
 output_rtti_data_defn(du_functor_desc(RttiTypeId, FunctorName, Ptag, Stag,
-		Locn, Ordinal, Arity, ContainsVarBitVector, ArgTypes,
+		Locn, Ordinal, Arity, ContainsVarBitVector, MaybeArgTypes,
 		MaybeNames, MaybeExist),
 		DeclSet0, DeclSet) -->
-	output_rtti_addr_decls(RttiTypeId, ArgTypes, "", "", 0, _,
-		DeclSet0, DeclSet1),
+	(
+		{ MaybeArgTypes = yes(ArgTypes) },
+		output_rtti_addr_decls(RttiTypeId, ArgTypes, "", "", 0, _,
+			DeclSet0, DeclSet1)
+	;
+		{ MaybeArgTypes = no },
+		{ DeclSet1 = DeclSet0 }
+	),
 	(
 		{ MaybeNames = yes(NamesInfo1) },
 		output_rtti_addr_decls(RttiTypeId, NamesInfo1, "", "",
@@ -214,7 +220,13 @@
 	io__write_int(Ordinal),
 	io__write_string(",\n\t"),
 	io__write_string("(MR_PseudoTypeInfo *) "), % cast away const
-	output_addr_of_rtti_addr(RttiTypeId, ArgTypes),
+	(
+		{ MaybeArgTypes = yes(ArgTypes2) },
+		output_addr_of_rtti_addr(RttiTypeId, ArgTypes2)
+	;
+		{ MaybeArgTypes = no },
+		io__write_string("NULL")
+	),
 	io__write_string(",\n\t"),
 	(
 		{ MaybeNames = yes(NamesInfo2) },
Index: compiler/rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.8
diff -u -d -r1.8 rtti_to_mlds.m
--- compiler/rtti_to_mlds.m	2000/11/03 15:51:30	1.8
+++ compiler/rtti_to_mlds.m	2000/11/14 06:39:14
@@ -156,7 +156,7 @@
 			ModuleName, ArgType)
 	]).
 gen_init_rtti_data_defn(du_functor_desc(RttiTypeId, FunctorName, Ptag, Stag,
-		Locn, Ordinal, Arity, ContainsVarBitVector, ArgTypes,
+		Locn, Ordinal, Arity, ContainsVarBitVector, MaybeArgTypes,
 		MaybeNames, MaybeExist), ModuleName, _, Init, []) :-
 	Init = init_struct([
 		gen_init_string(FunctorName),
@@ -166,7 +166,9 @@
 		gen_init_int(Ptag),
 		gen_init_int(Stag),
 		gen_init_int(Ordinal),
-		gen_init_rtti_name(ModuleName, RttiTypeId, ArgTypes),
+		gen_init_maybe(mlds__rtti_type(field_types(0)),
+			gen_init_rtti_name(ModuleName, RttiTypeId),
+			MaybeArgTypes),
 		gen_init_maybe(mlds__rtti_type(field_names(0)),
 			gen_init_rtti_name(ModuleName, RttiTypeId),
 			MaybeNames),
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.9
diff -u -d -r1.9 type_ctor_info.m
--- compiler/type_ctor_info.m	2000/08/10 05:11:05	1.9
+++ compiler/type_ctor_info.m	2000/09/25 08:19:38
@@ -566,21 +566,29 @@
 
 :- pred type_ctor_info__generate_arg_info_tables(module_info::in,
 	rtti_type_id::in, int::in, list(constructor_arg)::in, existq_tvars::in,
-	maybe(rtti_name)::out, rtti_name::out, list(rtti_data)::out, int::out)
-	is det.
+	maybe(rtti_name)::out, maybe(rtti_name)::out, list(rtti_data)::out,
+	int::out) is det.
 
 type_ctor_info__generate_arg_info_tables(
 		ModuleInfo, RttiTypeId, Ordinal, Args, ExistTvars,
-		MaybeFieldNamesRttiName, FieldTypesRttiName, Tables,
+		MaybeFieldNamesRttiName, MaybeFieldTypesRttiName, Tables,
 		ContainsVarBitVector) :-
 	RttiTypeId = rtti_type_id(_TypeModule, _TypeName, TypeArity),
 	type_ctor_info__generate_arg_infos(Args, TypeArity, ExistTvars,
 		ModuleInfo, MaybeArgNames, PseudoTypeInfos,
 		0, 0, ContainsVarBitVector, [], Tables0),
-	FieldTypesRttiName = field_types(Ordinal),
-	FieldTypesTable = field_types(RttiTypeId, Ordinal,
+	(
+		PseudoTypeInfos = [],
+		MaybeFieldTypesRttiName = no,
+		Tables1 = Tables0
+	;
+		PseudoTypeInfos = [_|_],
+		FieldTypesTable = field_types(RttiTypeId, Ordinal,
 			PseudoTypeInfos),
-	Tables1 = [FieldTypesTable | Tables0],
+		FieldTypesRttiName = field_types(Ordinal),
+		MaybeFieldTypesRttiName = yes(FieldTypesRttiName),
+		Tables1 = [FieldTypesTable | Tables0]
+	),
 	list__filter((lambda([MaybeName::in] is semidet, MaybeName = yes(_))),
 		MaybeArgNames, FieldNames),
 	(

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "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-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list