diff: more bug fixes for --inhibit-warnings

Fergus Henderson fjh at cs.mu.oz.au
Mon Jan 5 19:39:34 AEDT 1998


Estimated hours taken: 1

Add new options for disabling some warnings, so that they
can be disabled by `--inhibit-warnings'.

compiler/options.m:
	Add new options `warn-missing-module-name'
	and `warn-wrong-module-name' (enabled by default),
	and ensure that `--inhibit-warnings' disables these options.

compiler/prog_io.m:
	Add code to conditionalize the printing of warnings
	based on the settings of the new options.

doc/user_guide.texi:
	Document the new options.

tests/valid/Mmakefile:
tests/valid/inhibit_warn_test.m:
	A regression test.

cvs diff  compiler/options.m compiler/prog_io.m doc/user_guide.texi tests/valid/Mmakefile tests/valid/inhibit_warn_test.m
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.216
diff -u -r1.216 options.m
--- options.m	1998/01/05 08:06:04	1.216
+++ options.m	1998/01/05 08:14:03
@@ -58,6 +58,8 @@
 		;	warn_non_stratification
 		;	warn_simple_code
 		;	warn_duplicate_calls
+		;	warn_missing_module_name
+		;	warn_wrong_module_name
 	% Verbosity options
 		;	verbose
 		;	very_verbose
@@ -287,9 +289,12 @@
 	inhibit_warnings	-	bool_special,
 	halt_at_warn		-	bool(no),
 	halt_at_syntax_errors	-	bool(no),
+	%
+	% IMPORTANT NOTE:
 	% if you add any new warning options, or if you change
 	% the default for an existing warning option to `yes',
 	% then you will need to modify the handling of inhibit_warnings
+	%
 	warn_singleton_vars	-	bool(yes),
 	warn_overlapping_scopes	-	bool(yes),
 	warn_det_decls_too_lax	-	bool(yes),
@@ -299,7 +304,9 @@
 	warn_non_stratification -	bool(no),
 	warn_missing_opt_files  -	bool(yes),
 	warn_simple_code	-	bool(yes),
-	warn_duplicate_calls	-	bool(no)
+	warn_duplicate_calls	-	bool(no),
+	warn_missing_module_name -	bool(yes),
+	warn_wrong_module_name -	bool(yes)
 ]).
 option_defaults_2(verbosity_option, [
 		% Verbosity Options
@@ -588,6 +595,8 @@
 long_option("warn-missing-opt-files",	warn_missing_opt_files).
 long_option("warn-simple-code",		warn_simple_code).
 long_option("warn-duplicate-calls",	warn_duplicate_calls).
+long_option("warn-missing-module-name",	warn_missing_module_name).
+long_option("warn-wrong-module-name",	warn_wrong_module_name).
 
 % verbosity options
 long_option("verbose",			verbose).
@@ -909,7 +918,9 @@
 			warn_nothing_exported	-	bool(Enable),
 			warn_interface_imports	-	bool(Enable),
 			warn_missing_opt_files	-	bool(Enable),
-			warn_simple_code	-	bool(Enable)
+			warn_simple_code	-	bool(Enable),
+			warn_missing_module_name -	bool(Enable),
+			warn_wrong_module_name	-	bool(Enable)
 		], OptionTable0, OptionTable).
 special_handler(infer_all, bool(Infer), OptionTable0, ok(OptionTable)) :-
 	override_options([
@@ -1153,7 +1164,13 @@
 	io__write_string("\t\tsimple that they are likely to be programming errors.\n"),
 	io__write_string("\t--warn-duplicate-calls\n"),
 	io__write_string("\t\tWarn about multiple calls to a predicate with the\n"),
-	io__write_string("\t\tsame input arguments.\n").
+	io__write_string("\t\tsame input arguments.\n"),
+	io__write_string("\t--no-warn-missing-module-name\n"),
+	io__write_string("\t\tDisable warnings for modules that do no start with\n"),
+	io__write_string("\t\ta `:- module' declaration.\n"),
+	io__write_string("\t--no-warn-wrong-module-name\n"),
+	io__write_string("\t\tDisable warnings for modules whose `:- module'\n"),
+	io__write_string("\t\tdeclaration does not match the module's file name.\n").
 
 :- pred options_help_verbosity(io__state::di, io__state::uo) is det.
 
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.167
diff -u -r1.167 prog_io.m
--- prog_io.m	1997/12/19 03:07:55	1.167
+++ prog_io.m	1998/01/05 08:33:33
@@ -154,11 +154,11 @@
 		{
 		  get_end_module(RevItems0, RevItems, EndModule),
 		  list__reverse(RevMessages, Messages0),
-		  list__reverse(RevItems, Items0),
-		  check_begin_module(ModuleName,
-				Messages0, Items0, Error0, EndModule,
-				FileName, Messages, Items, Error)
+		  list__reverse(RevItems, Items0)
 		},
+		check_begin_module(ModuleName,
+				Messages0, Items0, Error0, EndModule,
+				FileName, Messages, Items, Error),
 		io__seen
 	;
 		io__progname_base("prog_io.m", Progname),
@@ -218,16 +218,20 @@
 	% and construct the final parsing result.
 
 :- pred check_begin_module(string, message_list, item_list, module_error,
-		module_end, string, message_list, item_list, module_error).
-:- mode check_begin_module(in, in, in, in, in, in, out, out, out) is det.
+		module_end, string, message_list, item_list, module_error,
+		io__state, io__state).
+:- mode check_begin_module(in, in, in, in, in, in, out, out, out, di, uo)
+		is det.
 
 check_begin_module(ModuleName, Messages0, Items0, Error0, EndModule, FileName,
-		Messages, Items, Error) :-
+		Messages, Items, Error) -->
+    globals__io_lookup_bool_option(warn_missing_module_name, WarnMissing),
+    globals__io_lookup_bool_option(warn_wrong_module_name, WarnWrong),
 
     % check that the first item is a `:- module ModuleName'
     % declaration
 
-    (
+    {
         Items0 = [module_defn(_VarSet, module(ModuleName1)) - Context
               | Items1]
     ->
@@ -250,7 +254,8 @@
         ;
 	% check that the begin module declaration matches the expected name
 	% of the module
-	    ModuleName1 \= ModuleName
+	    ModuleName1 \= ModuleName,
+	    WarnWrong = yes
 	->
 	    dummy_term_with_context(Context, Term2),
             ThisError =
@@ -265,14 +270,18 @@
 	    Error = Error0
         )
     ;
-	term__context_init(FileName, 1, Context),
-	dummy_term_with_context(Context, Term2),
-        ThisError = "Warning: module should start with a `:- module' declaration"
+	( WarnMissing = yes ->
+	    term__context_init(FileName, 1, Context),
+	    dummy_term_with_context(Context, Term2),
+            ThisError = "Warning: module should start with a `:- module' declaration"
 		- Term2,
-        Messages = [ThisError | Messages0],
+            Messages = [ThisError | Messages0]
+	;
+	    Messages = Messages0
+	),
 	Items = Items0,
 	Error = Error0
-    ).
+    }.
 
 	% Create a dummy term.
 	% Used for error messages that are not associated with any
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.111
diff -u -r1.111 user_guide.texi
--- user_guide.texi	1998/01/01 06:05:57	1.111
+++ user_guide.texi	1998/01/05 08:15:52
@@ -1471,6 +1471,16 @@
 Warn about multiple calls to a predicate with the same
 input arguments.
 
+ at sp 1
+ at item --no-warn-missing-module-name
+Disable warnings for modules that do not start with a
+ at samp{:- module} declaration.
+
+ at sp 1
+ at item --no-warn-wrong-module-name
+Disable warnings for modules whose @samp{:- module} declaration
+does not match the module's file name.
+
 @end table
 
 @node Verbosity options
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.5
diff -u -r1.5 Mmakefile
--- Mmakefile	1998/01/02 00:11:31	1.5
+++ Mmakefile	1998/01/05 08:37:14
@@ -37,6 +37,7 @@
 	higher_order_implied_mode.m \
 	ho_inst.m \
 	ho_func_call.m \
+	inhibit_warn_test.m \
 	implied_mode.m \
 	indexing.m \
 	intermod_lambda.m \
@@ -105,6 +106,7 @@
 MCFLAGS-compl_unify_bug		= -O3
 MCFLAGS-double_vn		= -O4
 MCFLAGS-higher_order_implied_mode = -O-1
+MCFLAGS-inhibit_warn_test       = --inhibit-warnings --halt-at-warn
 MCFLAGS-livevals_seq		= -O5 --opt-space
 MCFLAGS-middle_rec_labels	= --middle-rec --no-follow-vars 
 MCFLAGS-mostly_uniq_mode_inf	= --infer-all
Index: tests/valid/inhibit_warn_test.m
===================================================================
RCS file: inhibit_warn_test.m
diff -N inhibit_warn_test.m
--- /dev/null	Mon Jan  5 19:24:52 1998
+++ inhibit_warn_test.m	Mon Jan  5 19:36:39 1998
@@ -0,0 +1,4 @@
+% missing `:- module' declaration
+:- pred p(int).
+:- mode p(out) is semidet. % determinism could be tighter
+p(1).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list