[m-rev.] diff: emit an error if items occur after an end_module decl

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Oct 26 19:15:45 AEST 2004


Estimated hours taken: 1
Branches: main

Emit an error message if any items occur after the end_module
declaration of the top-level module in a file.  Currently,
this just causes an assertion failure in the compiler.

compiler/modules.m:
	Emit an error message when items occur after the
	end_module declaration in the top_level module of
	a file.

tests/invalid/Mmakefile:
tests/invalid/after_end_module.m:
tests/invalid/after_end_module.err_exp:
	Test case for the above.

Julien.

Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.308
diff -u -r1.308 modules.m
--- compiler/modules.m	16 Oct 2004 15:07:30 -0000	1.308
+++ compiler/modules.m	26 Oct 2004 05:51:36 -0000
@@ -6531,7 +6531,14 @@
 	InParentInterface = no,
 	split_into_submodules_2(ModuleName, Items0, InParentInterface,
 		Items, ModuleList, !IO),
-	require(unify(Items, []), "modules.m: items after end_module"),
+	%
+	% Check that there are no items after the end_module declaration.
+	%
+	( Items = [ _ - Context | _] ->
+		report_items_after_end_module(Context, !IO)
+	;
+		true
+	),
 	%
 	% check for modules declared as both nested and separate sub-modules
 	%
@@ -6743,6 +6750,13 @@
 	prog_out__write_context(Context),
 	io__write_string("  a separate sub-module and a nested sub-module.\n"),
 	io__set_exit_status(1).
+
+:- pred report_items_after_end_module(prog_context::in, io::di, io::uo) is det.
+
+report_items_after_end_module(Context, !IO) :-
+	ErrorPieces = [words("Error: item(s) after end_module delcaration.")],
+	write_error_pieces(Context, 0, ErrorPieces, !IO),
+	io.set_exit_status(1, !IO).

 	% Given a module (well, a list of items), extract the interface
 	% part of that module, i.e. all the items between `:- interface'
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.152
diff -u -r1.152 Mmakefile
--- tests/invalid/Mmakefile	31 May 2004 04:13:20 -0000	1.152
+++ tests/invalid/Mmakefile	26 Oct 2004 05:53:47 -0000
@@ -31,6 +31,7 @@
 	undef_mod_qual

 SINGLEMODULE= \
+	after_end_module \
 	any_mode \
 	any_should_not_match_bound \
 	assert_in_interface \
Index: tests/invalid/after_end_module.err_exp
===================================================================
RCS file: tests/invalid/after_end_module.err_exp
diff -N tests/invalid/after_end_module.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/after_end_module.err_exp	26 Oct 2004 05:54:58 -0000
@@ -0,0 +1,2 @@
+after_end_module.m:009: Error: item(s) after end_module delcaration.
+For more information, try recompiling with `-E'.
Index: tests/invalid/after_end_module.m
===================================================================
RCS file: tests/invalid/after_end_module.m
diff -N tests/invalid/after_end_module.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/after_end_module.m	25 Oct 2004 07:17:10 -0000
@@ -0,0 +1,9 @@
+:- module after_end_module.
+
+:- interface.
+
+:- type foo == int.
+
+:- end_module after_end_module.
+
+:- type bar == int.

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