[m-dev.] for review: more empty array initializers

Peter Ross peter.ross at miscrit.be
Wed Feb 7 20:16:08 AEDT 2001


On Wed, Feb 07, 2001 at 01:03:47PM +1100, Zoltan Somogyi wrote:
> The diff will be OK after you address Fergus's comments, but it could be
> improved.
> 
> > -	list__foldl(output_number_in_vector, VarNames),
> > +	( { VarNames = [] } ->
> > +		io__write_string("\t0\n")
> > +	;
> > +		list__foldl(output_number_in_vector, VarNames)
> > +	),
> >  	io__write_string("};\n"),
> >  	{ decl_set_insert(DeclSet0, data_addr(
> >  		layout_addr(proc_layout_var_names(ProcLabel))), DeclSet) }.
> 
> If a procedure has no variable names, then it would be better not to output
> a var name array at all.
> 
I would do that, but this array is referenced from one other type.
Can't remember which one.  This problem should only occur for impure
pragma foreign_code.

> > -	list__foldl(
> > -		output_layout_name_in_vector("(const MR_Proc_Layout *)\n\t&"),
> > -		ProcLayoutNames),
> > +	( { ProcLayoutNames = [] } ->
> > +		io__write_string("\tNULL\n")
> > +	;
> > +		list__foldl(output_layout_name_in_vector(
> > +					"(const MR_Proc_Layout *)\n\t&"),
> > +				ProcLayoutNames)
> > +	),
> 
> At the moment, ProcLayoutNames can be the empty list only if the module does
> not export any procedures or types (since types have automatically generated
> unify and compare procedures). I don't think that is allowed, although
> I am not sure whether the front end checks this.
> 
> > @@ -832,7 +840,11 @@
> >  	io__write_string("\n"),
> >  	output_layout_name_storage_type_name(VectorName, yes),
> >  	io__write_string(" = {\n"),
> > -	list__foldl(output_layout_name_in_vector("&"), FileLayoutNames),
> > +	( { FileLayoutNames = [] } ->
> > +		io__write_string("\tNULL\n")
> > +	;
> > +		list__foldl(output_layout_name_in_vector("&"), FileLayoutNames)
> > +	),
> >  	io__write_string("};\n"),
> >  	{ decl_set_insert(DeclSet1, data_addr(layout_addr(VectorName)),
> >  		DeclSet) }.
> 
> FileLayoutNames can be empty only if the module has *no* events with non-dummy
> contexts. Even if the module has #line directives, every procedure (even
> compiler-generated ones) should have a non-dummy context, so this can happen
> if the module has no procedures.
> 
> > @@ -907,9 +923,13 @@
> >  	io__write_string("\n"),
> >  	output_layout_name_storage_type_name(LayoutName, yes),
> >  	io__write_string(" = {\n"),
> > -	list__foldl(
> > -		output_data_addr_in_vector("(const MR_Label_Layout *)\n\t&"),
> > -		LabelAddrs),
> > +	( { LabelAddrs = [] } ->
> > +		io__write_string("\tNULL\n")
> > +	;
> > +		list__foldl(output_data_addr_in_vector(
> > +				"(const MR_Label_Layout *)\n\t&"),
> > +			LabelAddrs)
> > +	),
> >  	io__write_string("};\n"),
> >  	{ decl_set_insert(DeclSet0, data_addr(layout_addr(LayoutName)),
> >  		DeclSet) }.
> 
> Same deal here.
> 
Not sure which of the three caused it but library/enum.c wouldn't
compile with only the line number change so I added the above three in
and it compiled fine.  I can't remember which one was the problem.
--------------------------------------------------------------------------
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