for review: fix quoting bug

David Matthew Overton dmo at cs.mu.OZ.AU
Wed Oct 28 11:59:17 AEDT 1998


Hi,

This is a fix for a bug I reported to mercury-bugs yesterday.  Would
someone please review it.

David

Estimated hours taken: 0.5

Fix a bug with quoting of module-qualified terms in .opt files.
Add a test case for this bug.

compiler/hlds_out.m:
	Add a version of `hlds_out__write_functor' which has a
	`needs_quotes' argument.  Call this new predicate from
	`hlds_out__write_qualified_functor' to ensure that functors
	are properly quoted after the `:'.

compiler/mercury_to_mercury.m:
	Export `mercury_output_term/6' so it can be called by
	`hlds_out__write_functor/7'.

tests/valid/Mmakefile:
	Add the new test case.

tests/valid/intermod_quote.m:
tests/valid/intermod_quote2.m:
	New test case for this bug.

Index: compiler/hlds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_out.m,v
retrieving revision 1.207
diff -u -r1.207 hlds_out.m
--- 1.207	1998/10/16 10:37:29
+++ hlds_out.m	1998/10/27 02:54:53
@@ -1477,10 +1477,20 @@
 	).
 
 hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums) -->
+	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
+		not_next_to_graphic_token).
+
+:- pred hlds_out__write_functor(const, list(var), varset, bool, needs_quotes,
+	io__state, io__state).
+:- mode hlds_out__write_functor(in, in, in, in, in, di, uo) is det.
+
+hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums, 
+		NextToGraphicToken) -->
 	{ term__context_init(Context) },
 	{ term__var_list_to_term_list(ArgVars, ArgTerms) },
 	{ Term = term__functor(Functor, ArgTerms, Context) },
-	mercury_output_term(Term, VarSet, AppendVarnums).
+	mercury_output_term(Term, VarSet, AppendVarnums, NextToGraphicToken).
+
 
 :- pred hlds_out__write_qualified_functor(module_name, const, list(var),
 		varset, bool, io__state, io__state).
@@ -1490,7 +1500,8 @@
 		AppendVarnums) -->
 	mercury_output_bracketed_sym_name(ModuleName),
 	io__write_string(":"),
-	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums).
+	hlds_out__write_functor(Functor, ArgVars, VarSet, AppendVarnums,
+		next_to_graphic_token).
 
 hlds_out__write_functor_cons_id(ConsId, ArgVars, VarSet, AppendVarnums) -->
 	(
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.147
diff -u -r1.147 mercury_to_mercury.m
--- 1.147	1998/09/22 16:13:32
+++ mercury_to_mercury.m	1998/10/27 02:56:56
@@ -157,6 +157,11 @@
 :- pred mercury_output_term(term, varset, bool, io__state, io__state).
 :- mode mercury_output_term(in, in, in, di, uo) is det.
 
+:- pred mercury_output_term(term, varset, bool, needs_quotes,
+				io__state, io__state).
+:- mode mercury_output_term(in, in, in, in, di, uo) is det.
+
 :- pred mercury_type_to_string(varset, term, string).
 :- mode mercury_type_to_string(in, in, out) is det.
 
@@ -2292,10 +2297,6 @@
 	mercury_output_term(Term, VarSet, AppendVarnums,
 		not_next_to_graphic_token).
 
-:- pred mercury_output_term(term, varset, bool, needs_quotes,
-				io__state, io__state).
-:- mode mercury_output_term(in, in, in, in, di, uo) is det.
-
 mercury_output_term(term__variable(Var), VarSet, AppendVarnums, _) -->
 	mercury_output_var(Var, VarSet, AppendVarnums).
 mercury_output_term(term__functor(Functor, Args, _), VarSet, AppendVarnums,
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmakefile,v
retrieving revision 1.25
diff -u -r1.25 Mmakefile
--- 1.25	1998/09/21 11:27:18
+++ Mmakefile	1998/10/28 00:08:34
@@ -50,6 +50,7 @@
 	inhibit_warn_test.m \
 	inlining_bug.m \
 	intermod_lambda.m \
+	intermod_quote.m \
 	intermod_test.m \
 	lambda_inference.m\
 	lambda_instmap_bug.m \
@@ -159,6 +160,12 @@
 	$(MCG) $(GRADEFLAGS) $(MCGFLAGS) --intermodule-optimization \
 		intermod_lambda.m
 
+intermod_quote.c:
+	$(MCI) $(GRADEFLAGS) $(MCIFLAGS) intermod_quote2.m
+	$(MCOI) $(GRADEFLAGS) $(MCOIFLAGS) intermod_quote2.m
+	$(MCG) $(GRADEFLAGS) $(MCGFLAGS) --intermodule-optimization \
+		intermod_quote.m
+
 intermod_test.c:
 	$(MCI) $(GRADEFLAGS) $(MCIFLAGS) intermod_test2.m
 	$(MCOI) $(GRADEFLAGS) $(MCOIFLAGS) intermod_test2.m

New file: tests/valid/intermod_quote.m
===================================================================
% Regression test to ensure that terms are properly quoted in the intermodule
% .opt file.
:- module intermod_quote.
:- interface.

:- type foo. % Not used.

:- implementation.
:- import_module intermod_quote2.

:- type foo ---> foo.

New file: tests/valid/intermod_quote2.m
===================================================================
% Regression test to ensure that terms are properly quoted in the intermodule
% .opt file.
:- module intermod_quote2.
:- interface.

:- func '*'(func(X) = Y, func(Y) = Z, X) = Z.
:- mode '*'(func(in) = out is det, func(in) = out is det, in) = out is det.

:- implementation.

'*'(F, G, X) = G(F(X)).
-- 
David Overton
MEngSc Student                       Email: dmo at cs.mu.oz.au     
Department of Computer Science       Web: http://www.cs.mu.oz.au/~dmo
The University of Melbourne          Phone: +61 3 9344 9159



More information about the developers mailing list